Skip to content

Commit 83e2677

Browse files
Fix login design and to implement security(but is in progress)
1 parent 31db544 commit 83e2677

File tree

4 files changed

+69
-37
lines changed

4 files changed

+69
-37
lines changed

src/api/usuario/administrador.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,24 @@ export async function consultarUsuarios(filtros) {
2121
}
2222
}
2323

24+
/**
25+
* Consulta un usuario por su correo institucional.
26+
* @param {string} correo - Correo institucional del usuario.
27+
* @returns {Promise<Object>} - Datos del usuario.
28+
* @throws {Error} - Si la consulta falla.
29+
*/
30+
export async function consultarUsuarioPorCorreo(correo) {
31+
try {
32+
// Verifica la ruta y el parámetro "correo"
33+
const response = await axios.get(`${ADMIN_API}/usuarioPorCorreo`, {
34+
params: { correo: correo },
35+
});
36+
return response.data;
37+
} catch (error) {
38+
throw new Error(error.response?.data?.message || "Error consultando usuario");
39+
}
40+
}
41+
2442
/**
2543
* Agrega un nuevo usuario al sistema.
2644
* @param {Object} usuario - Datos del usuario a agregar.

src/components/Login/FormInput.js

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,35 @@
11
import React from "react";
22
import styled from "styled-components";
3-
import PropTypes from "prop-types";
43

5-
const FormInput = ({ label, type = "text" }) => {
4+
const FormInput = ({ label, type = "text", onChange, placeholder }) => {
65
return (
76
<InputWrapper>
87
<InputLabel>{label}</InputLabel>
9-
<StyledInput type={type} aria-label={label} />
8+
<StyledInput
9+
type={type}
10+
aria-label={label}
11+
onChange={onChange}
12+
placeholder={placeholder}
13+
/>
1014
<InputUnderline />
1115
</InputWrapper>
1216
);
1317
};
1418

1519
const InputWrapper = styled.div`
16-
margin-bottom: 108px;
20+
margin-bottom: 60px; /* Ajusta el espacio vertical entre los campos */
1721
width: 100%;
1822
@media (max-width: 640px) {
19-
margin-bottom: 60px;
23+
margin-bottom: 40px;
2024
}
2125
`;
2226

2327
const InputLabel = styled.label`
24-
color: ${(props) => (props.children === "CONTRASEÑA" ? "#000" : "#aaba70")};
28+
color: rgb(22, 45, 255); /* Negro */
2529
font-family: "Inter", sans-serif;
26-
font-size: 11px;
27-
margin-bottom: 22px;
30+
font-size: 18px; /* Tamaño mayor */
31+
font-weight: bold;
32+
margin-bottom: 10px;
2833
display: block;
2934
`;
3035

@@ -33,21 +38,22 @@ const StyledInput = styled.input`
3338
border: none;
3439
background: transparent;
3540
font-family: "Inter", sans-serif;
36-
font-size: 16px;
41+
font-size: 16px; /* Tamaño mayor */
42+
font-weight: bold;
3743
outline: none;
3844
padding: 0;
45+
color: #000; /* Texto en negro */
46+
47+
::placeholder {
48+
color: #999; /* Color del placeholder */
49+
}
3950
`;
4051

4152
const InputUnderline = styled.div`
4253
width: 100%;
4354
height: 1px;
44-
margin-top: 20px;
55+
margin-top: 10px;
4556
background-color: #aaba70;
4657
`;
47-
FormInput.propTypes = {
48-
label: PropTypes.string.isRequired,
49-
type: PropTypes.string,
50-
};
5158

5259
export default FormInput;
53-

src/components/Login/LoginForm.js

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,33 @@ import React, { useState } from "react";
22
import styled from "styled-components";
33
import FormInput from "./FormInput";
44
import { useNavigate } from "react-router-dom";
5+
import { consultarUsuarioPorCorreo } from "../../api/usuario/administrador"; // Importa la nueva función
6+
57

68
const LoginForm = () => {
79
const navigate = useNavigate();
810
const [correo, setCorreo] = useState("");
9-
const [password, setPassword] = useState("");
11+
const [password, setPassword] = useState(""); // Aquí se ingresa el idInstitucional
12+
const [errorMsg, setErrorMsg] = useState("");
1013

1114
const handleSubmit = async (e) => {
1215
e.preventDefault();
13-
// Aquí realiza la llamada a tu API de login con fetch o axios.
14-
// Por ejemplo:
15-
/*
16+
setErrorMsg("");
1617
try {
17-
const response = await fetch('https://localhost:8443/api/auth/login', {
18-
method: 'POST',
19-
headers: { 'Content-Type': 'application/json' },
20-
body: JSON.stringify({ correo, password })
21-
});
22-
if (!response.ok) throw new Error('Error en la autenticación');
23-
const data = await response.json();
24-
// Guarda el token en localStorage o maneja la cookie según corresponda
25-
localStorage.setItem('token', data.token);
26-
// Redirige a la pantalla de administrador
27-
navigate('/adminhome');
18+
// Consulta el usuario por su correo institucional
19+
const usuario = await consultarUsuarioPorCorreo(correo);
20+
// Valida que el idInstitucional (password) ingresado sea igual al del usuario retornado.
21+
if (usuario && String(usuario.idInstitucional) === password) {
22+
// Si coincide, redirige a la pantalla de administrador
23+
localStorage.setItem("token", "dummy-token");
24+
navigate("/adminhome");
25+
} else {
26+
setErrorMsg("Usuario no encontrado o contraseña incorrecta");
27+
}
2828
} catch (error) {
29+
setErrorMsg("Usuario no encontrado o contraseña incorrecta");
2930
console.error(error);
30-
// Aquí puedes mostrar un mensaje de error en la UI
3131
}
32-
*/
33-
// Para la demostración, simulamos un login exitoso:
34-
localStorage.setItem("token", "dummy-token");
35-
navigate("/adminhome");
3632
};
3733

3834
return (
@@ -45,15 +41,18 @@ const LoginForm = () => {
4541
<FormInput
4642
label="CORREO INSTITUCIONAL"
4743
type="email"
44+
placeholder="[email protected]"
4845
onChange={(e) => setCorreo(e.target.value)}
4946
/>
5047
<FormInput
5148
label="CONTRASEÑA"
5249
type="password"
50+
placeholder="idInstitucional"
5351
onChange={(e) => setPassword(e.target.value)}
5452
/>
5553
<LoginButton type="submit">Ingresar</LoginButton>
5654
</form>
55+
{errorMsg && <ErrorMessage>{errorMsg}</ErrorMessage>}
5756
<CvdsLogo
5857
src="https://cdn.builder.io/api/v1/image/assets/TEMP/a04bfa90ef84cb31360009a48d4d01c2ac370589"
5958
alt="CVDS Logo"
@@ -93,11 +92,12 @@ const LoginButton = styled.button`
9392
height: 54px;
9493
border-radius: 2px;
9594
border: none;
96-
color: #fff;
95+
color:rgb(22, 45, 255);
9796
font-family: "Inter", sans-serif;
9897
font-size: 19px;
9998
font-weight: 700;
10099
margin: 0 auto;
100+
margin-top: 100px;
101101
cursor: pointer;
102102
background-color: #d9ed92;
103103
display: block;
@@ -106,6 +106,14 @@ const LoginButton = styled.button`
106106
}
107107
`;
108108

109+
const ErrorMessage = styled.div`
110+
color: red;
111+
font-size: 16px;
112+
font-weight: bold;
113+
text-align: center;
114+
margin-top: 20px;
115+
`;
116+
109117
const CvdsLogo = styled.img`
110118
width: 59px;
111119
height: 63px;

src/pages/Login/LoginPage.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const PageContainer = styled.main`
1616
display: flex;
1717
width: 100%;
1818
height: 100vh;
19-
background-color: #fff;
19+
background-color:rgb(242, 245, 229);
2020
@media (max-width: 991px) {
2121
flex-direction: column;
2222
}

0 commit comments

Comments
 (0)