1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-12-03 17:36:05 +00:00
webvirtcloud/static/js/login_form.js
catborise 5d3280f9ea feat(accounts): the sign-in page keeps the username, warns of Caps Lock and shows the lock and a notice
A locked user got django-axes' plain-text 429 reply, untranslated and with
no way back; it is now a page in the panel's layout that says within how
many minutes the lock ends, and leads back to the sign-in page with the
destination kept (AXES_LOCKOUT_CALLABLE).

A failed sign-in emptied the username; it is kept, the password is marked
invalid and has the cursor (a refused username keeps it). A line under the
password says when Caps Lock is on. The fields carry autocomplete
(username, current-password, one-time-code) for password managers and
phones, and the show-password button is reachable with Tab again.

The lines under the forms are gone: "KVM / Libvirt" with a green dot
looked like a status it did not check, and "2FA Protection Active" was
shown to users without 2FA.

A new setting, Sign-in notice (Settings, Login), is shown above both
sign-in forms when set, e.g. planned maintenance or a terms-of-use line.
2026-11-20 22:40:41 +03:00

31 lines
1.5 KiB
JavaScript

// The sign-in forms (login, OTP login): the eye button shows or hides the
// password, a line says when Caps Lock is on, and while the form is sent its
// button is disabled and says so.
document.getElementById("btn-toggle-pwd").addEventListener("click", function () {
var password = document.getElementById("id_password");
var shown = password.type === "password";
password.type = shown ? "text" : "password";
var icon = document.getElementById("toggle-icon");
icon.classList.toggle("bi-eye", !shown);
icon.classList.toggle("bi-eye-slash", shown);
});
["keydown", "keyup"].forEach(function (type) {
document.getElementById("id_password").addEventListener(type, function (event) {
var on = event.getModifierState && event.getModifierState("CapsLock");
document.getElementById("caps-lock").classList.toggle("d-none", !on);
});
});
// Caps Lock may change elsewhere: the line waits for the next key here
document.getElementById("id_password").addEventListener("blur", function () {
document.getElementById("caps-lock").classList.add("d-none");
});
document.getElementById("form-signin").addEventListener("submit", function () {
var button = document.getElementById("btn-signin");
button.disabled = true;
var spinner = document.createElement("span");
spinner.className = "spinner-border spinner-border-sm me-2";
spinner.setAttribute("aria-hidden", "true");
button.replaceChildren(spinner, button.dataset.busyText);
});