Convert forgot password to phases like the other flows

pull/21833/head
J. Ryan Stinnett 2019-02-06 16:30:53 +00:00
parent 8aff6b2e45
commit b20f1d1240
2 changed files with 23 additions and 11 deletions

View File

@ -25,6 +25,18 @@ import SdkConfig from "../../../SdkConfig";
import PasswordReset from "../../../PasswordReset"; 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({ module.exports = React.createClass({
displayName: 'ForgotPassword', displayName: 'ForgotPassword',
@ -49,7 +61,7 @@ module.exports = React.createClass({
return { return {
enteredHsUrl: this.props.customHsUrl || this.props.defaultHsUrl, enteredHsUrl: this.props.customHsUrl || this.props.defaultHsUrl,
enteredIsUrl: this.props.customIsUrl || this.props.defaultIsUrl, enteredIsUrl: this.props.customIsUrl || this.props.defaultIsUrl,
progress: null, phase: null,
password: null, password: null,
password2: null, password2: null,
errorText: null, errorText: null,
@ -58,17 +70,17 @@ module.exports = React.createClass({
submitPasswordReset: function(hsUrl, identityUrl, email, password) { submitPasswordReset: function(hsUrl, identityUrl, email, password) {
this.setState({ this.setState({
progress: "sending_email", phase: PHASE_SENDING_EMAIL,
}); });
this.reset = new PasswordReset(hsUrl, identityUrl); this.reset = new PasswordReset(hsUrl, identityUrl);
this.reset.resetPassword(email, password).done(() => { this.reset.resetPassword(email, password).done(() => {
this.setState({ this.setState({
progress: "sent_email", phase: PHASE_EMAIL_SENT,
}); });
}, (err) => { }, (err) => {
this.showErrorDialog(_t('Failed to send email') + ": " + err.message); this.showErrorDialog(_t('Failed to send email') + ": " + err.message);
this.setState({ this.setState({
progress: null, phase: null,
}); });
}); });
}, },
@ -80,7 +92,7 @@ module.exports = React.createClass({
return; return;
} }
this.reset.checkEmailLinkClicked().done((res) => { this.reset.checkEmailLinkClicked().done((res) => {
this.setState({ progress: "complete" }); this.setState({ phase: PHASE_DONE });
}, (err) => { }, (err) => {
this.showErrorDialog(err.message); this.showErrorDialog(err.message);
}); });
@ -184,9 +196,9 @@ module.exports = React.createClass({
let resetPasswordJsx; let resetPasswordJsx;
if (this.state.progress === "sending_email") { if (this.state.phase === PHASE_SENDING_EMAIL) {
resetPasswordJsx = <Spinner />; resetPasswordJsx = <Spinner />;
} else if (this.state.progress === "sent_email") { } else if (this.state.phase === PHASE_EMAIL_SENT) {
resetPasswordJsx = ( resetPasswordJsx = (
<div> <div>
{ _t("An email has been sent to %(emailAddress)s. Once you've followed the link it contains, " + { _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')} /> value={_t('I have verified my email address')} />
</div> </div>
); );
} else if (this.state.progress === "complete") { } else if (this.state.phase === PHASE_DONE) {
resetPasswordJsx = ( resetPasswordJsx = (
<div> <div>
<p>{ _t('Your password has been reset') }.</p> <p>{ _t('Your password has been reset') }.</p>

View File

@ -31,10 +31,10 @@ import { AutoDiscovery } from "matrix-js-sdk";
const PHONE_NUMBER_REGEX = /^[0-9()\-\s]*$/; const PHONE_NUMBER_REGEX = /^[0-9()\-\s]*$/;
// Phases // Phases
// Show the appropriate login flow(s) for the server
const PHASE_LOGIN = 0;
// Show controls to configure server details // 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 // Enable phases for login
const PHASES_ENABLED = true; const PHASES_ENABLED = true;