2023-11-30 08:25:32 +00:00
|
|
|
let pin = "";
|
2024-06-04 12:38:09 +00:00
|
|
|
if ("addEventListener" in document) {
|
|
|
|
document.addEventListener("DOMContentLoaded", () => {
|
|
|
|
FastClick.attach(document.body);
|
2021-10-19 08:52:45 +00:00
|
|
|
|
2024-06-04 12:38:09 +00:00
|
|
|
const heartEl = document.querySelector("body > h1 > span");
|
2024-06-14 15:25:56 +00:00
|
|
|
const txtPin = document.querySelector("#txtPin");
|
2024-06-04 12:38:09 +00:00
|
|
|
refreshDeviceLabel();
|
2021-10-19 08:52:45 +00:00
|
|
|
|
2024-06-04 12:38:09 +00:00
|
|
|
heartEl.addEventListener("click", () => {
|
|
|
|
Swal.fire({
|
|
|
|
title: "Iniciar sesión",
|
|
|
|
html: `
|
|
|
|
<input id="device" class="swal2-input" type="text" placeholder="Dispositivo" value="${localStorage.getItem("device") ?? ""}">
|
|
|
|
<input id="user" class="swal2-input" type="text" placeholder="Usuario" value="${localStorage.getItem("user") ?? ""}">
|
|
|
|
<input id="pass" class="swal2-input" type="password" placeholder="Contraseña">`,
|
|
|
|
confirmButtonText: "Login",
|
|
|
|
showCloseButton: true,
|
|
|
|
showCancelButton: false,
|
|
|
|
}).then(async (result) => {
|
|
|
|
if (result.isConfirmed)
|
|
|
|
signIn(document.querySelector("#user").value, document.querySelector("#pass").value, document.querySelector("#device").value);
|
|
|
|
});
|
2023-11-28 13:50:11 +00:00
|
|
|
});
|
2022-12-12 09:21:02 +00:00
|
|
|
|
2024-06-14 15:25:56 +00:00
|
|
|
document.querySelectorAll(".btnnum").forEach((btn) => {
|
|
|
|
btn.addEventListener("click", (e) => {
|
|
|
|
pin += +e.currentTarget.children[0].innerHTML;
|
|
|
|
txtPin.textContent = pin;
|
|
|
|
});
|
2024-06-04 12:38:09 +00:00
|
|
|
});
|
2021-10-19 08:52:45 +00:00
|
|
|
|
2024-06-14 15:25:56 +00:00
|
|
|
document.querySelector(".btnCancel").addEventListener("click", () => {
|
2024-06-04 12:38:09 +00:00
|
|
|
pin = "";
|
2024-06-14 15:25:56 +00:00
|
|
|
txtPin.textContent = "ID USUARIO";
|
2024-06-04 12:38:09 +00:00
|
|
|
});
|
2021-10-19 08:52:45 +00:00
|
|
|
|
2024-06-14 15:25:56 +00:00
|
|
|
document.querySelector(".btnOk").addEventListener("click", () => pin && login());
|
2024-01-30 13:44:44 +00:00
|
|
|
});
|
2021-10-19 08:52:45 +00:00
|
|
|
}
|
|
|
|
|
2024-06-04 12:38:09 +00:00
|
|
|
async function login() {
|
|
|
|
try {
|
2024-06-18 14:39:32 +00:00
|
|
|
const data = await call("WorkerTimeControls/login", {
|
2024-06-04 12:38:09 +00:00
|
|
|
method: "POST",
|
|
|
|
body: { pin },
|
|
|
|
});
|
|
|
|
localStorage.setItem("userData", JSON.stringify(data));
|
|
|
|
window.location = "clockIn.html";
|
|
|
|
} catch (e) {
|
|
|
|
document.querySelector("#txtPin").textContent = "ID USUARIO";
|
|
|
|
pin = "";
|
|
|
|
}
|
2023-12-05 14:56:51 +00:00
|
|
|
}
|
|
|
|
|
2024-06-04 12:38:09 +00:00
|
|
|
async function signIn(user, password, device) {
|
2024-06-18 14:39:32 +00:00
|
|
|
const data = await call("vnUsers/sign-in", {
|
2024-06-04 12:38:09 +00:00
|
|
|
method: "POST",
|
|
|
|
body: { user, password },
|
|
|
|
});
|
|
|
|
localStorage.setItem("token", data.token);
|
|
|
|
localStorage.setItem("ttl", data.ttl);
|
|
|
|
localStorage.setItem("user", user);
|
|
|
|
localStorage.setItem("device", device);
|
|
|
|
localStorage.setItem("created", Date.now());
|
|
|
|
getTokenConfig();
|
|
|
|
refreshDeviceLabel();
|
2024-01-30 13:44:44 +00:00
|
|
|
}
|
|
|
|
|
2024-06-04 12:38:09 +00:00
|
|
|
const refreshDeviceLabel = () => (document.querySelector("#deviceLabel").textContent = localStorage.getItem("device") ?? "");
|