#6274 proxy workerTimeControl #14
|
@ -99,6 +99,7 @@ function getInfo() {
|
|||
}
|
||||
|
||||
function printTimetable(timetable) {
|
||||
console.log(timetable)
|
||||
var listWeekName = weekDays();
|
||||
var dated = new Date();
|
||||
dated.setDate(dated.getDate() - 6);
|
||||
|
@ -234,8 +235,8 @@ function ifIsEmptyImage(value) {
|
|||
}
|
||||
|
||||
function ifIsEmptyText(value) {
|
||||
if (value.trim().length === 0) {
|
||||
return "00:00";
|
||||
if (!value) {
|
||||
return 0;
|
||||
} else {
|
||||
return value;
|
||||
}
|
||||
|
|
12
js/index.js
12
js/index.js
|
@ -1,10 +1,11 @@
|
|||
var pin = "";
|
||||
var datoUsuario = "";
|
||||
var user = "";
|
||||
var pass = "";
|
||||
|
||||
$(document).ready(function () {
|
||||
FastClick.attach(document.body);
|
||||
if(!localStorage.getItem('user')) localStorage.setItem('user', user);
|
||||
renewToken()
|
||||
setEvents();
|
||||
});
|
||||
|
||||
|
@ -14,15 +15,13 @@ function setEvents() {
|
|||
Swal.fire({
|
||||
title: 'Iniciar sesión',
|
||||
html:
|
||||
'<input id="user" class="swal2-input" placeholder="Usuario">' +
|
||||
'<input id="pass" class="swal2-input" type="password" placeholder="Contraseña">',
|
||||
confirmButtonText: 'Login',
|
||||
showCloseButton: true,
|
||||
showCancelButton: false,
|
||||
}).then(async (result) => {
|
||||
if(result.isConfirmed) {
|
||||
const user =$('#user').val();
|
||||
const pass = $('#pass').val();
|
||||
pass = $('#pass').val();
|
||||
signIn(user,pass);
|
||||
}
|
||||
});
|
||||
|
@ -76,6 +75,9 @@ function signIn(user, password) {
|
|||
success: function (data) {
|
||||
localStorage.setItem("token", data.token);
|
||||
localStorage.setItem("ttl", data.ttl);
|
||||
localStorage.setItem("password", password);
|
||||
localStorage.setItem("signInTime", Date.now());
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
renewToken()
|
29
js/main.js
29
js/main.js
|
@ -1,3 +1,5 @@
|
|||
var user = "timeControl";
|
||||
|
||||
function confirmReset() {
|
||||
$(".confirm").removeClass('confirmKO');
|
||||
$(".txtConfirm").empty();
|
||||
|
@ -14,6 +16,33 @@ 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
|
||||
|
||||
}
|
||||
|
||||
$.ajaxPrefilter(function(xhr) {
|
||||
var orgErrorHandler = xhr.error;
|
||||
var token = localStorage.getItem('token')
|
||||
|
|
Loading…
Reference in New Issue