From b20f1d124058ad1ff0113f3cc53b250dc383278e Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Wed, 6 Feb 2019 16:30:53 +0000 Subject: [PATCH] Convert forgot password to phases like the other flows --- .../structures/auth/ForgotPassword.js | 28 +++++++++++++------ src/components/structures/auth/Login.js | 6 ++-- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/components/structures/auth/ForgotPassword.js b/src/components/structures/auth/ForgotPassword.js index a2ed97d1cf..1fbcd8dfd4 100644 --- a/src/components/structures/auth/ForgotPassword.js +++ b/src/components/structures/auth/ForgotPassword.js @@ -25,6 +25,18 @@ import SdkConfig from "../../../SdkConfig"; import PasswordReset from "../../../PasswordReset"; +// Phases +// Show controls to configure server details +const PHASE_SERVER_DETAILS = 0; +// Show the forgot password inputs +const PHASE_FORGOT = 1; +// Email is in the process of being sent +const PHASE_SENDING_EMAIL = 2; +// Email has been sent +const PHASE_EMAIL_SENT = 3; +// User has clicked the link in email and completed reset +const PHASE_DONE = 4; + module.exports = React.createClass({ displayName: 'ForgotPassword', @@ -49,7 +61,7 @@ module.exports = React.createClass({ return { enteredHsUrl: this.props.customHsUrl || this.props.defaultHsUrl, enteredIsUrl: this.props.customIsUrl || this.props.defaultIsUrl, - progress: null, + phase: null, password: null, password2: null, errorText: null, @@ -58,17 +70,17 @@ module.exports = React.createClass({ submitPasswordReset: function(hsUrl, identityUrl, email, password) { this.setState({ - progress: "sending_email", + phase: PHASE_SENDING_EMAIL, }); this.reset = new PasswordReset(hsUrl, identityUrl); this.reset.resetPassword(email, password).done(() => { this.setState({ - progress: "sent_email", + phase: PHASE_EMAIL_SENT, }); }, (err) => { this.showErrorDialog(_t('Failed to send email') + ": " + err.message); this.setState({ - progress: null, + phase: null, }); }); }, @@ -80,7 +92,7 @@ module.exports = React.createClass({ return; } this.reset.checkEmailLinkClicked().done((res) => { - this.setState({ progress: "complete" }); + this.setState({ phase: PHASE_DONE }); }, (err) => { this.showErrorDialog(err.message); }); @@ -184,9 +196,9 @@ module.exports = React.createClass({ let resetPasswordJsx; - if (this.state.progress === "sending_email") { + if (this.state.phase === PHASE_SENDING_EMAIL) { resetPasswordJsx = ; - } else if (this.state.progress === "sent_email") { + } else if (this.state.phase === PHASE_EMAIL_SENT) { resetPasswordJsx = (
{ _t("An email has been sent to %(emailAddress)s. Once you've followed the link it contains, " + @@ -196,7 +208,7 @@ module.exports = React.createClass({ value={_t('I have verified my email address')} />
); - } else if (this.state.progress === "complete") { + } else if (this.state.phase === PHASE_DONE) { resetPasswordJsx = (

{ _t('Your password has been reset') }.

diff --git a/src/components/structures/auth/Login.js b/src/components/structures/auth/Login.js index 8524447ed4..893b430214 100644 --- a/src/components/structures/auth/Login.js +++ b/src/components/structures/auth/Login.js @@ -31,10 +31,10 @@ import { AutoDiscovery } from "matrix-js-sdk"; const PHONE_NUMBER_REGEX = /^[0-9()\-\s]*$/; // Phases -// Show the appropriate login flow(s) for the server -const PHASE_LOGIN = 0; // Show controls to configure server details -const PHASE_SERVER_DETAILS = 1; +const PHASE_SERVER_DETAILS = 0; +// Show the appropriate login flow(s) for the server +const PHASE_LOGIN = 1; // Enable phases for login const PHASES_ENABLED = true;