From e497f6bf9bf4b694c48baa808b1bf3b08f4363e5 Mon Sep 17 00:00:00 2001 From: Penar Musaraj Date: Fri, 16 Feb 2024 12:18:07 -0500 Subject: [PATCH] UX: Allow resetting password when confirming session (#25708) This is particularly useful in scenarios where 2FA is enforced and users have forgotten their password. --- .../dialog-messages/confirm-session.gjs | 43 ++++++++++++++++++- .../user-preferences-security-test.js | 14 ++++++ app/assets/stylesheets/common/base/modal.scss | 14 +++--- config/locales/client.en.yml | 3 ++ 4 files changed, 67 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/discourse/app/components/dialog-messages/confirm-session.gjs b/app/assets/javascripts/discourse/app/components/dialog-messages/confirm-session.gjs index c22c7bc9ed9..f62d111a50a 100644 --- a/app/assets/javascripts/discourse/app/components/dialog-messages/confirm-session.gjs +++ b/app/assets/javascripts/discourse/app/components/dialog-messages/confirm-session.gjs @@ -6,7 +6,7 @@ import { inject as service } from "@ember/service"; import DButton from "discourse/components/d-button"; import UserLink from "discourse/components/user-link"; import { ajax } from "discourse/lib/ajax"; -import { popupAjaxError } from "discourse/lib/ajax-error"; +import { extractError, popupAjaxError } from "discourse/lib/ajax-error"; import { getPasskeyCredential, isWebauthnSupported, @@ -19,6 +19,7 @@ export default class ConfirmSession extends Component { @service siteSettings; @tracked errorMessage; + @tracked resetEmailSent = null; passwordLabel = I18n.t("user.password.title"); instructions = I18n.t("user.confirm_access.instructions"); @@ -82,6 +83,32 @@ export default class ConfirmSession extends Component { } } + @action + async sendPasswordResetEmail() { + try { + const result = await ajax("/session/forgot_password.json", { + data: { login: this.currentUser.username }, + type: "POST", + }); + + if (result.success) { + this.errorMessage = null; + this.resetEmailSent = I18n.t( + "user.confirm_access.password_reset_email_sent" + ); + } else { + this.errorMessage = I18n.t( + "user.confirm_access.cannot_send_password_reset_email" + ); + } + } catch (e) { + this.errorMessage = extractError( + e, + I18n.t("user.confirm_access.cannot_send_password_reset_email") + ); + } + } +