diff --git a/src/components/structures/MatrixChat.js b/src/components/structures/MatrixChat.js index fb35ab548b..d0f5a7e005 100644 --- a/src/components/structures/MatrixChat.js +++ b/src/components/structures/MatrixChat.js @@ -1709,45 +1709,6 @@ export default React.createClass({ // returns a promise which resolves to the new MatrixClient onRegistered: function(credentials) { - if (this.state.register_session_id) { - // The user came in through an email validation link. To avoid overwriting - // their session, check to make sure the session isn't someone else, and - // isn't a guest user since we'll usually have set a guest user session before - // starting the registration process. This isn't perfect since it's possible - // the user had a separate guest session they didn't actually mean to replace. - const sessionOwner = Lifecycle.getStoredSessionOwner(); - const sessionIsGuest = Lifecycle.getStoredSessionIsGuest(); - if (sessionOwner && !sessionIsGuest && sessionOwner !== credentials.userId) { - console.log( - `Found a session for ${sessionOwner} but ${credentials.userId} is trying to verify their ` + - `email address. Restoring the session for ${sessionOwner} with warning.`, - ); - this._loadSession(); - - const QuestionDialog = sdk.getComponent("dialogs.QuestionDialog"); - // N.B. first param is passed to piwik and so doesn't want i18n - Modal.createTrackedDialog('Existing session on register', '', - QuestionDialog, { - title: _t('You are logged in to another account'), - description: _t( - "Thank you for verifying your email! The account you're logged into here " + - "(%(sessionUserId)s) appears to be different from the account you've verified an " + - "email for (%(verifiedUserId)s). If you would like to log in to %(verifiedUserId2)s, " + - "please log out first.", { - sessionUserId: sessionOwner, - verifiedUserId: credentials.userId, - - // TODO: Fix translations to support reusing variables. - // https://github.com/vector-im/riot-web/issues/9086 - verifiedUserId2: credentials.userId, - }, - ), - hasCancelButton: false, - }); - - return MatrixClientPeg.get(); - } - } return Lifecycle.setLoggedIn(credentials); }, diff --git a/src/components/structures/auth/Registration.js b/src/components/structures/auth/Registration.js index 662444379f..e825dd7034 100644 --- a/src/components/structures/auth/Registration.js +++ b/src/components/structures/auth/Registration.js @@ -97,6 +97,13 @@ module.exports = React.createClass({ // Our matrix client - part of state because we can't render the UI auth // component without it. matrixClient: null, + + // The user ID we've just registered + registeredUsername: null, + + // if a different user ID to the one we just registered is logged in, + // this is the user ID that's logged in. + differentLoggedInUserId: null, }; }, @@ -297,7 +304,25 @@ module.exports = React.createClass({ const newState = { doingUIAuth: false, + registeredUsername: response.user_id, }; + + // The user came in through an email validation link. To avoid overwriting + // their session, check to make sure the session isn't someone else, and + // isn't a guest user since we'll usually have set a guest user session before + // starting the registration process. This isn't perfect since it's possible + // the user had a separate guest session they didn't actually mean to replace. + const sessionOwner = Lifecycle.getStoredSessionOwner(); + const sessionIsGuest = Lifecycle.getStoredSessionIsGuest(); + if (sessionOwner && !sessionIsGuest && sessionOwner !== response.userId) { + console.log( + `Found a session for ${sessionOwner} but ${response.userId} has just registered.`, + ); + newState.differentLoggedInUserId = sessionOwner; + } else { + newState.differentLoggedInUserId = null; + } + if (response.access_token) { const cli = await this.props.onLoggedIn({ userId: response.user_id, @@ -538,6 +563,7 @@ module.exports = React.createClass({ const AuthHeader = sdk.getComponent('auth.AuthHeader'); const AuthBody = sdk.getComponent("auth.AuthBody"); const AuthPage = sdk.getComponent('auth.AuthPage'); + const AccessibleButton = sdk.getComponent('elements.AccessibleButton'); let errorText; const err = this.state.errorText; @@ -574,28 +600,41 @@ module.exports = React.createClass({ let body; if (this.state.completedNoSignin) { let regDoneText; - if (this.state.formVals.password) { + if (this.state.differentLoggedInUserId) { + regDoneText =
+

{_t( + "Your new account (%(newAccountId)s) is registered, but you're already " + + "logged into a different account (%(loggedInUserId)s).", { + newAccountId: this.state.registeredUsername, + loggedInUserId: this.state.differentLoggedInUserId, + }, + )}

+

+ {_t("Continue with previous account")} +

+
; + } else if (this.state.formVals.password) { // We're the client that started the registration - regDoneText = _t( + regDoneText =

{_t( "Log in to your new account.", {}, { a: (sub) => {sub}, }, - ); + )}

; } else { // We're not the original client: the user probably got to us by clicking the // email validation link. We can't offer a 'go straight to your account' link // as we don't have the original creds. - regDoneText = _t( + regDoneText =

{_t( "You can now close this window or log in to your new account.", {}, { a: (sub) => {sub}, }, - ); + )}

