From 0f4092dcbc1c94934da9094f05516ca0215ac1ee Mon Sep 17 00:00:00 2001 From: David Baker Date: Wed, 13 Feb 2019 18:12:34 +0000 Subject: [PATCH 1/3] Fix registration after clicking email link We weren't correctly jumping into the appropriate bit of the registration flow when coming in from an email link. * If we have client secret / sessionId, go straight to registration phase * Don't reset server URLs when the server type component tells us its initial value * Confusingly, pass the custom server URL as 'default server URL' to the custom server type, as this is what we want the inital section to be based on. Fixes https://github.com/vector-im/riot-web/issues/8490 --- .../structures/auth/Registration.js | 30 +++++++++++++++---- .../views/auth/ServerTypeSelector.js | 6 +++- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/components/structures/auth/Registration.js b/src/components/structures/auth/Registration.js index 69abd8b88b..7629181d2d 100644 --- a/src/components/structures/auth/Registration.js +++ b/src/components/structures/auth/Registration.js @@ -64,6 +64,15 @@ module.exports = React.createClass({ getInitialState: function() { const customURLsAllowed = !SdkConfig.get()['disable_custom_urls']; + let initialPhase = PHASE_SERVER_DETAILS; + if ( + // if we have these two, skip to the good bit + (this.props.clientSecret && this.props.sessionId) || + // or if custom URLs aren't allowed, skip them + !customURLsAllowed + ) { + initialPhase = PHASE_REGISTRATION; + } return { busy: false, @@ -87,7 +96,7 @@ module.exports = React.createClass({ hsUrl: this.props.customHsUrl, isUrl: this.props.customIsUrl, // Phase of the overall registration dialog. - phase: customURLsAllowed ? PHASE_SERVER_DETAILS : PHASE_REGISTRATION, + phase: initialPhase, flows: null, }; }, @@ -111,7 +120,7 @@ module.exports = React.createClass({ }); }, - onServerTypeChange(type) { + onServerTypeChange(type, initial) { this.setState({ serverType: type, }); @@ -137,9 +146,15 @@ module.exports = React.createClass({ hsUrl: this.props.defaultHsUrl, isUrl: this.props.defaultIsUrl, }); - this.setState({ - phase: PHASE_SERVER_DETAILS, - }); + // if this is the initial value from the control and we're + // already in the registration phase, don't go back to the + // server details phase (but do if it's actually a change resulting + // from user interaction). + if (!initial || !this.state.phase === PHASE_REGISTRATION) { + this.setState({ + phase: PHASE_SERVER_DETAILS, + }); + } break; } }, @@ -372,9 +387,12 @@ module.exports = React.createClass({ // If we're on a different phase, we only show the server type selector, // which is always shown if we allow custom URLs at all. if (PHASES_ENABLED && this.state.phase !== PHASE_SERVER_DETAILS) { + // if we've been given a custom HS URL we should actually pass that, so + // that the appropriate section is selected at the start to match the + // homeserver URL we're using return
; diff --git a/src/components/views/auth/ServerTypeSelector.js b/src/components/views/auth/ServerTypeSelector.js index de76e6acf9..bda7d8d069 100644 --- a/src/components/views/auth/ServerTypeSelector.js +++ b/src/components/views/auth/ServerTypeSelector.js @@ -90,7 +90,11 @@ export default class ServerTypeSelector extends React.PureComponent { selected: type, }; if (onChange) { - onChange(type); + // FIXME: Supply a second 'initial' param here to flag that this is + // initialising the value rather than from user interaction + // (which sometuimes we'll want to ignore). Must be a better way + // to do this. + onChange(type, true); } } From 5b6454315954288f62751a7b0c85a629a170590c Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Wed, 13 Feb 2019 19:05:17 +0000 Subject: [PATCH 2/3] Typo Co-Authored-By: dbkr --- src/components/views/auth/ServerTypeSelector.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/views/auth/ServerTypeSelector.js b/src/components/views/auth/ServerTypeSelector.js index bda7d8d069..7a28eec0ed 100644 --- a/src/components/views/auth/ServerTypeSelector.js +++ b/src/components/views/auth/ServerTypeSelector.js @@ -92,7 +92,7 @@ export default class ServerTypeSelector extends React.PureComponent { if (onChange) { // FIXME: Supply a second 'initial' param here to flag that this is // initialising the value rather than from user interaction - // (which sometuimes we'll want to ignore). Must be a better way + // (which sometimes we'll want to ignore). Must be a better way // to do this. onChange(type, true); } From c3ca2b4d463fac688a5f113580871480fb10c8f9 Mon Sep 17 00:00:00 2001 From: David Baker Date: Wed, 13 Feb 2019 19:06:44 +0000 Subject: [PATCH 3/3] add comment --- src/components/structures/auth/Registration.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/components/structures/auth/Registration.js b/src/components/structures/auth/Registration.js index 7629181d2d..6b578f0f68 100644 --- a/src/components/structures/auth/Registration.js +++ b/src/components/structures/auth/Registration.js @@ -67,6 +67,8 @@ module.exports = React.createClass({ let initialPhase = PHASE_SERVER_DETAILS; if ( // if we have these two, skip to the good bit + // (they could come in from the URL params in a + // registration email link) (this.props.clientSecret && this.props.sessionId) || // or if custom URLs aren't allowed, skip them !customURLsAllowed