From 2cd50498c24f4a425e48aab91a1e16dd015abfab Mon Sep 17 00:00:00 2001 From: ansuz Date: Tue, 20 Dec 2016 11:11:40 +0100 Subject: [PATCH] add log(in|out) functions to common --- www/common/cryptpad-common.js | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index 0843fffc1..6cafa47c4 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -96,6 +96,41 @@ define([ }); }; + var userHashKey = common.userHashKey = 'User_hash'; + var fileHashKey = common.fileHashKey = 'FS_hash'; + + var login = common.login = function (hash, remember, cb) { + if (!hash) { throw new Error('expected a user hash'); } + if (!remember) { + sessionStorage.setItem(userHashKey, hash); + } + else { + localStorage.setItem(userHashKey, hash); + } + if (cb) { cb(); } + }; + + var logout = common.logout = function (cb) { + [ + fileHashKey, + userHashKey, + ].forEach(function (k) { + sessionStorage.removeItem(k); + localStorage.removeItem(k); + }); + if (cb) { cb(); } + }; + + var getUserHash = common.getUserHash = function () { + var hash; + [sessionStorage, localStorage].some(function (s) { + var h = s[userHashKey]; + if (h) { return (hash = h); } + }); + + return hash; + }; + Store.ready(function (err, Store) { if (err) { console.error(err);