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
This commit is contained in:
David Baker 2019-08-16 11:57:32 +01:00
parent ded2297523
commit e705d110af
2 changed files with 25 additions and 8 deletions

View file

@ -98,6 +98,9 @@ module.exports = React.createClass({
// component without it. // component without it.
matrixClient: null, matrixClient: null,
// the capabilities object from the server
serverCaps: null,
// The user ID we've just registered // The user ID we've just registered
registeredUsername: null, registeredUsername: null,
@ -204,13 +207,24 @@ module.exports = React.createClass({
} }
const {hsUrl, isUrl} = serverConfig; const {hsUrl, isUrl} = serverConfig;
this.setState({ const cli = Matrix.createClient({
matrixClient: Matrix.createClient({
baseUrl: hsUrl, baseUrl: hsUrl,
idBaseUrl: isUrl, idBaseUrl: isUrl,
}),
}); });
this.setState({busy: false});
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,
});
try { try {
await this._makeRegisterRequest({}); await this._makeRegisterRequest({});
// This should never succeed since we specified an empty // 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) { } else if (!this.state.matrixClient && !this.state.busy) {
return null; return null;
} else if (this.state.busy || !this.state.flows) { } else if (this.state.busy || !this.state.flows | this.state.serverCaps === null) {
return <div className="mx_AuthBody_spinner"> return <div className="mx_AuthBody_spinner">
<Spinner /> <Spinner />
</div>; </div>;
@ -550,6 +564,7 @@ module.exports = React.createClass({
flows={this.state.flows} flows={this.state.flows}
serverConfig={this.props.serverConfig} serverConfig={this.props.serverConfig}
canSubmit={!this.state.serverErrorIsFatal} canSubmit={!this.state.serverErrorIsFatal}
serverCapabilities={this.state.serverCaps}
/>; />;
} }
}, },

View file

@ -55,6 +55,7 @@ module.exports = React.createClass({
flows: PropTypes.arrayOf(PropTypes.object).isRequired, flows: PropTypes.arrayOf(PropTypes.object).isRequired,
serverConfig: PropTypes.instanceOf(ValidatedServerConfig).isRequired, serverConfig: PropTypes.instanceOf(ValidatedServerConfig).isRequired,
canSubmit: PropTypes.bool, canSubmit: PropTypes.bool,
serverCapabilities: PropTypes.object,
}, },
getDefaultProps: function() { getDefaultProps: function() {
@ -436,8 +437,9 @@ module.exports = React.createClass({
}, },
_showEmail() { _showEmail() {
const idServerRequired = !this.props.serverCapabilities['me.dbkr.idomyownemail'];
const haveIs = Boolean(this.props.serverConfig.isUrl); 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 false;
} }
return true; return true;