Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 3 additions & 20 deletions templates/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,8 @@
// script has run by the time DOMContentLoaded fires, which also makes the
// old $(function () { ... }) wrapper redundant.
document.addEventListener("DOMContentLoaded", function () {
var host = location.protocol + '//' + window.location.host
var urlParams = new URLSearchParams(window.location.search);
var code = urlParams.get('code');
// Where to go after logging in; validated server-side to a same-site path.
var next = {{ .next }};

if (code) {
var post = $.post(host + "/api/login", {"code": code});
post.done(function(data) {
window.location.href = next;
});
}

var emailForm = $("#email-form"), codeForm = $("#code-form"),
status = $("#email-login-status"), change = $("#email-change");
if (!emailForm.length) { return; }
Expand All @@ -27,7 +16,7 @@
emailForm.on("submit", function (e) {
e.preventDefault();
status.text("");
$.post(host + "/api/login/email", {email: $("#email-input").val()})
$.post("/api/login/email", {email: $("#email-input").val()})
.done(function () {
emailForm.hide(); codeForm.css("display", "flex"); change.show();
status.text("Check your inbox for a 6-digit code.");
Expand All @@ -38,7 +27,7 @@
codeForm.on("submit", function (e) {
e.preventDefault();
status.text("");
$.post(host + "/api/login/email/verify", {email: $("#email-input").val(), code: $("#code-input").val()})
$.post("/api/login/email/verify", {email: $("#email-input").val(), code: $("#code-input").val()})
.done(function () { window.location.href = next; })
.fail(function (xhr) { showError(xhr, "Could not verify the code."); });
});
Expand All @@ -54,16 +43,10 @@
<h2 style="font-weight: 700; margin-bottom: 8px; color: #1c2e1c;">Sign In</h2>
<p style="color: #7a937a; font-size: 14px; margin-bottom: 30px;">Log in to manage {{ .settings.site_title.Value }}</p>

<a id="github-button" href="" style="display: inline-flex; align-items: center; gap: 10px; padding: 12px 28px; background: #2d5a27; color: #fff; border-radius: 8px; text-decoration: none; font-size: 14px; font-weight: 500;">
<a id="github-button" href="/login/github{{ if .next }}{{ if ne .next "/" }}?next={{ .next | urlquery }}{{ end }}{{ end }}" style="display: inline-flex; align-items: center; gap: 10px; padding: 12px 28px; background: #2d5a27; color: #fff; border-radius: 8px; text-decoration: none; font-size: 14px; font-weight: 500;">
<i class="fab fa-github fa-lg"></i> Continue with GitHub
</a>

<script>
// The anchor above has already been parsed when this runs, so the link is
// never briefly inert, and setting .href needs no library at all.
document.getElementById("github-button").href = "https://github.com/login/oauth/authorize?client_id={{ .client_id }}&redirect_uri=" + window.location;
</script>

{{ if .email_login_enabled }}
<p style="color: #7a937a; font-size: 13px; margin: 24px 0 10px;">or sign in with email</p>
<form id="email-form" style="display: flex; gap: 8px; justify-content: center; flex-wrap: wrap;">
Expand Down