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") + ); + } + } +