Added: Change Password extension use pass_min_length and pass_min_strength in JavaScript

This commit is contained in:
the-djmaze 2022-11-09 15:28:12 +01:00
parent fbabf0a283
commit eb34fd64d1
3 changed files with 22 additions and 10 deletions

View file

@ -34,6 +34,9 @@
class ChangePasswordUserSettings
{
constructor() {
let minLength = rl.pluginSettingsGet('change-password', 'pass_min_length');
let minStrength = rl.pluginSettingsGet('change-password', 'pass_min_strength');
this.changeProcess = ko.observable(false);
this.errorDescription = ko.observable('');
this.passwordMismatch = ko.observable(false);
@ -43,6 +46,7 @@
this.currentPasswordError = ko.observable(false);
this.newPassword = ko.observable('');
this.newPassword2 = ko.observable('');
this.pass_min_length = minLength;
this.currentPassword.subscribe(() => this.resetUpdate(true));
this.newPassword.subscribe(() => this.resetUpdate());
@ -51,11 +55,16 @@
ko.decorateCommands(this, {
saveNewPasswordCommand: self => !self.changeProcess()
&& '' !== self.currentPassword()
&& '' !== self.newPassword()
&& '' !== self.newPassword2()
&& self.newPassword().length >= minLength
&& self.newPassword2() == self.newPassword()
&& (!this.meter || this.meter.value >= minStrength)
});
}
submitForm(form) {
form.reportValidity() && this.saveNewPasswordCommand();
}
saveNewPasswordCommand() {
if (this.newPassword() !== this.newPassword2()) {
this.passwordMismatch(true);
@ -111,6 +120,7 @@
onBuild(dom) {
let meter = dom.querySelector('.new-password-meter');
meter && this.newPassword.subscribe(value => meter.value = getPassStrength(value));
this.meter = meter;
}
onHide() {