#6274 proxy workerTimeControl #14

Merged
jorgep merged 12 commits from 6274-loginWorkerTimeControl into test 2024-01-04 13:26:28 +00:00
2 changed files with 26 additions and 42 deletions
Showing only changes of commit 57df79806a - Show all commits

View File

@ -5,7 +5,6 @@ var pass = "";
$(document).ready(function () {
FastClick.attach(document.body);
if(!localStorage.getItem('user')) localStorage.setItem('user', user);
renewToken()
setEvents();
});
@ -65,19 +64,4 @@ function login() {
pin = "";
}
});
}
function signIn(user, password) {
$.post({
urlPath: 'vnUsers/sign-in',
jsonData: {user, password},
processData: false,
success: function (data) {
localStorage.setItem("token", data.token);
localStorage.setItem("ttl", data.ttl);
localStorage.setItem("password", password);
localStorage.setItem("signInTime", Date.now());
},
})
}
renewToken()
}

View File

@ -16,31 +16,18 @@ function printError(msg){
}, 2300);
}
function renewToken() {
setInterval(function() {
const ttl = localStorage.getItem('ttl');
const password = localStorage.getItem('password');
if(ttl && password) {
const now = Date.now();
const signInTime = localStorage.getItem('signInTime');
const countdown = now - signInTime;
if(countdown > ttl) {
$.post({
urlPath: 'vnUsers/sign-in',
jsonData: {user, password},
processData: false,
success: function (data) {
localStorage.setItem("token", data.token);
localStorage.setItem("ttl", data.ttl);
localStorage.setItem("signInTime", Date.now());
},
})
}
}
},3600000)// 1 hour
function signIn(user, password) {
$.post({
urlPath: 'vnUsers/sign-in',
jsonData: {user, password},
processData: false,
success: function (data) {
localStorage.setItem("token", data.token);
localStorage.setItem("ttl", data.ttl);
localStorage.setItem("password", password);
localStorage.setItem("signInTime", Date.now());
},
})
}
$.ajaxPrefilter(function(xhr) {
@ -98,3 +85,16 @@ $.ajaxPrefilter(function(xhr) {
}
});
});
setInterval(function() {
const ttl = localStorage.getItem('ttl');
const password = localStorage.getItem('password');
if(ttl && password) {
const now = Date.now();
const signInTime = localStorage.getItem('signInTime');
const countdown = now - signInTime;
if(countdown < ttl) signIn(user, password)
}
},3600000)// 1 hour