81 lines
2.2 KiB
JavaScript
81 lines
2.2 KiB
JavaScript
var pin = "";
|
|
var datoUsuario = "";
|
|
var user = "";
|
|
var pass = "";
|
|
|
|
$(document).ready(function () {
|
|
FastClick.attach(document.body);
|
|
setEvents();
|
|
});
|
|
|
|
function setEvents() {
|
|
const heartEl = document.querySelector('body > h1 > span');
|
|
heartEl.addEventListener('click', function() {
|
|
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();
|
|
signIn(user,pass);
|
|
}
|
|
});
|
|
|
|
let token;
|
|
if (token === null) return
|
|
localStorage.setItem('token', token);
|
|
});
|
|
|
|
$(".btnnum").on("click", function () {
|
|
pin += parseInt($(this).children().html());
|
|
$("#txtPin").text(pin);
|
|
});
|
|
|
|
$(".btnCancel").on("click", function () {
|
|
pin = "";
|
|
$("#txtPin").text("ID USUARIO");
|
|
});
|
|
|
|
$(".btnOk").on("click", login);
|
|
|
|
$(".btnconfirmar").on("click", function () {
|
|
localStorage.setItem("userData", JSON.stringify(datoUsuario));
|
|
setTimeout(function () {
|
|
window.location = "clockIn.html";
|
|
}, 200);
|
|
});
|
|
}
|
|
|
|
function login() {
|
|
$.post({
|
|
urlPath: 'WorkerTimeControls/login',
|
|
jsonData: {pin},
|
|
processData: false,
|
|
success: function (data) {
|
|
localStorage.setItem("userData", JSON.stringify(data));
|
|
window.location = "clockIn.html";
|
|
},
|
|
error: function() {
|
|
$("#txtPin").text("ID USUARIO");
|
|
pin = "";
|
|
}
|
|
});
|
|
}
|
|
|
|
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);
|
|
},
|
|
})
|
|
} |