PLT-1016 force logout on other browsers

Этот коммит содержится в:
=Corey Hulen
2015-11-05 11:54:40 -08:00
родитель 6418b78f1c
Коммит 5dbefdecfe
3 изменённых файлов: 38 добавлений и 13 удалений

Просмотреть файл

@@ -24,6 +24,8 @@ class BrowserStoreClass {
this.setLastServerVersion = this.setLastServerVersion.bind(this);
this.clear = this.clear.bind(this);
this.clearAll = this.clearAll.bind(this);
this.checkedLocalStorageSupported = '';
this.signalLogout = this.signalLogout.bind(this);
var currentVersion = sessionStorage.getItem('storage_version');
if (currentVersion !== global.window.mm_config.Version) {
@@ -105,6 +107,13 @@ class BrowserStoreClass {
sessionStorage.setItem('last_server_version', version);
}
signalLogout() {
if (this.isLocalStorageSupported()) {
localStorage.setItem('__logout__', 'yes');
localStorage.removeItem('__logout__');
}
}
/**
* Preforms the given action on each item that has the given prefix
* Signature for action is action(key, value)
@@ -147,20 +156,26 @@ class BrowserStoreClass {
}
isLocalStorageSupported() {
try {
sessionStorage.setItem('testSession', '1');
sessionStorage.removeItem('testSession');
localStorage.setItem('testLocal', '1');
if (localStorage.getItem('testLocal') !== '1') {
return false;
}
localStorage.removeItem('testLocal', '1');
return true;
} catch (e) {
return false;
if (this.checkedLocalStorageSupported !== '') {
return this.checkedLocalStorageSupported;
}
try {
sessionStorage.setItem('__testSession__', '1');
sessionStorage.removeItem('__testSession__');
localStorage.setItem('__testLocal__', '1');
if (localStorage.getItem('__testLocal__') !== '1') {
this.checkedLocalStorageSupported = false;
}
localStorage.removeItem('__testLocal__', '1');
this.checkedLocalStorageSupported = true;
} catch (e) {
this.checkedLocalStorageSupported = false;
}
return this.checkedLocalStorageSupported;
}
}

Просмотреть файл

@@ -231,6 +231,7 @@ export function resetPassword(data, success, error) {
export function logout() {
track('api', 'api_users_logout');
var currentTeamUrl = TeamStore.getCurrentTeamUrl();
BrowserStore.signalLogout();
BrowserStore.clear();
ErrorStore.storeLastError(null);
window.location.href = currentTeamUrl + '/logout';

Просмотреть файл

@@ -52,6 +52,15 @@
headers: { 'X-MM-TokenIndex': mm_session_token_index }
});
}
$(function () {
$(window).bind('storage', function (e) {
if (e.originalEvent.key === '__logout__') {
console.log('detected logout from a different tab');
window.location.href = '/' + window.mm_team.name;
}
});
});
</script>
<script>