This commit is contained in:
parent
76aaa3fc41
commit
57df79806a
16
js/index.js
16
js/index.js
|
@ -5,7 +5,6 @@ var pass = "";
|
|||
$(document).ready(function () {
|
||||
FastClick.attach(document.body);
|
||||
if(!localStorage.getItem('user')) localStorage.setItem('user', user);
|
||||
renewToken()
|
||||
setEvents();
|
||||
});
|
||||
|
||||
|
@ -66,18 +65,3 @@ function login() {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
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()
|
30
js/main.js
30
js/main.js
|
@ -16,17 +16,7 @@ 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) {
|
||||
function signIn(user, password) {
|
||||
$.post({
|
||||
urlPath: 'vnUsers/sign-in',
|
||||
jsonData: {user, password},
|
||||
|
@ -34,14 +24,11 @@ function renewToken() {
|
|||
success: function (data) {
|
||||
localStorage.setItem("token", data.token);
|
||||
localStorage.setItem("ttl", data.ttl);
|
||||
localStorage.setItem("password", password);
|
||||
localStorage.setItem("signInTime", Date.now());
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
},3600000)// 1 hour
|
||||
|
||||
}
|
||||
|
||||
$.ajaxPrefilter(function(xhr) {
|
||||
var orgErrorHandler = xhr.error;
|
||||
|
@ -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
|
Loading…
Reference in New Issue