From ec35423a0d51793a7ed5f6ff920527b44c7bd74a Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Fri, 22 Feb 2019 16:16:05 +0000 Subject: [PATCH] Use correct initial phase for server type The initial phase of registration can differ by the default server type. In particular, the Matrix.org HS type wants to skip to the registration form. Fixes https://github.com/vector-im/riot-web/issues/8862 --- .../structures/auth/Registration.js | 37 ++++++++++++++----- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/src/components/structures/auth/Registration.js b/src/components/structures/auth/Registration.js index b5040777db..711ec3c1d7 100644 --- a/src/components/structures/auth/Registration.js +++ b/src/components/structures/auth/Registration.js @@ -69,8 +69,10 @@ module.exports = React.createClass({ }, getInitialState: function() { + const serverType = ServerType.getTypeFromHsUrl(this.props.customHsUrl); + const customURLsAllowed = !SdkConfig.get()['disable_custom_urls']; - let initialPhase = PHASE_SERVER_DETAILS; + let initialPhase = this.getDefaultPhaseForServerType(serverType); if ( // if we have these two, skip to the good bit // (they could come in from the URL params in a @@ -81,6 +83,11 @@ module.exports = React.createClass({ // if other logic says to, skip to form this.props.skipServerDetails ) { + // TODO: It would seem we've now added enough conditions here that the initial + // phase will _always_ be the form. It's tempting to remove the complexity and + // just do that, but we keep tweaking and changing auth, so let's wait until + // things settle a bit. + // Filed https://github.com/vector-im/riot-web/issues/8886 to track this. initialPhase = PHASE_REGISTRATION; } @@ -102,7 +109,7 @@ module.exports = React.createClass({ // If we've been given a session ID, we're resuming // straight back into UI auth doingUIAuth: Boolean(this.props.sessionId), - serverType: ServerType.getTypeFromHsUrl(this.props.customHsUrl), + serverType, hsUrl: this.props.customHsUrl, isUrl: this.props.customIsUrl, // Phase of the overall registration dialog. @@ -130,6 +137,19 @@ module.exports = React.createClass({ }); }, + getDefaultPhaseForServerType(type) { + switch (type) { + case ServerType.FREE: { + // Move directly to the registration phase since the server + // details are fixed. + return PHASE_REGISTRATION; + } + case ServerType.PREMIUM: + case ServerType.ADVANCED: + return PHASE_SERVER_DETAILS; + } + }, + onServerTypeChange(type) { this.setState({ serverType: type, @@ -144,10 +164,6 @@ module.exports = React.createClass({ hsUrl, isUrl, }); - // Move directly to the registration phase since the server details are fixed. - this.setState({ - phase: PHASE_REGISTRATION, - }); break; } case ServerType.PREMIUM: @@ -156,12 +172,13 @@ module.exports = React.createClass({ hsUrl: this.props.defaultHsUrl, isUrl: this.props.defaultIsUrl, }); - // Reset back to server details on type change. - this.setState({ - phase: PHASE_SERVER_DETAILS, - }); break; } + + // Reset the phase to default phase for the server type. + this.setState({ + phase: this.getDefaultPhaseForServerType(type), + }); }, _replaceClient: async function() {