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, + }, + )}
+