From e705d110af3edb0656b8b000d8b3cb875acb40ea Mon Sep 17 00:00:00 2001 From: David Baker Date: Fri, 16 Aug 2019 11:57:32 +0100 Subject: [PATCH 1/5] Allow registering with email if no ID Server If the server advertises that it supports doing so This version uses a random me.dbkr prefix until the MSC is written. Requires https://github.com/matrix-org/matrix-js-sdk/pull/1017 Implements https://github.com/matrix-org/matrix-doc/pull/2233 --- .../structures/auth/Registration.js | 29 ++++++++++++++----- src/components/views/auth/RegistrationForm.js | 4 ++- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/components/structures/auth/Registration.js b/src/components/structures/auth/Registration.js index 1c094cf862..0d3fe29967 100644 --- a/src/components/structures/auth/Registration.js +++ b/src/components/structures/auth/Registration.js @@ -98,6 +98,9 @@ module.exports = React.createClass({ // component without it. matrixClient: null, + // the capabilities object from the server + serverCaps: null, + // The user ID we've just registered registeredUsername: null, @@ -204,13 +207,24 @@ module.exports = React.createClass({ } const {hsUrl, isUrl} = serverConfig; - this.setState({ - matrixClient: Matrix.createClient({ - baseUrl: hsUrl, - idBaseUrl: isUrl, - }), + const cli = Matrix.createClient({ + baseUrl: hsUrl, + idBaseUrl: isUrl, + }); + + let caps = null; + try { + caps = await cli.getServerCapabilities(); + caps = caps || {}; + } catch (e) { + console.log("Unable to fetch server capabilities", e); + } + + this.setState({ + matrixClient: cli, + serverCaps: caps, + busy: false, }); - this.setState({busy: false}); try { await this._makeRegisterRequest({}); // This should never succeed since we specified an empty @@ -523,7 +537,7 @@ module.exports = React.createClass({ />; } else if (!this.state.matrixClient && !this.state.busy) { return null; - } else if (this.state.busy || !this.state.flows) { + } else if (this.state.busy || !this.state.flows | this.state.serverCaps === null) { return
; @@ -550,6 +564,7 @@ module.exports = React.createClass({ flows={this.state.flows} serverConfig={this.props.serverConfig} canSubmit={!this.state.serverErrorIsFatal} + serverCapabilities={this.state.serverCaps} />; } }, diff --git a/src/components/views/auth/RegistrationForm.js b/src/components/views/auth/RegistrationForm.js index f3b9640e16..368ab599e3 100644 --- a/src/components/views/auth/RegistrationForm.js +++ b/src/components/views/auth/RegistrationForm.js @@ -55,6 +55,7 @@ module.exports = React.createClass({ flows: PropTypes.arrayOf(PropTypes.object).isRequired, serverConfig: PropTypes.instanceOf(ValidatedServerConfig).isRequired, canSubmit: PropTypes.bool, + serverCapabilities: PropTypes.object, }, getDefaultProps: function() { @@ -436,8 +437,9 @@ module.exports = React.createClass({ }, _showEmail() { + const idServerRequired = !this.props.serverCapabilities['me.dbkr.idomyownemail']; const haveIs = Boolean(this.props.serverConfig.isUrl); - if (!haveIs || !this._authStepIsUsed('m.login.email.identity')) { + if ((idServerRequired && !haveIs) || !this._authStepIsUsed('m.login.email.identity')) { return false; } return true; From 19c7a4627da348d28a608b4e5137abf3e03f592c Mon Sep 17 00:00:00 2001 From: David Baker Date: Fri, 16 Aug 2019 12:24:52 +0100 Subject: [PATCH 2/5] fix test --- test/components/structures/auth/Registration-test.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/components/structures/auth/Registration-test.js b/test/components/structures/auth/Registration-test.js index 6a8b35fbc0..38c7ae3849 100644 --- a/test/components/structures/auth/Registration-test.js +++ b/test/components/structures/auth/Registration-test.js @@ -69,9 +69,10 @@ describe('Registration', function() { const root = render(); - // Set non-empty flow & matrixClient to get past the loading spinner + // Set non-empty flows, capabilities & matrixClient to get past the loading spinner root.setState({ flows: [], + serverCaps: {}, matrixClient: {}, busy: false, }); From 41a9db32242ebf422bd8a725df08af4b9adbd2c1 Mon Sep 17 00:00:00 2001 From: David Baker Date: Fri, 16 Aug 2019 15:07:15 +0100 Subject: [PATCH 3/5] Use new flag in /versions --- src/components/structures/auth/Registration.js | 15 +++++++-------- src/components/views/auth/RegistrationForm.js | 5 ++--- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/components/structures/auth/Registration.js b/src/components/structures/auth/Registration.js index 0d3fe29967..af51ca7df0 100644 --- a/src/components/structures/auth/Registration.js +++ b/src/components/structures/auth/Registration.js @@ -98,8 +98,8 @@ module.exports = React.createClass({ // component without it. matrixClient: null, - // the capabilities object from the server - serverCaps: null, + // whether the HS requires an ID server to register with a threepid + serverRequiresIdServer: null, // The user ID we've just registered registeredUsername: null, @@ -212,17 +212,16 @@ module.exports = React.createClass({ idBaseUrl: isUrl, }); - let caps = null; + let serverRequiresIdServer = true; try { - caps = await cli.getServerCapabilities(); - caps = caps || {}; + serverRequiresIdServer = await cli.doesServerRequireIdServerParam(); } catch (e) { - console.log("Unable to fetch server capabilities", e); + console.log("Unable to determine is server needs id_server param", e); } this.setState({ matrixClient: cli, - serverCaps: caps, + serverRequiresIdServer, busy: false, }); try { @@ -564,7 +563,7 @@ module.exports = React.createClass({ flows={this.state.flows} serverConfig={this.props.serverConfig} canSubmit={!this.state.serverErrorIsFatal} - serverCapabilities={this.state.serverCaps} + serverRequiresIdServer={this.state.serverRequiresIdServer} />; } }, diff --git a/src/components/views/auth/RegistrationForm.js b/src/components/views/auth/RegistrationForm.js index 368ab599e3..cf1b074fe1 100644 --- a/src/components/views/auth/RegistrationForm.js +++ b/src/components/views/auth/RegistrationForm.js @@ -55,7 +55,7 @@ module.exports = React.createClass({ flows: PropTypes.arrayOf(PropTypes.object).isRequired, serverConfig: PropTypes.instanceOf(ValidatedServerConfig).isRequired, canSubmit: PropTypes.bool, - serverCapabilities: PropTypes.object, + serverRequiresIdServer: PropTypes.bool, }, getDefaultProps: function() { @@ -437,9 +437,8 @@ module.exports = React.createClass({ }, _showEmail() { - const idServerRequired = !this.props.serverCapabilities['me.dbkr.idomyownemail']; const haveIs = Boolean(this.props.serverConfig.isUrl); - if ((idServerRequired && !haveIs) || !this._authStepIsUsed('m.login.email.identity')) { + if ((this.props.serverRequiresIdServer && !haveIs) || !this._authStepIsUsed('m.login.email.identity')) { return false; } return true; From 3c4c595f7989a644f03502677ea02db090addb2d Mon Sep 17 00:00:00 2001 From: David Baker Date: Fri, 16 Aug 2019 15:27:11 +0100 Subject: [PATCH 4/5] remove old serverCaps --- src/components/structures/auth/Registration.js | 2 +- test/components/structures/auth/Registration-test.js | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/components/structures/auth/Registration.js b/src/components/structures/auth/Registration.js index af51ca7df0..63c5b267cf 100644 --- a/src/components/structures/auth/Registration.js +++ b/src/components/structures/auth/Registration.js @@ -536,7 +536,7 @@ module.exports = React.createClass({ />; } else if (!this.state.matrixClient && !this.state.busy) { return null; - } else if (this.state.busy || !this.state.flows | this.state.serverCaps === null) { + } else if (this.state.busy || !this.state.flows) { return
; diff --git a/test/components/structures/auth/Registration-test.js b/test/components/structures/auth/Registration-test.js index 38c7ae3849..3d4c8f921a 100644 --- a/test/components/structures/auth/Registration-test.js +++ b/test/components/structures/auth/Registration-test.js @@ -72,7 +72,6 @@ describe('Registration', function() { // Set non-empty flows, capabilities & matrixClient to get past the loading spinner root.setState({ flows: [], - serverCaps: {}, matrixClient: {}, busy: false, }); From a87fb7eaa26296d60d8ba8225dfc95af3a368ed3 Mon Sep 17 00:00:00 2001 From: David Baker Date: Fri, 16 Aug 2019 15:36:41 +0100 Subject: [PATCH 5/5] also remove from comment --- test/components/structures/auth/Registration-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/components/structures/auth/Registration-test.js b/test/components/structures/auth/Registration-test.js index 3d4c8f921a..38188b2536 100644 --- a/test/components/structures/auth/Registration-test.js +++ b/test/components/structures/auth/Registration-test.js @@ -69,7 +69,7 @@ describe('Registration', function() { const root = render(); - // Set non-empty flows, capabilities & matrixClient to get past the loading spinner + // Set non-empty flows & matrixClient to get past the loading spinner root.setState({ flows: [], matrixClient: {},