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