Merge pull request #3473 from matrix-org/jryans/rm-id-server-reg-and-reset

Remove id_server param from threepid_creds
This commit is contained in:
J. Ryan Stinnett 2019-09-24 17:34:45 +01:00 committed by GitHub
commit 17e42eacd4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 44 additions and 36 deletions

View file

@ -1,5 +1,6 @@
/* /*
Copyright 2015, 2016 OpenMarket Ltd Copyright 2015, 2016 OpenMarket Ltd
Copyright 2019 The Matrix.org Foundation C.I.C.
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -72,15 +73,21 @@ class PasswordReset {
* with a "message" property which contains a human-readable message detailing why * with a "message" property which contains a human-readable message detailing why
* the reset failed, e.g. "There is no mapped matrix user ID for the given email address". * the reset failed, e.g. "There is no mapped matrix user ID for the given email address".
*/ */
checkEmailLinkClicked() { async checkEmailLinkClicked() {
return this.client.setPassword({ const creds = {
type: "m.login.email.identity", sid: this.sessionId,
threepid_creds: { client_secret: this.clientSecret,
sid: this.sessionId, };
client_secret: this.clientSecret, if (await this.doesServerRequireIdServerParam()) {
id_server: this.identityServerDomain, creds.id_server = this.identityServerDomain;
}, }
}, this.password).catch(function(err) {
try {
await this.client.setPassword({
type: "m.login.email.identity",
threepid_creds: creds,
}, this.password);
} catch (err) {
if (err.httpStatus === 401) { if (err.httpStatus === 401) {
err.message = _t('Failed to verify email address: make sure you clicked the link in the email'); err.message = _t('Failed to verify email address: make sure you clicked the link in the email');
} else if (err.httpStatus === 404) { } else if (err.httpStatus === 404) {
@ -90,7 +97,7 @@ class PasswordReset {
err.message += ` (Status ${err.httpStatus})`; err.message += ` (Status ${err.httpStatus})`;
} }
throw err; throw err;
}); }
} }
} }

View file

@ -117,17 +117,18 @@ module.exports = createReactClass({
}); });
}, },
onVerify: function(ev) { onVerify: async function(ev) {
ev.preventDefault(); ev.preventDefault();
if (!this.reset) { if (!this.reset) {
console.error("onVerify called before submitPasswordReset!"); console.error("onVerify called before submitPasswordReset!");
return; return;
} }
this.reset.checkEmailLinkClicked().done((res) => { try {
await this.reset.checkEmailLinkClicked();
this.setState({ phase: PHASE_DONE }); this.setState({ phase: PHASE_DONE });
}, (err) => { } catch (err) {
this.showErrorDialog(err.message); this.showErrorDialog(err.message);
}); }
}, },
onSubmitForm: async function(ev) { onSubmitForm: async function(ev) {

View file

@ -453,45 +453,45 @@ export const MsisdnAuthEntry = createReactClass({
}); });
}, },
_onFormSubmit: function(e) { _onFormSubmit: async function(e) {
e.preventDefault(); e.preventDefault();
if (this.state.token == '') return; if (this.state.token == '') return;
this.setState({ this.setState({
errorText: null, errorText: null,
}); });
this.props.matrixClient.submitMsisdnToken( try {
this._sid, this.props.clientSecret, this.state.token, const result = await this.props.matrixClient.submitMsisdnToken(
).then((result) => { this._sid, this.props.clientSecret, this.state.token,
);
if (result.success) { if (result.success) {
const idServerParsedUrl = url.parse( const creds = {
this.props.matrixClient.getIdentityServerUrl(), sid: this._sid,
); client_secret: this.props.clientSecret,
};
if (await this.props.matrixClient.doesServerRequireIdServerParam()) {
const idServerParsedUrl = url.parse(
this.props.matrixClient.getIdentityServerUrl(),
);
creds.id_server = idServerParsedUrl.host;
}
this.props.submitAuthDict({ this.props.submitAuthDict({
type: MsisdnAuthEntry.LOGIN_TYPE, type: MsisdnAuthEntry.LOGIN_TYPE,
// TODO: Remove `threepid_creds` once servers support proper UIA // TODO: Remove `threepid_creds` once servers support proper UIA
// See https://github.com/vector-im/riot-web/issues/10312 // See https://github.com/vector-im/riot-web/issues/10312
threepid_creds: { threepid_creds: creds,
sid: this._sid, threepidCreds: creds,
client_secret: this.props.clientSecret,
id_server: idServerParsedUrl.host,
},
threepidCreds: {
sid: this._sid,
client_secret: this.props.clientSecret,
id_server: idServerParsedUrl.host,
},
}); });
} else { } else {
this.setState({ this.setState({
errorText: _t("Token incorrect"), errorText: _t("Token incorrect"),
}); });
} }
}).catch((e) => { } catch (e) {
this.props.fail(e); this.props.fail(e);
console.log("Failed to submit msisdn token"); console.log("Failed to submit msisdn token");
}).done(); }
}, },
render: function() { render: function() {