unceremoniously kick web clients when you 'log out everywhere'

This commit is contained in:
ansuz 2017-05-05 18:25:55 +02:00
parent 1547063b7f
commit 42dcfb9661
2 changed files with 11 additions and 3 deletions

View File

@ -153,7 +153,7 @@ define([
f(void 0, store); f(void 0, store);
} }
var requestLogin = function (Cryptpad) { var requestLogin = function () {
// log out so that you don't go into an endless loop... // log out so that you don't go into an endless loop...
Cryptpad.logout(); Cryptpad.logout();
@ -162,11 +162,11 @@ define([
window.location.href = '/login/'; window.location.href = '/login/';
}; };
var tokenKey = 'loginToken';
if (Cryptpad.isLoggedIn()) { if (Cryptpad.isLoggedIn()) {
/* This isn't truly secure, since anyone who can read the user's object can /* This isn't truly secure, since anyone who can read the user's object can
set their local loginToken to match that in the object. However, it exposes set their local loginToken to match that in the object. However, it exposes
a UI that will work most of the time. */ a UI that will work most of the time. */
var tokenKey = 'loginToken';
// every user object should have a persistent, random number // every user object should have a persistent, random number
if (typeof(proxy.loginToken) !== 'number') { if (typeof(proxy.loginToken) !== 'number') {
@ -203,6 +203,13 @@ define([
if (typeof(n) !== "string") { return; } if (typeof(n) !== "string") { return; }
Cryptpad.changeDisplayName(n); Cryptpad.changeDisplayName(n);
}); });
proxy.on('change', [tokenKey], function () {
console.log('wut');
var localToken = tryParsing(localStorage.getItem(tokenKey));
if (localToken !== proxy[tokenKey]) {
return void requestLogin();
}
});
}; };
var initialized = false; var initialized = false;

View File

@ -273,8 +273,9 @@ define([
$spinner.show(); $spinner.show();
$ok.hide(); $ok.hide();
var token = proxy.loginToken = Math.floor(Math.random()*Number.MAX_SAFE_INTEGER); var token = Math.floor(Math.random()*Number.MAX_SAFE_INTEGER);
localStorage.setItem('loginToken', token); localStorage.setItem('loginToken', token);
proxy.loginToken = token;
Cryptpad.whenRealtimeSyncs(realtime, function () { Cryptpad.whenRealtimeSyncs(realtime, function () {
$spinner.hide(); $spinner.hide();