refs #6274 signIn refactor
gitea/worker-time-control/pipeline/head This commit looks good Details

This commit is contained in:
Jorge Penadés 2023-11-29 13:38:53 +01:00
parent 76aaa3fc41
commit 57df79806a
2 changed files with 26 additions and 42 deletions

View File

@ -5,7 +5,6 @@ var pass = "";
$(document).ready(function () { $(document).ready(function () {
FastClick.attach(document.body); FastClick.attach(document.body);
if(!localStorage.getItem('user')) localStorage.setItem('user', user); if(!localStorage.getItem('user')) localStorage.setItem('user', user);
renewToken()
setEvents(); 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()

View File

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