From fcc64e8a39d22a8d32f9fb364b8cffa7d29b720d Mon Sep 17 00:00:00 2001 From: Elliot Axel Noriega Date: Wed, 10 Jul 2024 15:08:27 -0600 Subject: [PATCH 1/3] Correcion de ruta para logearse, y ruta de imagen logos de gobierno --- cosiap_frontend/src/App.jsx | 4 ++-- .../common/layouts/LayoutBaseAuthenticator.jsx | 2 +- .../src/components/common/utility/Autenticador.jsx | 2 +- .../components/common/utility/LoginRequiredRoutes.jsx | 4 ++-- cosiap_frontend/src/components/users/Inicio.jsx | 7 +++++++ cosiap_frontend/src/components/users/InicioTest.jsx | 11 ----------- .../src/components/users/Login/LoginForm.jsx | 4 +++- 7 files changed, 16 insertions(+), 18 deletions(-) create mode 100644 cosiap_frontend/src/components/users/Inicio.jsx delete mode 100644 cosiap_frontend/src/components/users/InicioTest.jsx diff --git a/cosiap_frontend/src/App.jsx b/cosiap_frontend/src/App.jsx index 5590358..8b29bce 100644 --- a/cosiap_frontend/src/App.jsx +++ b/cosiap_frontend/src/App.jsx @@ -6,7 +6,7 @@ import {LoginRequiredRoutes} from "@/components/common/utility/LoginRequiredRout import "./App.css"; import { AuthPage } from "./components/users/AuthPage"; -import {InicioTest} from './components/users/InicioTest'; +import Inicio from "./components/users/Inicio"; function App() { @@ -27,7 +27,7 @@ function App() { {/* Rutas protegidas */} }> - } /> + } /> diff --git a/cosiap_frontend/src/components/common/layouts/LayoutBaseAuthenticator.jsx b/cosiap_frontend/src/components/common/layouts/LayoutBaseAuthenticator.jsx index 53e85fc..99c8343 100644 --- a/cosiap_frontend/src/components/common/layouts/LayoutBaseAuthenticator.jsx +++ b/cosiap_frontend/src/components/common/layouts/LayoutBaseAuthenticator.jsx @@ -25,7 +25,7 @@ export default function LayoutBaseAuthenticator({title, children}) {
company

