From 6707186edcec64e314dfeebbe3900100686d484f Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Fri, 7 Dec 2018 15:36:49 -0700 Subject: [PATCH] Change how the default server name and HS URL interact They are now independent of each other. If both are specified in the config, the user will see an error and be prevented from logging in. The expected behaviour is that when a default server name is given, we do a .well-known lookup to find the default homeserver (and block the UI while we do this to prevent it from using matrix.org while we go out and find more information). If the config specifies just a default homeserver URL however, we don't do anything special. --- res/css/structures/login/_Login.scss | 7 ------- src/components/structures/MatrixChat.js | 22 ++++++++++++++++++--- src/components/structures/login/Login.js | 5 +---- src/components/views/login/PasswordLogin.js | 14 ++----------- src/i18n/strings/en_EN.json | 3 ++- 5 files changed, 24 insertions(+), 27 deletions(-) diff --git a/res/css/structures/login/_Login.scss b/res/css/structures/login/_Login.scss index 9b19c24b14..1264d2a30f 100644 --- a/res/css/structures/login/_Login.scss +++ b/res/css/structures/login/_Login.scss @@ -180,13 +180,6 @@ limitations under the License. margin-bottom: 12px; } -.mx_Login_subtext { - display: block; - font-size: 0.8em; - text-align: center; - margin: 10px; -} - .mx_Login_type_container { display: flex; margin-bottom: 14px; diff --git a/src/components/structures/MatrixChat.js b/src/components/structures/MatrixChat.js index dc3872664b..e93234c679 100644 --- a/src/components/structures/MatrixChat.js +++ b/src/components/structures/MatrixChat.js @@ -298,7 +298,16 @@ export default React.createClass({ // Set up the default URLs (async) if (this.getDefaultServerName() && !this.getDefaultHsUrl(false)) { + this.setState({loadingDefaultHomeserver: true}); this._tryDiscoverDefaultHomeserver(this.getDefaultServerName()); + } else if (this.getDefaultServerName() && this.getDefaultHsUrl(false)) { + // Ideally we would somehow only communicate this to the server admins, but + // given this is at login time we can't really do much besides hope that people + // will check their settings. + this.setState({ + defaultServerName: null, // To un-hide any secrets people might be keeping + defaultServerDiscoveryError: _t("Invalid configuration: Cannot supply a default homeserver URL and a default server name"), + }); } // Set a default HS with query param `hs_url` @@ -1756,13 +1765,20 @@ export default React.createClass({ const state = discovery["m.homeserver"].state; if (state !== AutoDiscovery.SUCCESS) { console.error("Failed to discover homeserver on startup:", discovery); - this.setState({defaultServerDiscoveryError: discovery["m.homeserver"].error}); + this.setState({ + defaultServerDiscoveryError: discovery["m.homeserver"].error, + loadingDefaultHomeserver: false, + }); } else { const hsUrl = discovery["m.homeserver"].base_url; const isUrl = discovery["m.identity_server"].state === AutoDiscovery.SUCCESS ? discovery["m.identity_server"].base_url : "https://vector.im"; - this.setState({defaultHsUrl: hsUrl, defaultIsUrl: isUrl}); + this.setState({ + defaultHsUrl: hsUrl, + defaultIsUrl: isUrl, + loadingDefaultHomeserver: false, + }); } }, @@ -1780,7 +1796,7 @@ export default React.createClass({ render: function() { // console.log(`Rendering MatrixChat with view ${this.state.view}`); - if (this.state.view === VIEWS.LOADING || this.state.view === VIEWS.LOGGING_IN) { + if (this.state.view === VIEWS.LOADING || this.state.view === VIEWS.LOGGING_IN || this.state.loadingDefaultHomeserver) { const Spinner = sdk.getComponent('elements.Spinner'); return (
diff --git a/src/components/structures/login/Login.js b/src/components/structures/login/Login.js index 08e94e413a..6dcbfe7e47 100644 --- a/src/components/structures/login/Login.js +++ b/src/components/structures/login/Login.js @@ -470,9 +470,6 @@ module.exports = React.createClass({ _renderPasswordStep: function() { const PasswordLogin = sdk.getComponent('login.PasswordLogin'); - const hsName = this.state.enteredHomeserverUrl === this.props.defaultHsUrl - ? this.props.defaultServerName - : null; return ( ); }, diff --git a/src/components/views/login/PasswordLogin.js b/src/components/views/login/PasswordLogin.js index 582ccf94dd..04aaae3630 100644 --- a/src/components/views/login/PasswordLogin.js +++ b/src/components/views/login/PasswordLogin.js @@ -252,21 +252,12 @@ class PasswordLogin extends React.Component { } let matrixIdText = _t('Matrix ID'); - let matrixIdSubtext = null; if (this.props.hsName) { matrixIdText = _t('%(serverName)s Matrix ID', {serverName: this.props.hsName}); - } - if (this.props.hsUrl) { + } else { try { const parsedHsUrl = new URL(this.props.hsUrl); - if (!this.props.hsName) { - matrixIdText = _t('%(serverName)s Matrix ID', {serverName: parsedHsUrl.hostname}); - } else if (parsedHsUrl.hostname !== this.props.hsName) { - matrixIdSubtext = _t('%(serverName)s is located at %(homeserverUrl)s', { - serverName: this.props.hsName, - homeserverUrl: this.props.hsUrl, - }); - } + matrixIdText = _t('%(serverName)s Matrix ID', {serverName: parsedHsUrl.hostname}); } catch (e) { // ignore } @@ -304,7 +295,6 @@ class PasswordLogin extends React.Component {
{ loginType } - { matrixIdSubtext } { loginField } {this._passwordField = e;}} type="password" name="password" diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index 87bc05c81c..8c5f3f5351 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -721,8 +721,8 @@ "User name": "User name", "Mobile phone number": "Mobile phone number", "Forgot your password?": "Forgot your password?", + "Matrix ID": "Matrix ID", "%(serverName)s Matrix ID": "%(serverName)s Matrix ID", - "%(serverName)s is located at %(homeserverUrl)s": "%(serverName)s is located at %(homeserverUrl)s", "Sign in with": "Sign in with", "Email address": "Email address", "Sign in": "Sign in", @@ -1114,6 +1114,7 @@ "You are currently using Riot anonymously as a guest.": "You are currently using Riot anonymously as a guest.", "If you would like to create a Matrix account you can register now.": "If you would like to create a Matrix account you can register now.", "Login": "Login", + "Invalid configuration: Cannot supply a default homeserver URL and a default server name": "Invalid configuration: Cannot supply a default homeserver URL and a default server name", "Failed to reject invitation": "Failed to reject invitation", "This room is not public. You will not be able to rejoin without an invite.": "This room is not public. You will not be able to rejoin without an invite.", "Are you sure you want to leave the room '%(roomName)s'?": "Are you sure you want to leave the room '%(roomName)s'?",