; } body =

{_t("Registration Successful")}

-

{ regDoneText }

+ { regDoneText }
; } else { body =
diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index 5b365a4bf5..c17b5d9fec 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -1257,8 +1257,8 @@ "Unknown devices": "Unknown devices", "Upload files (%(current)s of %(total)s)": "Upload files (%(current)s of %(total)s)", "Upload files": "Upload files", - "Upload": "Upload", "Upload all": "Upload all", + "Upload": "Upload", "This file is too large to upload. The file size limit is %(limit)s but this file is %(sizeOfThisFile)s.": "This file is too large to upload. The file size limit is %(limit)s but this file is %(sizeOfThisFile)s.", "These files are too large to upload. The file size limit is %(limit)s.": "These files are too large to upload. The file size limit is %(limit)s.", "Some files are too large to be uploaded. The file size limit is %(limit)s.": "Some files are too large to be uploaded. The file size limit is %(limit)s.", @@ -1459,8 +1459,6 @@ "Review terms and conditions": "Review terms and conditions", "Old cryptography data detected": "Old cryptography data detected", "Data from an older version of Riot has been detected. This will have caused end-to-end cryptography to malfunction in the older version. End-to-end encrypted messages exchanged recently whilst using the older version may not be decryptable in this version. This may also cause messages exchanged with this version to fail. If you experience problems, log out and back in again. To retain message history, export and re-import your keys.": "Data from an older version of Riot has been detected. This will have caused end-to-end cryptography to malfunction in the older version. End-to-end encrypted messages exchanged recently whilst using the older version may not be decryptable in this version. This may also cause messages exchanged with this version to fail. If you experience problems, log out and back in again. To retain message history, export and re-import your keys.", - "You are logged in to another account": "You are logged in to another account", - "Thank you for verifying your email! The account you're logged into here (%(sessionUserId)s) appears to be different from the account you've verified an email for (%(verifiedUserId)s). If you would like to log in to %(verifiedUserId2)s, please log out first.": "Thank you for verifying your email! The account you're logged into here (%(sessionUserId)s) appears to be different from the account you've verified an email for (%(verifiedUserId)s). If you would like to log in to %(verifiedUserId2)s, please log out first.", "Logout": "Logout", "Your Communities": "Your Communities", "Did you know: you can use communities to filter your Riot.im experience!": "Did you know: you can use communities to filter your Riot.im experience!", @@ -1567,6 +1565,9 @@ "Registration has been disabled on this homeserver.": "Registration has been disabled on this homeserver.", "Unable to query for supported registration methods.": "Unable to query for supported registration methods.", "This server does not support authentication with a phone number.": "This server does not support authentication with a phone number.", + "Your new account (%(newAccountId)s) is registered, but you're already logged into a different account (%(loggedInUserId)s).": "Your new account (%(newAccountId)s) is registered, but you're already logged into a different account (%(loggedInUserId)s).", + "Continue with previous account": "Continue with previous account", + "Sign out of previous account": "Sign out of previous account", "Log in to your new account.": "Log in to your new account.", "You can now close this window or log in to your new account.": "You can now close this window or log in to your new account.", "Registration Successful": "Registration Successful",