{ const contextoAut = useContext(ContextoAut); - + console.log(contextoAut) if (!contextoAut) { throw new Error( "useAutenticacion se tiene que usar dentro de un componente autenticador" diff --git a/cosiap_frontend/src/components/common/utility/LoginRequiredRoutes.jsx b/cosiap_frontend/src/components/common/utility/LoginRequiredRoutes.jsx index 627f5d7..660cbfc 100644 --- a/cosiap_frontend/src/components/common/utility/LoginRequiredRoutes.jsx +++ b/cosiap_frontend/src/components/common/utility/LoginRequiredRoutes.jsx @@ -3,9 +3,9 @@ import { Navigate, Outlet } from "react-router-dom"; export const LoginRequiredRoutes = () => { const { token } = useAutenticacion(); - + if (token === null) { - return ; + return ; } else if (token === undefined) { return null; // O un spinner de carga o marcador de posición } else { diff --git a/cosiap_frontend/src/components/users/Inicio.jsx b/cosiap_frontend/src/components/users/Inicio.jsx new file mode 100644 index 0000000..a6d7e7b --- /dev/null +++ b/cosiap_frontend/src/components/users/Inicio.jsx @@ -0,0 +1,7 @@ +export default function Inicio() { + return ( +
+

Inicio

+
+ ); +} diff --git a/cosiap_frontend/src/components/users/InicioTest.jsx b/cosiap_frontend/src/components/users/InicioTest.jsx deleted file mode 100644 index 9b6e9e1..0000000 --- a/cosiap_frontend/src/components/users/InicioTest.jsx +++ /dev/null @@ -1,11 +0,0 @@ -export const InicioTest = () => { - return ( -
-

Inicio

-

Inicio

-

Inicio

-

Inicio

-
Inicio
-
- ); -} diff --git a/cosiap_frontend/src/components/users/Login/LoginForm.jsx b/cosiap_frontend/src/components/users/Login/LoginForm.jsx index c6d1a0b..c087f74 100644 --- a/cosiap_frontend/src/components/users/Login/LoginForm.jsx +++ b/cosiap_frontend/src/components/users/Login/LoginForm.jsx @@ -6,6 +6,7 @@ import {LoginInputCURP} from '@/components/users/Login/LoginInputCURP' import { LoginInputPassword } from "@/components/users/Login/LoginInputPassword"; import { useState } from "react"; import {ErrorDisplay} from '@/components/common/ui/ErrorDisplay' +import { Navigate } from "react-router-dom"; const CURP_REGEX = /^[A-Z]{1}[AEIOU]{1}[A-Z]{2}[0-9]{2}(0[1-9]|1[0-2])(0[1-9]|1[0-9]|2[0-9]|3[0-1])[HM]{1}(AS|BC|BS|CC|CH|CL|CM|DF|DG|GT|GR|HG|JC|MC|MN|MS|NT|NL|OC|PL|QT|QR|SP|SL|SR|TC|TS|TL|VZ|YN|ZS|NE)[B-DF-HJ-NP-TV-Z]{3}[0-9A-Z]{1}[0-9]{1}$/; @@ -26,11 +27,12 @@ export function LoginForm() { resolver: yupResolver(validationSchema), }); + const onSubmit = async (data) => { try { const response = await api.usuarios.token.login(data); console.log("Login successful:", response.data); - // Manejar la respuesta exitosa aquí + } catch (error) { console.error("Login failed:", error); setLoginError(error.response.data.detail) -- GitLab From 97ec50db64362e09b84b50a4badda4ad1e16a1d9 Mon Sep 17 00:00:00 2001 From: Elliot Axel Noriega Date: Thu, 11 Jul 2024 11:56:40 -0600 Subject: [PATCH 2/3] Autenticacion --- cosiap_frontend/src/App.jsx | 1 - .../src/components/common/utility/Autenticador.jsx | 1 - .../src/components/common/utility/LoginRequiredRoutes.jsx | 4 ++-- cosiap_frontend/src/components/users/Login/LoginForm.jsx | 5 +++-- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/cosiap_frontend/src/App.jsx b/cosiap_frontend/src/App.jsx index 8b29bce..adbdd3f 100644 --- a/cosiap_frontend/src/App.jsx +++ b/cosiap_frontend/src/App.jsx @@ -1,4 +1,3 @@ -import React, { useEffect, useState } from "react"; import { BrowserRouter, Routes, Route, Navigate } from 'react-router-dom'; import {PaginaHead} from "@/components/common/utility/PaginaHead"; import {Autenticador} from "@/components/common/utility/Autenticador"; diff --git a/cosiap_frontend/src/components/common/utility/Autenticador.jsx b/cosiap_frontend/src/components/common/utility/Autenticador.jsx index 8de5779..4b67a9f 100644 --- a/cosiap_frontend/src/components/common/utility/Autenticador.jsx +++ b/cosiap_frontend/src/components/common/utility/Autenticador.jsx @@ -12,7 +12,6 @@ const ContextoAut = createContext(undefined); export const useAutenticacion = () => { const contextoAut = useContext(ContextoAut); - console.log(contextoAut) if (!contextoAut) { throw new Error( "useAutenticacion se tiene que usar dentro de un componente autenticador" diff --git a/cosiap_frontend/src/components/common/utility/LoginRequiredRoutes.jsx b/cosiap_frontend/src/components/common/utility/LoginRequiredRoutes.jsx index 660cbfc..b921962 100644 --- a/cosiap_frontend/src/components/common/utility/LoginRequiredRoutes.jsx +++ b/cosiap_frontend/src/components/common/utility/LoginRequiredRoutes.jsx @@ -3,7 +3,7 @@ import { Navigate, Outlet } from "react-router-dom"; export const LoginRequiredRoutes = () => { const { token } = useAutenticacion(); - + if (token === null) { return ; } else if (token === undefined) { @@ -13,4 +13,4 @@ export const LoginRequiredRoutes = () => { } }; -export default LoginRequiredRoutes; +export default LoginRequiredRoutes; \ No newline at end of file diff --git a/cosiap_frontend/src/components/users/Login/LoginForm.jsx b/cosiap_frontend/src/components/users/Login/LoginForm.jsx index c087f74..3632137 100644 --- a/cosiap_frontend/src/components/users/Login/LoginForm.jsx +++ b/cosiap_frontend/src/components/users/Login/LoginForm.jsx @@ -6,7 +6,7 @@ import {LoginInputCURP} from '@/components/users/Login/LoginInputCURP' import { LoginInputPassword } from "@/components/users/Login/LoginInputPassword"; import { useState } from "react"; import {ErrorDisplay} from '@/components/common/ui/ErrorDisplay' -import { Navigate } from "react-router-dom"; +import { useNavigate } from "react-router-dom"; const CURP_REGEX = /^[A-Z]{1}[AEIOU]{1}[A-Z]{2}[0-9]{2}(0[1-9]|1[0-2])(0[1-9]|1[0-9]|2[0-9]|3[0-1])[HM]{1}(AS|BC|BS|CC|CH|CL|CM|DF|DG|GT|GR|HG|JC|MC|MN|MS|NT|NL|OC|PL|QT|QR|SP|SL|SR|TC|TS|TL|VZ|YN|ZS|NE)[B-DF-HJ-NP-TV-Z]{3}[0-9A-Z]{1}[0-9]{1}$/; @@ -19,6 +19,7 @@ const validationSchema = Yup.object({ export function LoginForm() { const [loginError, setLoginError] = useState('') + const navigate = useNavigate(); const { register, handleSubmit, @@ -32,7 +33,7 @@ export function LoginForm() { try { const response = await api.usuarios.token.login(data); console.log("Login successful:", response.data); - + navigate("/inicio"); } catch (error) { console.error("Login failed:", error); setLoginError(error.response.data.detail) -- GitLab From d0b6bc76585db2b1277a3041942a55bf9aa931a1 Mon Sep 17 00:00:00 2001 From: RafaUC Date: Thu, 11 Jul 2024 13:48:21 -0600 Subject: [PATCH 3/3] seteo corrrecto de sesion despues de login --- cosiap_api/cosiap_api/settings.py | 4 ++-- .../src/components/common/utility/Autenticador.jsx | 2 +- cosiap_frontend/src/components/users/Login/LoginForm.jsx | 5 ++++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/cosiap_api/cosiap_api/settings.py b/cosiap_api/cosiap_api/settings.py index 3341e2c..ac1f99c 100644 --- a/cosiap_api/cosiap_api/settings.py +++ b/cosiap_api/cosiap_api/settings.py @@ -192,8 +192,8 @@ SESSION_COOKIE_SECURE = True SESSION_COOKIE_HTTPONLY = True SIMPLE_JWT = { - 'ACCESS_TOKEN_LIFETIME': timedelta(minutes=0.5), - 'REFRESH_TOKEN_LIFETIME': timedelta(minutes=1), + 'ACCESS_TOKEN_LIFETIME': timedelta(minutes=3), + 'REFRESH_TOKEN_LIFETIME': timedelta(days=1), 'ROTATE_REFRESH_TOKENS': False, 'BLACKLIST_AFTER_ROTATION': False, 'ALGORITHM': 'HS256', diff --git a/cosiap_frontend/src/components/common/utility/Autenticador.jsx b/cosiap_frontend/src/components/common/utility/Autenticador.jsx index 4b67a9f..dcb8654 100644 --- a/cosiap_frontend/src/components/common/utility/Autenticador.jsx +++ b/cosiap_frontend/src/components/common/utility/Autenticador.jsx @@ -76,7 +76,7 @@ export const Autenticador = ({ children }) => { }; }); return ( - + {children} ); diff --git a/cosiap_frontend/src/components/users/Login/LoginForm.jsx b/cosiap_frontend/src/components/users/Login/LoginForm.jsx index 3632137..a3344bb 100644 --- a/cosiap_frontend/src/components/users/Login/LoginForm.jsx +++ b/cosiap_frontend/src/components/users/Login/LoginForm.jsx @@ -7,6 +7,7 @@ import { LoginInputPassword } from "@/components/users/Login/LoginInputPassword" import { useState } from "react"; import {ErrorDisplay} from '@/components/common/ui/ErrorDisplay' import { useNavigate } from "react-router-dom"; +import {useAutenticacion} from "@/components/common/utility/Autenticador" const CURP_REGEX = /^[A-Z]{1}[AEIOU]{1}[A-Z]{2}[0-9]{2}(0[1-9]|1[0-2])(0[1-9]|1[0-9]|2[0-9]|3[0-1])[HM]{1}(AS|BC|BS|CC|CH|CL|CM|DF|DG|GT|GR|HG|JC|MC|MN|MS|NT|NL|OC|PL|QT|QR|SP|SL|SR|TC|TS|TL|VZ|YN|ZS|NE)[B-DF-HJ-NP-TV-Z]{3}[0-9A-Z]{1}[0-9]{1}$/; @@ -20,6 +21,7 @@ const validationSchema = Yup.object({ export function LoginForm() { const [loginError, setLoginError] = useState('') const navigate = useNavigate(); + const { setToken } = useAutenticacion(); const { register, handleSubmit, @@ -32,7 +34,8 @@ export function LoginForm() { const onSubmit = async (data) => { try { const response = await api.usuarios.token.login(data); - console.log("Login successful:", response.data); + console.log("Login successful:", response.data); + setToken(response.data.access) navigate("/inicio"); } catch (error) { console.error("Login failed:", error); -- GitLab