From 366f7e277a289899288b6b0317b4f6fe97d89ea2 Mon Sep 17 00:00:00 2001 From: David Baker Date: Wed, 7 Aug 2019 11:15:56 +0100 Subject: [PATCH] Make registration work without an IS. --- src/components/views/auth/RegistrationForm.js | 51 +++++++++++++++---- src/components/views/auth/ServerConfig.js | 2 +- src/i18n/strings/en_EN.json | 2 + src/utils/AutoDiscoveryUtils.js | 18 ++++--- 4 files changed, 57 insertions(+), 16 deletions(-) diff --git a/src/components/views/auth/RegistrationForm.js b/src/components/views/auth/RegistrationForm.js index ad663bee47..cd3dab12ac 100644 --- a/src/components/views/auth/RegistrationForm.js +++ b/src/components/views/auth/RegistrationForm.js @@ -91,14 +91,25 @@ module.exports = React.createClass({ const self = this; if (this.state.email == '') { + const haveIs = Boolean(this.props.serverConfig.isUrl); + + let desc; + if (haveIs) { + desc = _t( + "If you don't specify an email address, you won't be able to reset your password. " + + "Are you sure?", + ); + } else { + desc = _t( + "No Identity Server is configured so you cannot add add an email address in order to " + + "reset your password in the future.", + ); + } + const QuestionDialog = sdk.getComponent("dialogs.QuestionDialog"); Modal.createTrackedDialog('If you don\'t specify an email address...', '', QuestionDialog, { title: _t("Warning!"), - description: -
- { _t("If you don't specify an email address, you won't be able to reset your password. " + - "Are you sure?") } -
, + description: desc, button: _t("Continue"), onFinished: function(confirmed) { if (confirmed) { @@ -423,8 +434,16 @@ module.exports = React.createClass({ }); }, + _showEmail() { + const haveIs = Boolean(this.props.serverConfig.isUrl); + if (!haveIs || !this._authStepIsUsed('m.login.email.identity')) { + return false; + } + return true; + }, + renderEmail() { - if (!this._authStepIsUsed('m.login.email.identity')) { + if (!this._showEmail()) { return null; } const Field = sdk.getComponent('elements.Field'); @@ -473,7 +492,8 @@ module.exports = React.createClass({ renderPhoneNumber() { const threePidLogin = !SdkConfig.get().disable_3pid_login; - if (!threePidLogin || !this._authStepIsUsed('m.login.msisdn')) { + const haveIs = Boolean(this.props.serverConfig.isUrl); + if (!threePidLogin || !haveIs || !this._authStepIsUsed('m.login.msisdn')) { return null; } const CountryDropdown = sdk.getComponent('views.auth.CountryDropdown'); @@ -547,6 +567,19 @@ module.exports = React.createClass({ ); + const emailHelperText = this._showEmail() ?
+ {_t("Use an email address to recover your account.") + " "} + {_t("Other users can invite you to rooms using your contact details.")} +
: null; + + const haveIs = Boolean(this.props.serverConfig.isUrl); + const noIsText = haveIs ? null :
+ {_t( + "No Identity Server is configured: no email addreses can be added. " + + "You will be unable to reset your password.", + )} +
; + return (

@@ -565,8 +598,8 @@ module.exports = React.createClass({ {this.renderEmail()} {this.renderPhoneNumber()}

- {_t("Use an email address to recover your account.") + " "} - {_t("Other users can invite you to rooms using your contact details.")} + { emailHelperText } + { noIsText } { registerButton } diff --git a/src/components/views/auth/ServerConfig.js b/src/components/views/auth/ServerConfig.js index 9dcc2c9abe..467ba307d0 100644 --- a/src/components/views/auth/ServerConfig.js +++ b/src/components/views/auth/ServerConfig.js @@ -210,7 +210,7 @@ export default class ServerConfig extends React.PureComponent { ": "Create your Matrix account on ", "Use an email address to recover your account.": "Use an email address to recover your account.", "Other users can invite you to rooms using your contact details.": "Other users can invite you to rooms using your contact details.", + "No Identity Server is configured: no email addreses can be added. You will be unable to reset your password.": "No Identity Server is configured: no email addreses can be added. You will be unable to reset your password.", "Other servers": "Other servers", "Enter custom server URLs What does this mean?": "Enter custom server URLs What does this mean?", "Homeserver URL": "Homeserver URL", diff --git a/src/utils/AutoDiscoveryUtils.js b/src/utils/AutoDiscoveryUtils.js index c21377a034..e94c454a3e 100644 --- a/src/utils/AutoDiscoveryUtils.js +++ b/src/utils/AutoDiscoveryUtils.js @@ -18,6 +18,7 @@ import React from 'react'; import {AutoDiscovery} from "matrix-js-sdk"; import {_t, _td, newTranslatableError} from "../languageHandler"; import {makeType} from "./TypeUtils"; +import SdkConfig from '../SdkConfig'; const LIVELINESS_DISCOVERY_ERRORS = [ AutoDiscovery.ERROR_INVALID_HOMESERVER, @@ -133,11 +134,14 @@ export default class AutoDiscoveryUtils { "m.homeserver": { base_url: homeserverUrl, }, - "m.identity_server": { - base_url: identityUrl, - }, }; + if (identityUrl) { + wellknownConfig['m.identity_server'] = { + base_url: identityUrl, + }; + } + const result = await AutoDiscovery.fromDiscoveryConfig(wellknownConfig); const url = new URL(homeserverUrl); @@ -179,14 +183,16 @@ export default class AutoDiscoveryUtils { const hsResult = discoveryResult['m.homeserver']; const isResult = discoveryResult['m.identity_server']; + const defaultConfig = SdkConfig.get()["validated_server_config"]; + // Validate the identity server first because an invalid identity server causes // and invalid homeserver, which may not be picked up correctly. - // Note: In the cases where we rely on this pre-populated "https://vector.im" (namely + // Note: In the cases where we rely on the default IS from the config (namely // lack of identity server provided by the discovery method), we intentionally do not - // validate it. We already know the IS is an IS, and this helps some off-the-grid usage + // validate it. This has already been validated and this helps some off-the-grid usage // of Riot. - let preferredIdentityUrl = "https://vector.im"; + let preferredIdentityUrl = defaultConfig && defaultConfig['isUrl']; if (isResult && isResult.state === AutoDiscovery.SUCCESS) { preferredIdentityUrl = isResult["base_url"]; } else if (isResult && isResult.state !== AutoDiscovery.PROMPT) {