add login funccions
This commit is contained in:
@@ -34,7 +34,6 @@ export default function Page() {
|
||||
content: (
|
||||
<>
|
||||
<div className="checkbox-grid">
|
||||
{" "}
|
||||
<label>
|
||||
<input type="checkbox" /> Mesa
|
||||
</label>
|
||||
|
||||
@@ -176,7 +176,6 @@ export default function Page() {
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{" "}
|
||||
<form className="containerForm">
|
||||
<label className="label">Ubicacion de equipo</label>
|
||||
|
||||
@@ -213,7 +212,6 @@ export default function Page() {
|
||||
>
|
||||
<option value="">-- Selecciona una sancion --</option>
|
||||
<option value="sancion 1">
|
||||
{" "}
|
||||
No cerrar sesion (Una semana)
|
||||
</option>
|
||||
</select>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
'use client';
|
||||
import { useState } from "react";
|
||||
import axios from "axios";
|
||||
import "./Login.css";
|
||||
import { loginUser } from "@/app/lib/login";
|
||||
|
||||
function Login() {
|
||||
const [user, setUser] = useState("");
|
||||
@@ -11,17 +11,14 @@ function Login() {
|
||||
const handleLogin = async (e: React.FormEvent<HTMLFormElement>) => {
|
||||
e.preventDefault();
|
||||
|
||||
try {
|
||||
const response = await axios.post(`${process.env.NEXT_PUBLIC_API_URL}/user`, {
|
||||
usuario: user,
|
||||
password: password,
|
||||
});
|
||||
const data = await loginUser(user, password);
|
||||
|
||||
if ("error" in data) {
|
||||
setMessage(data.error);
|
||||
} else {
|
||||
localStorage.setItem("token", data.access_token);
|
||||
setMessage("Inicio de sesión exitoso");
|
||||
console.log("Respuesta del servidor:", response.data);
|
||||
} catch (error) {
|
||||
setMessage("Error en inicio de sesión");
|
||||
console.error("Error:", error);
|
||||
console.log("Respuesta del servidor:", data);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -65,14 +62,14 @@ function Login() {
|
||||
>Iniciar sesión
|
||||
</button>
|
||||
|
||||
{message &&
|
||||
<div
|
||||
className={`messageBox ${message.includes('exitoso') ? 'success' : 'error'}`}
|
||||
style={{ marginTop: '10px' }}
|
||||
>
|
||||
{message}
|
||||
</div>
|
||||
}
|
||||
{message &&
|
||||
<div
|
||||
className={`messageBox ${message.includes('exitoso') ? 'success' : 'error'}`}
|
||||
style={{ marginTop: '10px' }}
|
||||
>
|
||||
{message}
|
||||
</div>
|
||||
}
|
||||
</form>
|
||||
</section>
|
||||
);
|
||||
|
||||
@@ -49,59 +49,58 @@ function ProgramSelector({ titulo, opcion }: DatosEquipo) {
|
||||
</label>
|
||||
<label>
|
||||
<input type="checkbox" /> COREL DRAW
|
||||
</label>{" "}
|
||||
</label>
|
||||
<label>
|
||||
<input type="checkbox" /> DEV-C++
|
||||
</label>{" "}
|
||||
</label>
|
||||
<label>
|
||||
<input type="checkbox" /> EVIEWS Enterprise
|
||||
</label>{" "}
|
||||
</label>
|
||||
<label>
|
||||
<input type="checkbox" /> Google Earth
|
||||
</label>{" "}
|
||||
</label>
|
||||
<label>
|
||||
<input type="checkbox" /> INTERNERT
|
||||
</label>{" "}
|
||||
</label>
|
||||
<label>
|
||||
<input type="checkbox" /> MAPLE
|
||||
</label>
|
||||
<label>
|
||||
<input type="checkbox" /> MATHEMATICA
|
||||
</label>{" "}
|
||||
</label>
|
||||
<label>
|
||||
<input type="checkbox" /> MATLAB
|
||||
</label>{" "}
|
||||
</label>
|
||||
<label>
|
||||
<input type="checkbox" /> Maxima
|
||||
</label>{" "}
|
||||
</label>
|
||||
<label>
|
||||
<input type="checkbox" /> miktex
|
||||
</label>{" "}
|
||||
</label>
|
||||
<label>
|
||||
<input type="checkbox" /> NETBEANS
|
||||
</label>{" "}
|
||||
</label>
|
||||
<label>
|
||||
<input type="checkbox" /> OFFICE 2016
|
||||
</label>{" "}
|
||||
</label>
|
||||
<label>
|
||||
<input type="checkbox" /> PSeint
|
||||
</label>{" "}
|
||||
</label>
|
||||
<label>
|
||||
<input type="checkbox" /> R 3.0.1
|
||||
</label>{" "}
|
||||
</label>
|
||||
<label>
|
||||
<input type="checkbox" /> R Studio
|
||||
</label>{" "}
|
||||
</label>
|
||||
<label>
|
||||
<input type="checkbox" /> SPPS Statiscs
|
||||
</label>{" "}
|
||||
</label>
|
||||
<label>
|
||||
<input type="checkbox" /> STATA 13
|
||||
</label>{" "}
|
||||
</label>
|
||||
<label>
|
||||
<input type="checkbox" /> STATGRAOHICS Centurion XVI
|
||||
</label>
|
||||
{/* ... resto de checkboxes */}
|
||||
</div>
|
||||
|
||||
<button className="button buttonSearch">Guardar cambios</button>
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
export const envConfig = {
|
||||
apiUrl: process.env.NEXT_PUBLIC_API_URL,
|
||||
};
|
||||
@@ -0,0 +1,15 @@
|
||||
import axios from "axios";
|
||||
import { envConfig } from "./config";
|
||||
|
||||
export async function loginUser(usuario: string, password: string) {
|
||||
try {
|
||||
const response = await axios.post(`${envConfig.apiUrl}/user`, { usuario, password });
|
||||
return response.data;
|
||||
} catch (error: any) {
|
||||
const msg =
|
||||
error.response?.data?.message ||
|
||||
error.message ||
|
||||
"Error desconocido en el login";
|
||||
return { error: msg };
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user