mirror of https://github.com/vector-im/riot-web
Merge pull request #2970 from matrix-org/dbkr/fix_email_reg_2
Fix registration with emailpull/21833/head
commit
8f2d60a833
|
@ -126,6 +126,15 @@ export function getStoredSessionOwner() {
|
||||||
return hsUrl && userId && accessToken ? userId : null;
|
return hsUrl && userId && accessToken ? userId : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @returns {bool} True if the stored session is for a guest user or false if it is
|
||||||
|
* for a real user. If there is no stored session, return null.
|
||||||
|
*/
|
||||||
|
export function getStoredSessionIsGuest() {
|
||||||
|
const sessVars = _getLocalStorageSessionVars();
|
||||||
|
return sessVars.hsUrl && sessVars.userId && sessVars.accessToken ? sessVars.isGuest : null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Object} queryParams string->string map of the
|
* @param {Object} queryParams string->string map of the
|
||||||
* query-parameters extracted from the real query-string of the starting
|
* query-parameters extracted from the real query-string of the starting
|
||||||
|
@ -235,7 +244,15 @@ function _getLocalStorageSessionVars() {
|
||||||
const userId = localStorage.getItem("mx_user_id");
|
const userId = localStorage.getItem("mx_user_id");
|
||||||
const deviceId = localStorage.getItem("mx_device_id");
|
const deviceId = localStorage.getItem("mx_device_id");
|
||||||
|
|
||||||
return {hsUrl, isUrl, accessToken, userId, deviceId};
|
let isGuest;
|
||||||
|
if (localStorage.getItem("mx_is_guest") !== null) {
|
||||||
|
isGuest = localStorage.getItem("mx_is_guest") === "true";
|
||||||
|
} else {
|
||||||
|
// legacy key name
|
||||||
|
isGuest = localStorage.getItem("matrix-is-guest") === "true";
|
||||||
|
}
|
||||||
|
|
||||||
|
return {hsUrl, isUrl, accessToken, userId, deviceId, isGuest};
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns a promise which resolves to true if a session is found in
|
// returns a promise which resolves to true if a session is found in
|
||||||
|
@ -253,15 +270,7 @@ async function _restoreFromLocalStorage() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const {hsUrl, isUrl, accessToken, userId, deviceId} = _getLocalStorageSessionVars();
|
const {hsUrl, isUrl, accessToken, userId, deviceId, isGuest} = _getLocalStorageSessionVars();
|
||||||
|
|
||||||
let isGuest;
|
|
||||||
if (localStorage.getItem("mx_is_guest") !== null) {
|
|
||||||
isGuest = localStorage.getItem("mx_is_guest") === "true";
|
|
||||||
} else {
|
|
||||||
// legacy key name
|
|
||||||
isGuest = localStorage.getItem("matrix-is-guest") === "true";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (accessToken && userId && hsUrl) {
|
if (accessToken && userId && hsUrl) {
|
||||||
console.log(`Restoring session for ${userId}`);
|
console.log(`Restoring session for ${userId}`);
|
||||||
|
|
|
@ -1733,14 +1733,15 @@ export default React.createClass({
|
||||||
|
|
||||||
// returns a promise which resolves to the new MatrixClient
|
// returns a promise which resolves to the new MatrixClient
|
||||||
onRegistered: function(credentials) {
|
onRegistered: function(credentials) {
|
||||||
// XXX: This should be in state or ideally store(s) because we risk not
|
|
||||||
// rendering the most up-to-date view of state otherwise.
|
|
||||||
this._is_registered = true;
|
|
||||||
if (this.state.register_session_id) {
|
if (this.state.register_session_id) {
|
||||||
// The user came in through an email validation link. To avoid overwriting
|
// The user came in through an email validation link. To avoid overwriting
|
||||||
// their session, check to make sure the session isn't someone else.
|
// 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 sessionOwner = Lifecycle.getStoredSessionOwner();
|
||||||
if (sessionOwner && sessionOwner !== credentials.userId) {
|
const sessionIsGuest = Lifecycle.getStoredSessionIsGuest();
|
||||||
|
if (sessionOwner && !sessionIsGuest && sessionOwner !== credentials.userId) {
|
||||||
console.log(
|
console.log(
|
||||||
`Found a session for ${sessionOwner} but ${credentials.userId} is trying to verify their ` +
|
`Found a session for ${sessionOwner} but ${credentials.userId} is trying to verify their ` +
|
||||||
`email address. Restoring the session for ${sessionOwner} with warning.`,
|
`email address. Restoring the session for ${sessionOwner} with warning.`,
|
||||||
|
@ -1771,6 +1772,9 @@ export default React.createClass({
|
||||||
return MatrixClientPeg.get();
|
return MatrixClientPeg.get();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// XXX: This should be in state or ideally store(s) because we risk not
|
||||||
|
// rendering the most up-to-date view of state otherwise.
|
||||||
|
this._is_registered = true;
|
||||||
return Lifecycle.setLoggedIn(credentials);
|
return Lifecycle.setLoggedIn(credentials);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue