Skip to content

A platform for community discussion. Free, open, simple.

DEV: replace passwordValidation mixin in PasswordResetController (#31412)

Kelv29d06f1243fa
diff --git a/app/assets/javascripts/discourse/app/controllers/password-reset.js b/app/assets/javascripts/discourse/app/controllers/password-reset.js
index 25a6d64d37f..c533feb6e71 100644
--- a/app/assets/javascripts/discourse/app/controllers/password-reset.js
+++ b/app/assets/javascripts/discourse/app/controllers/password-reset.js
@@ -1,3 +1,4 @@
+import { tracked } from "@glimmer/tracking";
import Controller from "@ember/controller";
import { action } from "@ember/object";
import { alias, or, readOnly } from "@ember/object/computed";
@@ -5,15 +6,14 @@ import { ajax } from "discourse/lib/ajax";
import discourseComputed from "discourse/lib/decorators";
import getURL from "discourse/lib/get-url";
import { wantsNewWindow } from "discourse/lib/intercept-click";
+import PasswordValidationHelper from "discourse/lib/password-validation-helper";
import DiscourseURL, { userPath } from "discourse/lib/url";
import { getWebauthnCredential } from "discourse/lib/webauthn";
-import PasswordValidation from "discourse/mixins/password-validation";
import { SECOND_FACTOR_METHODS } from "discourse/models/user";
import { i18n } from "discourse-i18n";
-export default class PasswordResetController extends Controller.extend(
- PasswordValidation
-) {
+export default class PasswordResetController extends Controller {
+ @tracked accountPassword;
@alias("model.is_developer") isDeveloper;
@alias("model.admin") admin;
@alias("model.second_factor_required") secondFactorRequired;
@@ -29,7 +29,7 @@ export default class PasswordResetController extends Controller.extend(
requiresApproval = false;
redirected = false;
maskPassword = true;
- passwordValidationVisible = false;
+ passwordValidationHelper = new PasswordValidationHelper(this);
lockImageUrl = getURL("/images/lock.svg");
@@ -54,6 +54,10 @@ export default class PasswordResetController extends Controller.extend(
}
}
+ get passwordValidation() {
+ return this.passwordValidationHelper.passwordValidation;
+ }
+
@discourseComputed()
continueButtonText() {
return i18n("password_reset.continue", {
@@ -66,28 +70,8 @@ export default class PasswordResetController extends Controller.extend(
return getURL(redirectTo || "/");
}
- @discourseComputed(
- "passwordValidation.ok",
- "passwordValidation.reason",
- "passwordValidationVisible"
- )
- showPasswordValidation(
- passwordValidationOk,
- passwordValidationReason,
- passwordValidationVisible
- ) {
- return (
- passwordValidationOk ||
- (passwordValidationReason && passwordValidationVisible)
- );
- }
-
- @action
- togglePasswordValidation() {
- this.set(
- "passwordValidationVisible",
- Boolean(this.passwordValidation.reason)
- );
+ get showPasswordValidation() {
+ return this.passwordValidation.ok || this.passwordValidation.reason;
}
@action
@@ -146,8 +130,10 @@ export default class PasswordResetController extends Controller.extend(
errorMessage: null,
});
} else if (result.errors?.["user_password.password"]?.length > 0) {
- this.rejectedPasswords.pushObject(this.accountPassword);
- this.rejectedPasswordsMessages.set(
+ this.passwordValidationHelper.rejectedPasswords.push(
+ this.accountPassword
+ );
+ this.passwordValidationHelper.rejectedPasswordsMessages.set(
this.accountPassword,
(result.friendly_messages || []).join("\n")
);
diff --git a/app/assets/javascripts/discourse/app/templates/password-reset.hbs b/app/assets/javascripts/discourse/app/templates/password-reset.hbs
index 29c4f512e7b..60924fb72a9 100644
--- a/app/assets/javascripts/discourse/app/templates/password-reset.hbs
+++ b/app/assets/javascripts/discourse/app/templates/password-reset.hbs
@@ -74,7 +74,6 @@
<div class="input">
<PasswordField
@value={{this.accountPassword}}
- {{on "focusout" this.togglePasswordValidation}}
@capsLockOn={{this.capsLockOn}}
type={{if this.maskPassword "password" "text"}}
autofocus="autofocus"