diff --git a/src/components/views/settings/SetIdServer.js b/src/components/views/settings/SetIdServer.js index af38c997a3..ae550725f1 100644 --- a/src/components/views/settings/SetIdServer.js +++ b/src/components/views/settings/SetIdServer.js @@ -130,15 +130,21 @@ export default class SetIdServer extends React.Component { MatrixClientPeg.get().setAccountData("m.identity_server", { base_url: fullUrl, }); - this.setState({idServer: '', busy: false, error: null}); + this.setState({ + busy: false, + error: null, + currentClientIdServer: fullUrl, + idServer: '', + }); }; _checkIdServer = async (e) => { e.preventDefault(); + const { idServer, currentClientIdServer } = this.state; this.setState({busy: true, checking: true, error: null}); - const fullUrl = unabbreviateUrl(this.state.idServer); + const fullUrl = unabbreviateUrl(idServer); let errStr = await checkIdentityServerUrl(fullUrl); if (!errStr) { @@ -150,20 +156,49 @@ export default class SetIdServer extends React.Component { const authClient = new IdentityAuthClient(fullUrl); await authClient.getAccessToken(); + let save = true; + // Double check that the identity server even has terms of service. - const terms = await MatrixClientPeg.get().getTerms(SERVICE_TYPES.IS, fullUrl); - if (!terms || !terms["policies"] || Object.keys(terms["policies"]).length <= 0) { - this._showNoTermsWarning(fullUrl); - return; + let terms; + try { + terms = await MatrixClientPeg.get().getTerms(SERVICE_TYPES.IS, fullUrl); + } catch (e) { + console.error(e); + if (e.cors === "rejected" || e.httpStatus === 404) { + terms = null; + } else { + throw e; + } } - this._saveIdServer(fullUrl); + if (!terms || !terms["policies"] || Object.keys(terms["policies"]).length <= 0) { + const [confirmed] = await this._showNoTermsWarning(fullUrl); + save = confirmed; + } + + // Show a general warning, possibly with details about any bound + // 3PIDs that would be left behind. + if (save && currentClientIdServer && fullUrl !== currentClientIdServer) { + const [confirmed] = await this._showServerChangeWarning({ + title: _t("Change identity server"), + unboundMessage: _t( + "Disconnect from the identity server and " + + "connect to instead?", {}, + { + current: sub => {abbreviateUrl(currentClientIdServer)}, + new: sub => {abbreviateUrl(idServer)}, + }, + ), + button: _t("Continue"), + }); + save = confirmed; + } + + if (save) { + this._saveIdServer(fullUrl); + } } catch (e) { console.error(e); - if (e.cors === "rejected" || e.httpStatus === 404) { - this._showNoTermsWarning(fullUrl); - return; - } errStr = _t("Terms of service not accepted or the identity server is invalid."); } } @@ -172,13 +207,12 @@ export default class SetIdServer extends React.Component { checking: false, error: errStr, currentClientIdServer: MatrixClientPeg.get().getIdentityServerUrl(), - idServer: this.state.idServer, }); }; _showNoTermsWarning(fullUrl) { const QuestionDialog = sdk.getComponent("views.dialogs.QuestionDialog"); - Modal.createTrackedDialog('No Terms Warning', '', QuestionDialog, { + const { finished } = Modal.createTrackedDialog('No Terms Warning', '', QuestionDialog, { title: _t("Identity server has no terms of service"), description: (
@@ -191,54 +225,67 @@ export default class SetIdServer extends React.Component {
), button: _t("Continue"), - onFinished: async (confirmed) => { - if (!confirmed) return; - this._saveIdServer(fullUrl); - }, }); + return finished; } _onDisconnectClicked = async () => { this.setState({disconnectBusy: true}); try { - const threepids = await getThreepidBindStatus(MatrixClientPeg.get()); - - const boundThreepids = threepids.filter(tp => tp.bound); - let message; - if (boundThreepids.length) { - message = _t( - "You are currently sharing email addresses or phone numbers on the identity " + - "server . You will need to reconnect to to stop " + - "sharing them.", {}, - { - idserver: sub => {abbreviateUrl(this.state.currentClientIdServer)}, - // XXX: https://github.com/vector-im/riot-web/issues/9086 - idserver2: sub => {abbreviateUrl(this.state.currentClientIdServer)}, - }, - ); - } else { - message = _t( + const [confirmed] = await this._showServerChangeWarning({ + title: _t("Disconnect identity server"), + unboundMessage: _t( "Disconnect from the identity server ?", {}, {idserver: sub => {abbreviateUrl(this.state.currentClientIdServer)}}, - ); - } - - const QuestionDialog = sdk.getComponent("dialogs.QuestionDialog"); - Modal.createTrackedDialog('Identity Server Disconnect Warning', '', QuestionDialog, { - title: _t("Disconnect Identity Server"), - description: message, + ), button: _t("Disconnect"), - onFinished: (confirmed) => { - if (confirmed) { - this._disconnectIdServer(); - } - }, }); + if (confirmed) { + this._disconnectIdServer(); + } } finally { this.setState({disconnectBusy: false}); } }; + async _showServerChangeWarning({ title, unboundMessage, button }) { + const threepids = await getThreepidBindStatus(MatrixClientPeg.get()); + + const boundThreepids = threepids.filter(tp => tp.bound); + let message; + let danger = false; + if (boundThreepids.length) { + message =
+

{_t( + "You are still sharing your personal data on the identity " + + "server .", {}, + { + idserver: sub => {abbreviateUrl(this.state.currentClientIdServer)}, + b: sub => {sub}, + }, + )}

+

{_t( + "We recommend that you remove your email addresses and phone numbers " + + "from the identity server before disconnecting.", + )}

+
; + danger = true; + button = _t("Disconnect anyway"); + } else { + message = unboundMessage; + } + + const QuestionDialog = sdk.getComponent("dialogs.QuestionDialog"); + const { finished } = Modal.createTrackedDialog('Identity Server Bound Warning', '', QuestionDialog, { + title, + description: message, + button, + cancelButton: _t("Go back"), + danger, + }); + return finished; + } + _disconnectIdServer = () => { // Account data change will update localstorage, client, etc through dispatcher MatrixClientPeg.get().setAccountData("m.identity_server", { diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index 6529e7322c..ed7b180312 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -554,14 +554,19 @@ "Not a valid Identity Server (status code %(code)s)": "Not a valid Identity Server (status code %(code)s)", "Could not connect to Identity Server": "Could not connect to Identity Server", "Checking server": "Checking server", + "Change identity server": "Change identity server", + "Disconnect from the identity server and connect to instead?": "Disconnect from the identity server and connect to instead?", "Terms of service not accepted or the identity server is invalid.": "Terms of service not accepted or the identity server is invalid.", "Identity server has no terms of service": "Identity server has no terms of service", "The identity server you have chosen does not have any terms of service.": "The identity server you have chosen does not have any terms of service.", "Only continue if you trust the owner of the server.": "Only continue if you trust the owner of the server.", - "You are currently sharing email addresses or phone numbers on the identity server . You will need to reconnect to to stop sharing them.": "You are currently sharing email addresses or phone numbers on the identity server . You will need to reconnect to to stop sharing them.", + "Disconnect identity server": "Disconnect identity server", "Disconnect from the identity server ?": "Disconnect from the identity server ?", - "Disconnect Identity Server": "Disconnect Identity Server", "Disconnect": "Disconnect", + "You are still sharing your personal data on the identity server .": "You are still sharing your personal data on the identity server .", + "We recommend that you remove your email addresses and phone numbers from the identity server before disconnecting.": "We recommend that you remove your email addresses and phone numbers from the identity server before disconnecting.", + "Disconnect anyway": "Disconnect anyway", + "Go back": "Go back", "Identity Server (%(server)s)": "Identity Server (%(server)s)", "You are currently using to discover and be discoverable by existing contacts you know. You can change your identity server below.": "You are currently using to discover and be discoverable by existing contacts you know. You can change your identity server below.", "If you don't want to use to discover and be discoverable by existing contacts you know, enter another identity server below.": "If you don't want to use to discover and be discoverable by existing contacts you know, enter another identity server below.", @@ -1290,7 +1295,6 @@ "If you run into any bugs or have feedback you'd like to share, please let us know on GitHub.": "If you run into any bugs or have feedback you'd like to share, please let us know on GitHub.", "To help avoid duplicate issues, please view existing issues first (and add a +1) or create a new issue if you can't find it.": "To help avoid duplicate issues, please view existing issues first (and add a +1) or create a new issue if you can't find it.", "Report bugs & give feedback": "Report bugs & give feedback", - "Go back": "Go back", "Room Settings - %(roomName)s": "Room Settings - %(roomName)s", "Failed to upgrade room": "Failed to upgrade room", "The room upgrade could not be completed": "The room upgrade could not be completed",