34 lines
1.0 KiB
JavaScript
34 lines
1.0 KiB
JavaScript
const formulario = document.getElementById("login-formulario");
|
|
const notificacion = document.getElementById("mensaje-error");
|
|
|
|
formulario.addEventListener("submit", async (event) => {
|
|
|
|
event.preventDefault();
|
|
|
|
const numeroPersonal = document.getElementById("numero-personal").value;
|
|
const contrasena = document.getElementById("contrasena").value;
|
|
const data = new FormData();
|
|
|
|
data.append("numero-personal", numeroPersonal);
|
|
data.append("contrasena", contrasena);
|
|
|
|
try {
|
|
const respuestaPeticion = await fetch("controllers/login.php", {
|
|
method: "POST",
|
|
body: data,
|
|
});
|
|
|
|
const verificarCredenciales = await respuestaPeticion.json();
|
|
|
|
if (verificarCredenciales.loginExitoso) {
|
|
window.location.href = 'inicio.html';
|
|
} else {
|
|
notificacion.textContent = "Usuario y/o contraseña incorrectos";
|
|
notificacion.style.display = "block";
|
|
}
|
|
} catch (error) {
|
|
notificacion.textContent =
|
|
"Lo sentimos, el servicio no está disponible por el momento";
|
|
}
|
|
});
|