fixed
This commit is contained in:
1 parent
4194cef934
commit
363127fe9e
3350 files changed
+1284220
-1
No files matched your search
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* Login page: submit credentials, store the token pair and redirect.
|
||||
*/
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
if (document.body.dataset.page !== "login") return;
|
||||
|
||||
// Already signed in? Go straight to the dashboard.
|
||||
if (Api.tokens.access) {
|
||||
window.location.href = "/admin";
|
||||
return;
|
||||
}
|
||||
|
||||
const form = document.getElementById("login-form");
|
||||
const loginInput = document.getElementById("login-input");
|
||||
const passwordInput = document.getElementById("password-input");
|
||||
const errorEl = document.getElementById("login-error");
|
||||
const submitButton = document.getElementById("login-submit");
|
||||
|
||||
form.addEventListener("submit", async (event) => {
|
||||
event.preventDefault();
|
||||
errorEl.classList.add("hidden");
|
||||
|
||||
const loginValue = loginInput.value.trim();
|
||||
const password = passwordInput.value;
|
||||
if (!loginValue || !password) {
|
||||
errorEl.textContent = "Please enter your login and password.";
|
||||
errorEl.classList.remove("hidden");
|
||||
return;
|
||||
}
|
||||
|
||||
UI.setLoading(submitButton, true);
|
||||
try {
|
||||
await Auth.login(loginValue, password);
|
||||
window.location.href = "/admin";
|
||||
} catch (error) {
|
||||
errorEl.textContent =
|
||||
error.status === 400
|
||||
? "Invalid login or password."
|
||||
: error.message;
|
||||
errorEl.classList.remove("hidden");
|
||||
UI.setLoading(submitButton, false);
|
||||
}
|
||||
});
|
||||
});
|
||||
})();
|
||||
Reference in new issue
Block a user