FIX: Hide form after password reset (#14526)

When hide_email_address_taken was disabled, the forgot password modal
showed a flash message and continued to display the form causing
confusion. This change shows the flash message only when an error occurs
and in all other cases it shows a success message and hides the form.
This commit is contained in:
Bianca Nenciu 2021-10-06 17:16:59 +03:00 committed by GitHub
parent f58ab2283d
commit 14efd17b7b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 51 additions and 20 deletions

View File

@ -54,14 +54,23 @@ export default Controller.extend(ModalFunctionality, {
const accountEmailOrUsername = escapeExpression(
this.accountEmailOrUsername
);
const isEmail = accountEmailOrUsername.match(/@/);
let key = `forgot_password.complete_${
isEmail ? "email" : "username"
}`;
let extraClass;
if (data.user_found === true) {
key += "_found";
let key = "forgot_password.complete";
key += accountEmailOrUsername.match(/@/) ? "_email" : "_username";
if (data.user_found === false) {
key += "_not_found";
this.flash(
I18n.t(key, {
email: accountEmailOrUsername,
username: accountEmailOrUsername,
}),
"error"
);
} else {
key += data.user_found ? "_found" : "";
this.set("accountEmailOrUsername", "");
this.set(
"offerHelp",
@ -70,19 +79,7 @@ export default Controller.extend(ModalFunctionality, {
username: accountEmailOrUsername,
})
);
} else {
if (data.user_found === false) {
key += "_not_found";
extraClass = "error";
}
this.flash(
I18n.t(key, {
email: accountEmailOrUsername,
username: accountEmailOrUsername,
}),
extraClass
);
this.set("helpSeen", !data.user_found);
}
})
.catch((e) => {

View File

@ -85,3 +85,37 @@ acceptance("Forgot password", function (needs) {
);
});
});
acceptance(
"Forgot password - hide_email_address_taken enabled",
function (needs) {
needs.pretender((server, helper) => {
server.post("/session/forgot_password", () => {
return helper.response({});
});
});
test("requesting password reset", async function (assert) {
await visit("/");
await click("header .login-button");
await click("#forgot-password-link");
assert.equal(
queryAll(".forgot-password-reset").attr("disabled"),
"disabled",
"it should disable the button until the field is filled"
);
await fillIn("#username-or-email", "someuser");
await click(".forgot-password-reset");
assert.equal(
queryAll(".modal-body").html().trim(),
I18n.t("forgot_password.complete_username", {
username: "someuser",
}),
"it should display a success message"
);
});
}
);