From e705d110af3edb0656b8b000d8b3cb875acb40ea Mon Sep 17 00:00:00 2001 From: David Baker Date: Fri, 16 Aug 2019 11:57:32 +0100 Subject: [PATCH] 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 | 27 ++++++++++++++----- src/components/views/auth/RegistrationForm.js | 4 ++- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/components/structures/auth/Registration.js b/src/components/structures/auth/Registration.js index 1c094cf8624..0d3fe29967c 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; + 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: Matrix.createClient({ - baseUrl: hsUrl, - idBaseUrl: isUrl, - }), + 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 f3b9640e168..368ab599e32 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;