Skip to content

Commit a71a0dc

Browse files
authored
UX: don't always fill username for forgot password (#32646)
Reported here: https://meta.discourse.org/t/autofill-with-username-in-forgot-password-modal/365310 When `hide_email_address_taken` is enabled, we don't want to populate the username in the forgot email input, because we require an email address. This will remove username content that doesn't look like an email when that site setting is enabled. Before (username populated when email required): ![image](https://github.com/user-attachments/assets/7a6eb638-9b5e-4767-b111-e32cec94d8a7) After (username not populated, email is): ![image](https://github.com/user-attachments/assets/2d5eff84-92f8-4f76-bc98-b66bc6381fd3) ![image](https://github.com/user-attachments/assets/ecd071a0-804e-45ef-b0a2-ae331f87f029)
1 parent cf2f1ac commit a71a0dc

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

app/assets/javascripts/discourse/app/components/local-login-form.gjs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { i18n } from "discourse-i18n";
2525

2626
export default class LocalLoginForm extends Component {
2727
@service modal;
28+
@service siteSettings;
2829

2930
@tracked maskPassword = true;
3031
@tracked processingEmailLink = false;
@@ -129,9 +130,20 @@ export default class LocalLoginForm extends Component {
129130
handleForgotPassword(event) {
130131
event?.preventDefault();
131132

133+
let filledLoginName = this.args.loginName;
134+
135+
// no spaces, at least one dot, one @ with one or more characters before & after
136+
const likelyEmail = /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(
137+
filledLoginName?.trim()
138+
);
139+
140+
if (this.siteSettings.hide_email_address_taken && !likelyEmail) {
141+
filledLoginName = null;
142+
}
143+
132144
this.modal.show(ForgotPassword, {
133145
model: {
134-
emailOrUsername: this.args.loginName,
146+
emailOrUsername: filledLoginName,
135147
},
136148
});
137149
}

0 commit comments

Comments
 (0)