diff --git a/js/clockIn.js b/js/clockIn.js
index 748f61f..50bb19d 100644
--- a/js/clockIn.js
+++ b/js/clockIn.js
@@ -45,7 +45,8 @@ function setView() {
function fichar(direction) {
const data = {
workerFk: userData['userFk'],
- direction
+ direction,
+ device: localStorage.getItem("device")
}
$.post({
diff --git a/js/index.js b/js/index.js
index b6dbdc8..929e86d 100644
--- a/js/index.js
+++ b/js/index.js
@@ -7,12 +7,14 @@ $(document).ready(function () {
function setEvents() {
const heartEl = document.querySelector('body > h1 > span');
-
+ refreshDeviceLabel()
+
heartEl.addEventListener('click', function() {
Swal.fire({
title: 'Iniciar sesión',
html:
- `
+ `
+
`,
confirmButtonText: 'Login',
showCloseButton: true,
@@ -21,7 +23,8 @@ function setEvents() {
if(result.isConfirmed) {
const user = $('#user').val();
const pass = $('#pass').val();
- signIn(user,pass);
+ const device = $('#device').val();
+ signIn(user, pass, device);
}
});
});
@@ -36,8 +39,11 @@ function setEvents() {
$("#txtPin").text("ID USUARIO");
});
- $(".btnOk").on("click", login);
-
+ $(".btnOk").on("click", function () {
+ if (pin) {
+ login();
+ };
+ });
}
function login() {
@@ -56,7 +62,7 @@ function login() {
});
}
-function signIn(user, password) {
+function signIn(user, password, device) {
$.post({
urlPath: 'vnUsers/sign-in',
jsonData: {user, password},
@@ -65,9 +71,14 @@ function signIn(user, password) {
localStorage.setItem("token", data.token);
localStorage.setItem("ttl", data.ttl);
localStorage.setItem("user", user);
- localStorage.setItem("password", password);
+ localStorage.setItem("device", device);
localStorage.setItem("created", Date.now());
getTokenConfig();
+ refreshDeviceLabel();
},
})
+}
+
+function refreshDeviceLabel() {
+ $("#deviceLabel").text(localStorage.getItem('device') ?? '')
}
\ No newline at end of file
diff --git a/js/main.js b/js/main.js
index 2919bc6..1d4f89b 100644
--- a/js/main.js
+++ b/js/main.js
@@ -45,7 +45,7 @@ function getTokenConfig() {
}
function checkValidity() {
- const created = localStorage.getItem('created');
+ const created = +localStorage.getItem('created');
const ttl = localStorage.getItem('ttl');
if (isCheckingToken || !created) return;
@@ -66,11 +66,11 @@ $.ajaxPrefilter(function(xhr) {
const token = localStorage.getItem('token')
Object.assign(xhr, {
- url: `api/${xhr.urlPath}`,
+ url: `/api/${xhr.urlPath}`,
headers: {
Authorization : token
},
- timeout: 1000,
+ timeout: 2000,
contentType: 'application/json; charset=utf-8',
dataType: 'json',
processData: false,
@@ -97,13 +97,20 @@ $.ajaxPrefilter(function(xhr) {
mensaje = 'Ajax request aborted';
break;
case 'error':
+ if (xhr?.responseJSON?.error?.name == 'UserError') {
+ mensaje = xhr.responseJSON.error.message;
+ break;
+ }
switch (xhr.status){
case 0:
mensaje = 'Not connect: Verify Network';
break;
+ case 504:
+ mensaje = 'No se ha podido conectar con Salix, consulta con informática';
+ break;
case 555:
mensaje = JSON.parse(xhr.statusText).Message;
- break;
+ break;
default:
if (xhr.status >= 400 && xhr.status < 500)
mensaje = xhr.statusText;
diff --git a/proxy.js b/proxy.js
index 30f546f..e6bbf25 100644
--- a/proxy.js
+++ b/proxy.js
@@ -3,16 +3,23 @@ const dotenv = require('dotenv');
const { createProxyMiddleware } = require('http-proxy-middleware');
const app = express();
+const env = process.env;
dotenv.config();
+
+if (!env.TARGET || !env.PORT) {
+ console.error(`[ERROR] The '.env' file is not configured`);
+ process.exit();
+}
+
const apiProxy = createProxyMiddleware('/api', {
- target: process.env.TARGET,
- changeOrigin: true,
+ target: env.TARGET,
+ changeOrigin: true,
});
app.use('/api', apiProxy);
app.use('/', express.static(__dirname));
-const port = process.env.PORT;
+const port = env.PORT;
app.listen(port, () => {
- console.log(`Server running on port: ${port}`);
+ console.log(`[SERVER] Running on port: ${port}`);
});