Merge pull request #3462 from matrix-org/jryans/msc2290
Use separate 3PID add and bind flow for supporting HSes
This commit is contained in:
commit
351a3ebd67
7 changed files with 229 additions and 46 deletions
|
@ -62,9 +62,7 @@ export default createReactClass({
|
|||
return;
|
||||
}
|
||||
this._addThreepid = new AddThreepid();
|
||||
// we always bind emails when registering, so let's do the
|
||||
// same here.
|
||||
this._addThreepid.addEmailAddress(emailAddress, true).done(() => {
|
||||
this._addThreepid.addEmailAddress(emailAddress).done(() => {
|
||||
Modal.createTrackedDialog('Verification Pending', '', QuestionDialog, {
|
||||
title: _t("Verification Pending"),
|
||||
description: _t(
|
||||
|
|
|
@ -161,7 +161,7 @@ export default class EmailAddresses extends React.Component {
|
|||
const task = new AddThreepid();
|
||||
this.setState({verifying: true, continueDisabled: true, addTask: task});
|
||||
|
||||
task.addEmailAddress(email, false).then(() => {
|
||||
task.addEmailAddress(email).then(() => {
|
||||
this.setState({continueDisabled: false});
|
||||
}).catch((err) => {
|
||||
console.error("Unable to add email address " + email + " " + err);
|
||||
|
|
|
@ -158,7 +158,7 @@ export default class PhoneNumbers extends React.Component {
|
|||
const task = new AddThreepid();
|
||||
this.setState({verifying: true, continueDisabled: true, addTask: task});
|
||||
|
||||
task.addMsisdn(phoneCountry, phoneNumber, false).then((response) => {
|
||||
task.addMsisdn(phoneCountry, phoneNumber).then((response) => {
|
||||
this.setState({continueDisabled: false, verifyMsisdn: response.msisdn});
|
||||
}).catch((err) => {
|
||||
console.error("Unable to add phone number " + phoneNumber + " " + err);
|
||||
|
|
|
@ -64,6 +64,44 @@ export class EmailAddress extends React.Component {
|
|||
}
|
||||
|
||||
async changeBinding({ bind, label, errorTitle }) {
|
||||
if (!await MatrixClientPeg.get().doesServerSupportSeparateAddAndBind()) {
|
||||
return this.changeBindingTangledAddBind({ bind, label, errorTitle });
|
||||
}
|
||||
|
||||
const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
|
||||
const { medium, address } = this.props.email;
|
||||
|
||||
try {
|
||||
if (bind) {
|
||||
const task = new AddThreepid();
|
||||
this.setState({
|
||||
verifying: true,
|
||||
continueDisabled: true,
|
||||
addTask: task,
|
||||
});
|
||||
await task.bindEmailAddress(address);
|
||||
this.setState({
|
||||
continueDisabled: false,
|
||||
});
|
||||
} else {
|
||||
await MatrixClientPeg.get().unbindThreePid(medium, address);
|
||||
}
|
||||
this.setState({ bound: bind });
|
||||
} catch (err) {
|
||||
console.error(`Unable to ${label} email address ${address} ${err}`);
|
||||
this.setState({
|
||||
verifying: false,
|
||||
continueDisabled: false,
|
||||
addTask: null,
|
||||
});
|
||||
Modal.createTrackedDialog(`Unable to ${label} email address`, '', ErrorDialog, {
|
||||
title: errorTitle,
|
||||
description: ((err && err.message) ? err.message : _t("Operation failed")),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async changeBindingTangledAddBind({ bind, label, errorTitle }) {
|
||||
const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
|
||||
const { medium, address } = this.props.email;
|
||||
|
||||
|
@ -75,14 +113,12 @@ export class EmailAddress extends React.Component {
|
|||
});
|
||||
|
||||
try {
|
||||
// XXX: Unfortunately, at the moment we can't just bind via the HS
|
||||
// in a single operation, at it will error saying the 3PID is in use
|
||||
// even though it's in use by the current user. For the moment, we
|
||||
// work around this by removing the 3PID from the HS and re-adding
|
||||
// it with IS binding enabled.
|
||||
// See https://github.com/matrix-org/matrix-doc/pull/2140/files#r311462052
|
||||
await MatrixClientPeg.get().deleteThreePid(medium, address);
|
||||
await task.addEmailAddress(address, bind);
|
||||
if (bind) {
|
||||
await task.bindEmailAddress(address);
|
||||
} else {
|
||||
await task.addEmailAddress(address);
|
||||
}
|
||||
this.setState({
|
||||
continueDisabled: false,
|
||||
bound: bind,
|
||||
|
|
|
@ -56,6 +56,48 @@ export class PhoneNumber extends React.Component {
|
|||
}
|
||||
|
||||
async changeBinding({ bind, label, errorTitle }) {
|
||||
if (!await MatrixClientPeg.get().doesServerSupportSeparateAddAndBind()) {
|
||||
return this.changeBindingTangledAddBind({ bind, label, errorTitle });
|
||||
}
|
||||
|
||||
const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
|
||||
const { medium, address } = this.props.msisdn;
|
||||
|
||||
try {
|
||||
if (bind) {
|
||||
const task = new AddThreepid();
|
||||
this.setState({
|
||||
verifying: true,
|
||||
continueDisabled: true,
|
||||
addTask: task,
|
||||
});
|
||||
// XXX: Sydent will accept a number without country code if you add
|
||||
// a leading plus sign to a number in E.164 format (which the 3PID
|
||||
// address is), but this goes against the spec.
|
||||
// See https://github.com/matrix-org/matrix-doc/issues/2222
|
||||
await task.bindMsisdn(null, `+${address}`);
|
||||
this.setState({
|
||||
continueDisabled: false,
|
||||
});
|
||||
} else {
|
||||
await MatrixClientPeg.get().unbindThreePid(medium, address);
|
||||
}
|
||||
this.setState({ bound: bind });
|
||||
} catch (err) {
|
||||
console.error(`Unable to ${label} phone number ${address} ${err}`);
|
||||
this.setState({
|
||||
verifying: false,
|
||||
continueDisabled: false,
|
||||
addTask: null,
|
||||
});
|
||||
Modal.createTrackedDialog(`Unable to ${label} phone number`, '', ErrorDialog, {
|
||||
title: errorTitle,
|
||||
description: ((err && err.message) ? err.message : _t("Operation failed")),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async changeBindingTangledAddBind({ bind, label, errorTitle }) {
|
||||
const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
|
||||
const { medium, address } = this.props.msisdn;
|
||||
|
||||
|
@ -67,18 +109,16 @@ export class PhoneNumber extends React.Component {
|
|||
});
|
||||
|
||||
try {
|
||||
// XXX: Unfortunately, at the moment we can't just bind via the HS
|
||||
// in a single operation, at it will error saying the 3PID is in use
|
||||
// even though it's in use by the current user. For the moment, we
|
||||
// work around this by removing the 3PID from the HS and re-adding
|
||||
// it with IS binding enabled.
|
||||
// See https://github.com/matrix-org/matrix-doc/pull/2140/files#r311462052
|
||||
await MatrixClientPeg.get().deleteThreePid(medium, address);
|
||||
// XXX: Sydent will accept a number without country code if you add
|
||||
// a leading plus sign to a number in E.164 format (which the 3PID
|
||||
// address is), but this goes against the spec.
|
||||
// See https://github.com/matrix-org/matrix-doc/issues/2222
|
||||
await task.addMsisdn(null, `+${address}`, bind);
|
||||
if (bind) {
|
||||
await task.bindMsisdn(null, `+${address}`);
|
||||
} else {
|
||||
await task.addMsisdn(null, `+${address}`);
|
||||
}
|
||||
this.setState({
|
||||
continueDisabled: false,
|
||||
bound: bind,
|
||||
|
|
|
@ -51,7 +51,7 @@ export default class GeneralUserSettingsTab extends React.Component {
|
|||
language: languageHandler.getCurrentLanguage(),
|
||||
theme: SettingsStore.getValueAt(SettingLevel.ACCOUNT, "theme"),
|
||||
haveIdServer: Boolean(MatrixClientPeg.get().getIdentityServerUrl()),
|
||||
serverRequiresIdServer: null,
|
||||
serverSupportsSeparateAddAndBind: null,
|
||||
idServerHasUnsignedTerms: false,
|
||||
requiredPolicyInfo: { // This object is passed along to a component for handling
|
||||
hasTerms: false,
|
||||
|
@ -69,8 +69,8 @@ export default class GeneralUserSettingsTab extends React.Component {
|
|||
async componentWillMount() {
|
||||
const cli = MatrixClientPeg.get();
|
||||
|
||||
const serverRequiresIdServer = await cli.doesServerRequireIdServerParam();
|
||||
this.setState({serverRequiresIdServer});
|
||||
const serverSupportsSeparateAddAndBind = await cli.doesServerSupportSeparateAddAndBind();
|
||||
this.setState({serverSupportsSeparateAddAndBind});
|
||||
|
||||
this._getThreepidState();
|
||||
}
|
||||
|
@ -222,7 +222,12 @@ export default class GeneralUserSettingsTab extends React.Component {
|
|||
|
||||
let threepidSection = null;
|
||||
|
||||
if (this.state.haveIdServer || this.state.serverRequiresIdServer === false) {
|
||||
// For older homeservers without separate 3PID add and bind methods (MSC2290),
|
||||
// we use a combo add with bind option API which requires an identity server to
|
||||
// validate 3PID ownership even if we're just adding to the homeserver only.
|
||||
// For newer homeservers with separate 3PID add and bind methods (MSC2290),
|
||||
// there is no such concern, so we can always show the HS account 3PIDs.
|
||||
if (this.state.haveIdServer || this.state.serverSupportsSeparateAddAndBind === true) {
|
||||
threepidSection = <div>
|
||||
<span className="mx_SettingsTab_subheading">{_t("Email addresses")}</span>
|
||||
<EmailAddresses
|
||||
|
@ -236,7 +241,7 @@ export default class GeneralUserSettingsTab extends React.Component {
|
|||
onMsisdnsChange={this._onMsisdnsChange}
|
||||
/>
|
||||
</div>;
|
||||
} else if (this.state.serverRequiresIdServer === null) {
|
||||
} else if (this.state.serverSupportsSeparateAddAndBind === null) {
|
||||
threepidSection = <Spinner />;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue