Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Allow registering with email if no ID Server
Browse files Browse the repository at this point in the history
If the server advertises that it supports doing so

This version uses a random me.dbkr prefix until the MSC is
written.

Requires matrix-org/matrix-js-sdk#1017
Implements matrix-org/matrix-spec-proposals#2233
  • Loading branch information
dbkr committed Aug 16, 2019
1 parent ded2297 commit e705d11
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
27 changes: 21 additions & 6 deletions src/components/structures/auth/Registration.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 <div className="mx_AuthBody_spinner">
<Spinner />
</div>;
Expand All @@ -550,6 +564,7 @@ module.exports = React.createClass({
flows={this.state.flows}
serverConfig={this.props.serverConfig}
canSubmit={!this.state.serverErrorIsFatal}
serverCapabilities={this.state.serverCaps}
/>;
}
},
Expand Down
4 changes: 3 additions & 1 deletion src/components/views/auth/RegistrationForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit e705d11

Please sign in to comment.