From 206aea72ed1221d8984ae6ca548821253a91c671 Mon Sep 17 00:00:00 2001 From: Felipe Date: Thu, 6 Feb 2025 17:50:26 -0500 Subject: [PATCH] funcionamiento --- resources/views/login.html | 59 ++++++++++++++++++++++++++------------ 1 file changed, 41 insertions(+), 18 deletions(-) diff --git a/resources/views/login.html b/resources/views/login.html index 5a4618b..64efa0e 100644 --- a/resources/views/login.html +++ b/resources/views/login.html @@ -12,19 +12,19 @@

Bienvenido

- + - +
- +
@@ -36,24 +36,47 @@ document.getElementById('loginForm').addEventListener('submit', async function (e) { e.preventDefault(); - const email = document.getElementById('email').value; + const username = document.getElementById('username').value; const password = document.getElementById('password').value; - const response = await fetch('/api/login', { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ email, password }), - }); + try { + const response = await fetch('/do/login', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + nombre_usuario: username, + password: password, + }), + }); - const result = await response.json(); + const result = await response.json(); - if (result.success) { - alert('Login exitoso'); - window.location.href = '/dashboard'; - } else { - alert('Error: ' + result.message); + switch (result.status) { + case "success": + window.location.href = '/app/dashboard'; + break; + + case "missing": + window.location.href = '/update-credentials'; + break; + + case "error": + if (result.message === "no_password") { + window.location.href = '/update-credentials'; + } else { + alert("Error: " + result.message); + } + break; + + default: + alert("Respuesta inesperada del servidor"); + break; + } + } catch (error) { + console.error("Error en la solicitud:", error); + alert("Hubo un error al intentar iniciar sesión. Inténtalo de nuevo."); } }); \ No newline at end of file