mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-08 22:18:28 +03:00
Add time limit for hash
This commit is contained in:
parent
d3aab2646e
commit
862a02f88a
2 changed files with 64 additions and 21 deletions
|
|
@ -1,7 +1,10 @@
|
|||
|
||||
import window from 'window';
|
||||
|
||||
const STORAGE_KEY = '__rlA';
|
||||
const
|
||||
STORAGE_KEY = '__rlA',
|
||||
TIME_KEY = '__rlT'
|
||||
;
|
||||
|
||||
class RainLoopStorage
|
||||
{
|
||||
|
|
@ -12,50 +15,90 @@ class RainLoopStorage
|
|||
{
|
||||
this.s = window.sessionStorage || null;
|
||||
this.t = window.top || window;
|
||||
|
||||
this.init();
|
||||
}
|
||||
|
||||
getHash() {
|
||||
__get(key) {
|
||||
|
||||
let result = null;
|
||||
if (this.s)
|
||||
{
|
||||
result = this.s.getItem(STORAGE_KEY) || null;
|
||||
result = this.s.getItem(key) || null;
|
||||
}
|
||||
else if (this.t && JSON)
|
||||
{
|
||||
const data = this.t.name && '{' === this.t.name.toString().substr(0, 1) ? JSON.parse(this.t.name.toString()) : null;
|
||||
result = data ? (data[STORAGE_KEY] || null) : null;
|
||||
result = data ? (data[key] || null) : null;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
setHash() {
|
||||
const
|
||||
key = 'AuthAccountHash',
|
||||
appData = window.__rlah_data()
|
||||
;
|
||||
__set(key, value) {
|
||||
if (this.s)
|
||||
{
|
||||
this.s.setItem(STORAGE_KEY, appData && appData[key] ? appData[key] : '');
|
||||
this.s.setItem(key, value);
|
||||
}
|
||||
else if (this.t && JSON)
|
||||
{
|
||||
let data = {};
|
||||
data[STORAGE_KEY] = appData && appData[key] ? appData[key] : '';
|
||||
let data = this.t.name && '{' === this.t.name.toString().substr(0, 1) ? JSON.parse(this.t.name.toString()) : null;
|
||||
data = data || {};
|
||||
data[key] = value;
|
||||
|
||||
this.t.name = JSON.stringify(data);
|
||||
}
|
||||
}
|
||||
|
||||
timestamp() {
|
||||
return window.Math.round((new Date()).getTime() / 1000);
|
||||
}
|
||||
|
||||
init() {
|
||||
|
||||
const
|
||||
six = 1000 * 60 * 6, // 6m
|
||||
now = this.timestamp()
|
||||
;
|
||||
|
||||
if (now > this.getTimestamp() + six * 10)
|
||||
{
|
||||
this.clearHash();
|
||||
}
|
||||
|
||||
window.setInterval(() => {
|
||||
this.setTimestamp();
|
||||
}, six);
|
||||
}
|
||||
|
||||
getHash() {
|
||||
return this.__get(STORAGE_KEY);
|
||||
}
|
||||
|
||||
setHash() {
|
||||
|
||||
const
|
||||
key = 'AuthAccountHash',
|
||||
appData = window.__rlah_data()
|
||||
;
|
||||
|
||||
this.__set(STORAGE_KEY, appData && appData[key] ? appData[key] : '');
|
||||
this.setTimestamp();
|
||||
}
|
||||
|
||||
|
||||
setTimestamp() {
|
||||
this.__set(TIME_KEY, this.timestamp());
|
||||
}
|
||||
|
||||
getTimestamp() {
|
||||
let time = this.__get(TIME_KEY, 0);
|
||||
return time ? (window.parseInt(time, 10) | 0) : 0;
|
||||
}
|
||||
|
||||
clearHash() {
|
||||
if (this.s)
|
||||
{
|
||||
this.s.setItem(STORAGE_KEY, '');
|
||||
}
|
||||
else if (this.t)
|
||||
{
|
||||
this.t.name = '';
|
||||
}
|
||||
this.__set(STORAGE_KEY, '');
|
||||
this.setTimestamp();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@
|
|||
<span class="i18n" data-i18n="POPUPS_TWO_FACTOR_CFG/BUTTON_CLEAR"></span>
|
||||
</a>
|
||||
<a class="btn" data-bind="click: createTwoFactor, visible: !twoFactorStatus()">
|
||||
<i class="icon-ok" data-bind="css: {'icon-ok': !processing(), 'icon-spinner animated': processing()}" ></i>
|
||||
<i class="icon-play" data-bind="css: {'icon-play': !processing(), 'icon-spinner animated': processing()}" ></i>
|
||||
|
||||
<span class="i18n" data-i18n="POPUPS_TWO_FACTOR_CFG/BUTTON_ACTIVATE"></span>
|
||||
</a>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue