mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-03 17:36:05 +00:00
feat(accounts): a password change card that continues the sign-in
The forced first-login change was a plain settings form under a menu whose every link led back to it, asked for an "Old password" the user did not know was the temporary one, and listed Django's four rules as long sentences, with their refusals under the confirmation field. The page is now a card like the sign-in page: "Set your own password", signed in as whom and why, the temporary password named as such, and no menu but a Log out link. A rule list under the two new entries ticks what the browser can check (8 characters, not only digits, both entries match) and says the rest is checked on save; the server's refusals join that list. The eye button shows both new entries. A change chosen from the profile uses the same card with the menu and a Cancel link. base.html gets a navbar block for it. Turkish and Chinese texts.
This commit is contained in:
parent
40e3a7dfdd
commit
9809e5b79a
10 changed files with 546 additions and 135 deletions
31
static/js/password_change.js
Normal file
31
static/js/password_change.js
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
// The password change form: the eye button shows or hides both new
|
||||
// entries, and the rules the browser can check are ticked as you type.
|
||||
// The server checks every rule again when the form is sent.
|
||||
var newPassword = document.getElementById("id_new_password1");
|
||||
var again = document.getElementById("id_new_password2");
|
||||
var rules = document.getElementById("password-rules");
|
||||
|
||||
document.getElementById("toggle-new-password").addEventListener("click", function () {
|
||||
var shown = newPassword.type === "password";
|
||||
newPassword.type = again.type = shown ? "text" : "password";
|
||||
this.setAttribute("aria-pressed", String(shown));
|
||||
this.querySelector("i").className = shown ? "bi bi-eye-slash" : "bi bi-eye";
|
||||
});
|
||||
|
||||
function tick() {
|
||||
var value = newPassword.value;
|
||||
// as Python counts them: characters, not UTF-16 units; any digit, as str.isdigit
|
||||
var met = {
|
||||
length: Array.from(value).length >= 8,
|
||||
letters: value !== "" && !/^[\p{Nd}\p{No}]+$/u.test(value),
|
||||
match: value !== "" && value === again.value,
|
||||
};
|
||||
Object.keys(met).forEach(function (rule) {
|
||||
var item = rules.querySelector('[data-rule="' + rule + '"]');
|
||||
item.classList.toggle("text-success", met[rule]);
|
||||
item.querySelector("i").className = (met[rule] ? "bi bi-check-circle-fill" : "bi bi-circle") + " me-2";
|
||||
item.querySelector(".visually-hidden").textContent = met[rule] ? rules.dataset.met : rules.dataset.unmet;
|
||||
});
|
||||
}
|
||||
newPassword.addEventListener("input", tick);
|
||||
again.addEventListener("input", tick);
|
||||
Loading…
Add table
Add a link
Reference in a new issue