From 76aaa3fc41dbc8150fbc4b9a2100cdeb917e3f73 Mon Sep 17 00:00:00 2001 From: jorgep Date: Wed, 29 Nov 2023 09:26:04 +0100 Subject: [PATCH] refs #6274 renewToken created --- js/clockIn.js | 5 +++-- js/index.js | 12 +++++++----- js/main.js | 29 +++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 7 deletions(-) diff --git a/js/clockIn.js b/js/clockIn.js index 532dd11..e933267 100644 --- a/js/clockIn.js +++ b/js/clockIn.js @@ -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; } diff --git a/js/index.js b/js/index.js index fa902b6..b1e7a0c 100644 --- a/js/index.js +++ b/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: - '' + '', 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()); }, }) -} \ No newline at end of file +} +renewToken() \ No newline at end of file diff --git a/js/main.js b/js/main.js index e2aae1f..e8f21b4 100644 --- a/js/main.js +++ b/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')