2018-03-26 09:16:57 +08:00
|
|
|
import utils from "./utils.js";
|
|
|
|
import server from "./server.js";
|
|
|
|
|
|
|
|
let lastProtectedSessionOperationDate = null;
|
|
|
|
let protectedSessionTimeout = null;
|
|
|
|
let protectedSessionId = null;
|
|
|
|
|
|
|
|
$(document).ready(() => {
|
2018-04-02 08:33:10 +08:00
|
|
|
server.get('options').then(options => protectedSessionTimeout = options.protected_session_timeout);
|
2018-03-26 09:16:57 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
setInterval(() => {
|
|
|
|
if (lastProtectedSessionOperationDate !== null && new Date().getTime() - lastProtectedSessionOperationDate.getTime() > protectedSessionTimeout * 1000) {
|
|
|
|
resetProtectedSession();
|
|
|
|
}
|
|
|
|
}, 5000);
|
|
|
|
|
|
|
|
function setProtectedSessionTimeout(encSessTimeout) {
|
|
|
|
protectedSessionTimeout = encSessTimeout;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getProtectedSessionId() {
|
|
|
|
return protectedSessionId;
|
|
|
|
}
|
|
|
|
|
|
|
|
function setProtectedSessionId(id) {
|
|
|
|
protectedSessionId = id;
|
|
|
|
}
|
|
|
|
|
|
|
|
function resetProtectedSession() {
|
|
|
|
protectedSessionId = null;
|
|
|
|
|
|
|
|
// most secure solution - guarantees nothing remained in memory
|
|
|
|
// since this expires because user doesn't use the app, it shouldn't be disruptive
|
|
|
|
utils.reloadApp();
|
|
|
|
}
|
|
|
|
|
|
|
|
function isProtectedSessionAvailable() {
|
|
|
|
return protectedSessionId !== null;
|
|
|
|
}
|
|
|
|
|
|
|
|
function touchProtectedSession() {
|
|
|
|
if (isProtectedSessionAvailable()) {
|
|
|
|
lastProtectedSessionOperationDate = new Date();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default {
|
|
|
|
getProtectedSessionId,
|
|
|
|
setProtectedSessionId,
|
|
|
|
resetProtectedSession,
|
|
|
|
isProtectedSessionAvailable,
|
|
|
|
setProtectedSessionTimeout,
|
|
|
|
touchProtectedSession
|
|
|
|
};
|