diff --git a/src/components/structures/auth/ForgotPassword.js b/src/components/structures/auth/ForgotPassword.js index 2ea39ad657..e235446b16 100644 --- a/src/components/structures/auth/ForgotPassword.js +++ b/src/components/structures/auth/ForgotPassword.js @@ -22,7 +22,7 @@ import sdk from '../../../index'; import Modal from "../../../Modal"; import SdkConfig from "../../../SdkConfig"; import PasswordReset from "../../../PasswordReset"; -import {ValidatedServerConfig} from "../../../utils/AutoDiscoveryUtils"; +import AutoDiscoveryUtils, {ValidatedServerConfig} from "../../../utils/AutoDiscoveryUtils"; // Phases // Show controls to configure server details @@ -53,9 +53,40 @@ module.exports = React.createClass({ password: "", password2: "", errorText: null, + + // We perform liveliness checks later, but for now suppress the errors. + // We also track the server dead errors independently of the regular errors so + // that we can render it differently, and override any other error the user may + // be seeing. + serverIsAlive: true, + serverDeadError: "", }; }, + componentWillMount: function() { + this._checkServerLiveliness(this.props.serverConfig); + }, + + componentWillReceiveProps: async function(newProps) { + if (newProps.serverConfig.hsUrl === this.props.serverConfig.hsUrl && + newProps.serverConfig.isUrl === this.props.serverConfig.isUrl) return; + + // Do a liveliness check on the new URLs + this._checkServerLiveliness(newProps.serverConfig); + }, + + _checkServerLiveliness: async function(serverConfig) { + try { + await AutoDiscoveryUtils.validateServerConfigWithStaticUrls( + serverConfig.hsUrl, + serverConfig.isUrl, + ); + this.setState({serverIsAlive: true}); + } catch (e) { + this.setState(AutoDiscoveryUtils.authComponentStateForError(e)); + } + }, + submitPasswordReset: function(email, password) { this.setState({ phase: PHASE_SENDING_EMAIL, @@ -89,6 +120,8 @@ module.exports = React.createClass({ onSubmitForm: function(ev) { ev.preventDefault(); + if (!this.state.serverIsAlive) return; + if (!this.state.email) { this.showErrorDialog(_t('The email address linked to your account must be entered.')); } else if (!this.state.password || !this.state.password2) { @@ -173,11 +206,21 @@ module.exports = React.createClass({ const Field = sdk.getComponent('elements.Field'); let errorText = null; - const err = this.state.errorText || this.props.defaultServerDiscoveryError; + const err = this.state.errorText; if (err) { errorText =