mirror of
https://github.com/discourse/discourse.git
synced 2025-03-09 14:34:35 +00:00
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:
parent
f58ab2283d
commit
14efd17b7b
@ -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) => {
|
||||
|
@ -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"
|
||||
);
|
||||
});
|
||||
}
|
||||
);
|
||||
|
Loading…
x
Reference in New Issue
Block a user