57 lines
1.7 KiB
JavaScript
57 lines
1.7 KiB
JavaScript
function idleLogout() {
|
|
var t;
|
|
var sleep = false;
|
|
window.onload = resetTimer;
|
|
window.onmousemove = resetTimer;
|
|
window.onmousedown = resetTimer; // catches touchscreen presses as well
|
|
window.ontouchstart = resetTimer; // catches touchscreen swipes as well
|
|
window.ontouchmove = resetTimer; // required by some devices
|
|
window.onclick = resetTimer; // catches touchpad clicks as well
|
|
window.onkeydown = resetTimer;
|
|
window.addEventListener('scroll', resetTimer, true); // improved; see comments
|
|
|
|
function yourFunction() {
|
|
clearTimeout(t);
|
|
sleep = true;
|
|
modal.sessionLeft('Вашата сесия ще изтече след ', 60, null, () => {
|
|
sleep = false;
|
|
resetTimer();
|
|
}, () => {
|
|
let key = document.getElementById('user_type_key');
|
|
window.location.href = `/${key.value}/logout/`
|
|
});
|
|
}
|
|
|
|
function resetTimer() {
|
|
if(!sleep) {
|
|
clearTimeout(t);
|
|
t = setTimeout(yourFunction, 9*60*1000); // time is in milliseconds
|
|
}
|
|
}
|
|
}
|
|
|
|
//idleLogout();
|
|
|
|
function checkActivity() {
|
|
const xhr = new XMLHttpRequest();
|
|
xhr.open('get', '/remote/check-activity/')
|
|
xhr.responseType = 'json';
|
|
xhr.onload = () => {
|
|
if (xhr.response && xhr.response.status) {
|
|
if (xhr.response.status === 'inactive') {
|
|
window.location.href = xhr.response.redirect;
|
|
//console.log(xhr.response)
|
|
} else {
|
|
console.log(xhr.response)
|
|
setTimeout(function () {
|
|
checkActivity()
|
|
}, 200000)
|
|
}
|
|
}
|
|
}
|
|
xhr.send();
|
|
|
|
}
|
|
|
|
checkActivity();
|