Add time limit for hash

This commit is contained in:
RainLoop Team 2016-05-22 03:09:20 +03:00
parent d3aab2646e
commit 862a02f88a
2 changed files with 64 additions and 21 deletions

View file

@ -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();
}
}

View file

@ -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>
&nbsp;&nbsp;
<span class="i18n" data-i18n="POPUPS_TWO_FACTOR_CFG/BUTTON_ACTIVATE"></span>
</a>