From 6597db6328f15a1bd2a834c789778bbbd76e9662 Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Thu, 31 Jan 2019 12:01:17 -0600 Subject: [PATCH] Simplify login server URL state --- src/components/structures/auth/Login.js | 54 ++++++++++++------------- 1 file changed, 25 insertions(+), 29 deletions(-) diff --git a/src/components/structures/auth/Login.js b/src/components/structures/auth/Login.js index d1b0aad31a..c5cdba3caa 100644 --- a/src/components/structures/auth/Login.js +++ b/src/components/structures/auth/Login.js @@ -88,8 +88,8 @@ module.exports = React.createClass({ loginIncorrect: false, serverType: null, - enteredHomeserverUrl: this.props.customHsUrl || this.props.defaultHsUrl, - enteredIdentityServerUrl: this.props.customIsUrl || this.props.defaultIsUrl, + enteredHsUrl: this.props.customHsUrl || this.props.defaultHsUrl, + enteredIsUrl: this.props.customIsUrl || this.props.defaultIsUrl, // used for preserving form values when changing homeserver username: "", @@ -102,8 +102,6 @@ module.exports = React.createClass({ currentFlow: "m.login.password", // .well-known discovery - discoveredHsUrl: "", - discoveredIsUrl: "", discoveryError: "", findingHomeserver: false, }; @@ -308,10 +306,10 @@ module.exports = React.createClass({ errorText: null, // reset err messages }; if (config.hsUrl !== undefined) { - newState.enteredHomeserverUrl = config.hsUrl; + newState.enteredHsUrl = config.hsUrl; } if (config.isUrl !== undefined) { - newState.enteredIdentityServerUrl = config.isUrl; + newState.enteredIsUrl = config.isUrl; } this.props.onServerConfigChange(config); @@ -377,7 +375,10 @@ module.exports = React.createClass({ _tryWellKnownDiscovery: async function(serverName) { if (!serverName.trim()) { // Nothing to discover - this.setState({discoveryError: "", discoveredHsUrl: "", discoveredIsUrl: "", findingHomeserver: false}); + this.setState({ + discoveryError: "", + findingHomeserver: false, + }); return; } @@ -387,33 +388,28 @@ module.exports = React.createClass({ const state = discovery["m.homeserver"].state; if (state !== AutoDiscovery.SUCCESS && state !== AutoDiscovery.PROMPT) { this.setState({ - discoveredHsUrl: "", - discoveredIsUrl: "", discoveryError: discovery["m.homeserver"].error, findingHomeserver: false, }); } else if (state === AutoDiscovery.PROMPT) { this.setState({ - discoveredHsUrl: "", - discoveredIsUrl: "", discoveryError: "", findingHomeserver: false, }); } else if (state === AutoDiscovery.SUCCESS) { this.setState({ - discoveredHsUrl: discovery["m.homeserver"].base_url, - discoveredIsUrl: - discovery["m.identity_server"].state === AutoDiscovery.SUCCESS - ? discovery["m.identity_server"].base_url - : "", discoveryError: "", findingHomeserver: false, }); + this.onServerConfigChange({ + hsUrl: discovery["m.homeserver"].base_url, + isUrl: discovery["m.identity_server"].state === AutoDiscovery.SUCCESS + ? discovery["m.identity_server"].base_url + : "", + }); } else { console.warn("Unknown state for m.homeserver in discovery response: ", discovery); this.setState({ - discoveredHsUrl: "", - discoveredIsUrl: "", discoveryError: _t("Unknown failure discovering homeserver"), findingHomeserver: false, }); @@ -429,8 +425,8 @@ module.exports = React.createClass({ _initLoginLogic: function(hsUrl, isUrl) { const self = this; - hsUrl = hsUrl || this.state.enteredHomeserverUrl; - isUrl = isUrl || this.state.enteredIdentityServerUrl; + hsUrl = hsUrl || this.state.enteredHsUrl; + isUrl = isUrl || this.state.enteredIsUrl; const fallbackHsUrl = hsUrl === this.props.defaultHsUrl ? this.props.fallbackHsUrl : null; @@ -440,8 +436,8 @@ module.exports = React.createClass({ this._loginLogic = loginLogic; this.setState({ - enteredHomeserverUrl: hsUrl, - enteredIdentityServerUrl: isUrl, + enteredHsUrl: hsUrl, + enteredIsUrl: isUrl, busy: true, loginIncorrect: false, }); @@ -507,8 +503,8 @@ module.exports = React.createClass({ if (err.cors === 'rejected') { if (window.location.protocol === 'https:' && - (this.state.enteredHomeserverUrl.startsWith("http:") || - !this.state.enteredHomeserverUrl.startsWith("http")) + (this.state.enteredHsUrl.startsWith("http:") || + !this.state.enteredHsUrl.startsWith("http")) ) { errorText = { _t("Can't connect to homeserver via HTTP when an HTTPS URL is in your browser bar. " + @@ -532,7 +528,7 @@ module.exports = React.createClass({ { 'a': (sub) => { return { sub }; }, }, @@ -572,7 +568,7 @@ module.exports = React.createClass({ break; case ServerType.PREMIUM: serverDetails = );