From 5256a49dd4601adce7eab799c665a7d842be3a97 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Omar=20Luna=20Hern=C3=A1ndez?= <42101656@uaz.edu.mx>
Date: Fri, 22 Mar 2024 13:26:19 -0600
Subject: [PATCH 01/34] Se agregaron las dependencias de axios, font awesome
free solid svg icons y react-fontawesome
---
web/package-lock.json | 86 +++++++++++++++++++++++++++++++++++++++++--
web/package.json | 6 +++
2 files changed, 89 insertions(+), 3 deletions(-)
diff --git a/web/package-lock.json b/web/package-lock.json
index 202bff49..56b6f8ca 100644
--- a/web/package-lock.json
+++ b/web/package-lock.json
@@ -8,6 +8,8 @@
"name": "web",
"version": "0.1.0",
"dependencies": {
+ "@fortawesome/free-solid-svg-icons": "^6.5.1",
+ "@fortawesome/react-fontawesome": "^0.2.0",
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
@@ -15,11 +17,15 @@
"@types/node": "^16.18.87",
"@types/react": "^18.2.64",
"@types/react-dom": "^18.2.21",
+ "axios": "^1.6.8",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "5.0.1",
"typescript": "^4.9.5",
"web-vitals": "^2.1.4"
+ },
+ "devDependencies": {
+ "tailwindcss": "^3.4.1"
}
},
"node_modules/@aashutoshrathi/word-wrap": {
@@ -2381,6 +2387,52 @@
"node": "^12.22.0 || ^14.17.0 || >=16.0.0"
}
},
+ "node_modules/@fortawesome/fontawesome-common-types": {
+ "version": "6.5.1",
+ "resolved": "https://registry.npmjs.org/@fortawesome/fontawesome-common-types/-/fontawesome-common-types-6.5.1.tgz",
+ "integrity": "sha512-GkWzv+L6d2bI5f/Vk6ikJ9xtl7dfXtoRu3YGE6nq0p/FFqA1ebMOAWg3XgRyb0I6LYyYkiAo+3/KrwuBp8xG7A==",
+ "hasInstallScript": true,
+ "engines": {
+ "node": ">=6"
+ }
+ },
+ "node_modules/@fortawesome/fontawesome-svg-core": {
+ "version": "6.5.1",
+ "resolved": "https://registry.npmjs.org/@fortawesome/fontawesome-svg-core/-/fontawesome-svg-core-6.5.1.tgz",
+ "integrity": "sha512-MfRCYlQPXoLlpem+egxjfkEuP9UQswTrlCOsknus/NcMoblTH2g0jPrapbcIb04KGA7E2GZxbAccGZfWoYgsrQ==",
+ "hasInstallScript": true,
+ "peer": true,
+ "dependencies": {
+ "@fortawesome/fontawesome-common-types": "6.5.1"
+ },
+ "engines": {
+ "node": ">=6"
+ }
+ },
+ "node_modules/@fortawesome/free-solid-svg-icons": {
+ "version": "6.5.1",
+ "resolved": "https://registry.npmjs.org/@fortawesome/free-solid-svg-icons/-/free-solid-svg-icons-6.5.1.tgz",
+ "integrity": "sha512-S1PPfU3mIJa59biTtXJz1oI0+KAXW6bkAb31XKhxdxtuXDiUIFsih4JR1v5BbxY7hVHsD1RKq+jRkVRaf773NQ==",
+ "hasInstallScript": true,
+ "dependencies": {
+ "@fortawesome/fontawesome-common-types": "6.5.1"
+ },
+ "engines": {
+ "node": ">=6"
+ }
+ },
+ "node_modules/@fortawesome/react-fontawesome": {
+ "version": "0.2.0",
+ "resolved": "https://registry.npmjs.org/@fortawesome/react-fontawesome/-/react-fontawesome-0.2.0.tgz",
+ "integrity": "sha512-uHg75Rb/XORTtVt7OS9WoK8uM276Ufi7gCzshVWkUJbHhh3svsUUeqXerrM96Wm7fRiDzfKRwSoahhMIkGAYHw==",
+ "dependencies": {
+ "prop-types": "^15.8.1"
+ },
+ "peerDependencies": {
+ "@fortawesome/fontawesome-svg-core": "~1 || ~6",
+ "react": ">=16.3"
+ }
+ },
"node_modules/@humanwhocodes/config-array": {
"version": "0.11.14",
"resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.11.14.tgz",
@@ -5223,6 +5275,29 @@
"node": ">=4"
}
},
+ "node_modules/axios": {
+ "version": "1.6.8",
+ "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.8.tgz",
+ "integrity": "sha512-v/ZHtJDU39mDpyBoFVkETcd/uNdxrWRrg3bKpOKzXFA6Bvqopts6ALSMU3y6ijYxbw2B+wPrIv46egTzJXCLGQ==",
+ "dependencies": {
+ "follow-redirects": "^1.15.6",
+ "form-data": "^4.0.0",
+ "proxy-from-env": "^1.1.0"
+ }
+ },
+ "node_modules/axios/node_modules/form-data": {
+ "version": "4.0.0",
+ "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz",
+ "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==",
+ "dependencies": {
+ "asynckit": "^0.4.0",
+ "combined-stream": "^1.0.8",
+ "mime-types": "^2.1.12"
+ },
+ "engines": {
+ "node": ">= 6"
+ }
+ },
"node_modules/axobject-query": {
"version": "3.2.1",
"resolved": "https://registry.npmjs.org/axobject-query/-/axobject-query-3.2.1.tgz",
@@ -8308,9 +8383,9 @@
"integrity": "sha512-X8cqMLLie7KsNUDSdzeN8FYK9rEt4Dt67OsG/DNGnYTSDBG4uFAJFBnUeiV+zCVAvwFy56IjM9sH51jVaEhNxw=="
},
"node_modules/follow-redirects": {
- "version": "1.15.5",
- "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.5.tgz",
- "integrity": "sha512-vSFWUON1B+yAw1VN4xMfxgn5fTUiaOzAJCKBwIIgT/+7CuGy9+r+5gITvP62j3RmaD5Ph65UaERdOSRGUzZtgw==",
+ "version": "1.15.6",
+ "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.6.tgz",
+ "integrity": "sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA==",
"funding": [
{
"type": "individual",
@@ -14522,6 +14597,11 @@
"node": ">= 0.10"
}
},
+ "node_modules/proxy-from-env": {
+ "version": "1.1.0",
+ "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz",
+ "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg=="
+ },
"node_modules/psl": {
"version": "1.9.0",
"resolved": "https://registry.npmjs.org/psl/-/psl-1.9.0.tgz",
diff --git a/web/package.json b/web/package.json
index 600a7e75..0df47da9 100644
--- a/web/package.json
+++ b/web/package.json
@@ -3,6 +3,8 @@
"version": "0.1.0",
"private": true,
"dependencies": {
+ "@fortawesome/free-solid-svg-icons": "^6.5.1",
+ "@fortawesome/react-fontawesome": "^0.2.0",
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
@@ -10,6 +12,7 @@
"@types/node": "^16.18.87",
"@types/react": "^18.2.64",
"@types/react-dom": "^18.2.21",
+ "axios": "^1.6.8",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "5.0.1",
@@ -39,5 +42,8 @@
"last 1 firefox version",
"last 1 safari version"
]
+ },
+ "devDependencies": {
+ "tailwindcss": "^3.4.1"
}
}
--
GitLab
From 34f8bdbf8cbaeff240ceeb864e7cb254c8920af2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Omar=20Luna=20Hern=C3=A1ndez?= <42101656@uaz.edu.mx>
Date: Fri, 22 Mar 2024 13:27:12 -0600
Subject: [PATCH 02/34] =?UTF-8?q?Se=20agrega=20la=20pagina=20de=20login=20?=
=?UTF-8?q?como=20la=20p=C3=A1gina=20principal?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
web/src/App.tsx | 18 ++----------------
1 file changed, 2 insertions(+), 16 deletions(-)
diff --git a/web/src/App.tsx b/web/src/App.tsx
index a53698aa..730f36e7 100644
--- a/web/src/App.tsx
+++ b/web/src/App.tsx
@@ -1,24 +1,10 @@
-import React from 'react';
-import logo from './logo.svg';
import './App.css';
+import { LoginPage } from './pages/login_page/login_page';
function App() {
return (
);
}
--
GitLab
From 3a940796273b48d3f54da1c53ed74a59a7c23a8d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Omar=20Luna=20Hern=C3=A1ndez?= <42101656@uaz.edu.mx>
Date: Fri, 22 Mar 2024 13:27:38 -0600
Subject: [PATCH 03/34] =?UTF-8?q?Se=20crea=20la=20p=C3=A1gina=20de=20inici?=
=?UTF-8?q?o=20de=20sesi=C3=B3n?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
web/src/pages/login_page/login_page.tsx | 53 +++++++++++++++++++++++++
1 file changed, 53 insertions(+)
create mode 100644 web/src/pages/login_page/login_page.tsx
diff --git a/web/src/pages/login_page/login_page.tsx b/web/src/pages/login_page/login_page.tsx
new file mode 100644
index 00000000..cb9b0f6d
--- /dev/null
+++ b/web/src/pages/login_page/login_page.tsx
@@ -0,0 +1,53 @@
+import { usePasswoordVisibility } from "../../hooks/usePasswordVisibility"
+import "./styles/styles.css"
+import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
+import { faEye , faEyeSlash} from "@fortawesome/free-solid-svg-icons";
+
+export const LoginPage = () => {
+ const {
+ values,
+ handleClickShowPassword,
+ handleMouseDownPassword,
+ } = usePasswoordVisibility();
+
+
+ return (
+
+ )
+
+}
\ No newline at end of file
--
GitLab
From d779fae057aa9d2de44e153f1e4040b8962eeee3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Omar=20Luna=20Hern=C3=A1ndez?= <42101656@uaz.edu.mx>
Date: Fri, 22 Mar 2024 13:28:00 -0600
Subject: [PATCH 04/34] =?UTF-8?q?Se=20crea=20el=20archivo=20para=20la=20p?=
=?UTF-8?q?=C3=A1gina=20de=20inicio=20de=20sesi=C3=B3n?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
web/src/pages/login_page/styles/styles.css | 122 +++++++++++++++++++++
1 file changed, 122 insertions(+)
create mode 100644 web/src/pages/login_page/styles/styles.css
diff --git a/web/src/pages/login_page/styles/styles.css b/web/src/pages/login_page/styles/styles.css
new file mode 100644
index 00000000..91b5d62c
--- /dev/null
+++ b/web/src/pages/login_page/styles/styles.css
@@ -0,0 +1,122 @@
+@import url('https://fonts.googleapis.com/css?family=Poppins:400,500,600,700&display=swap');
+
+* {
+ margin: 10;
+ padding: 0;
+ font-family: 'Poppins', sans-serif;
+ box-sizing: border-box;
+}
+
+.login-page-root{
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ height: 100vh;
+ width: 100vw;
+}
+
+.login-form-container{
+ border-radius: 15px;
+ background: white;
+ display: grid;
+ place-items: center;
+ box-shadow: 0px 15px 20px rgba(0,0,0,0.1);
+}
+
+.login-form-container .title{
+ font-size: 35px;
+ font-weight: 600;
+ width: 100%;
+ color: white;
+ line-height: 50px;
+ text-align: center;
+ user-select: none;
+ border-radius: 15px 15px 0 0;
+ background: linear-gradient(-140deg,#413d3d, rgb(0, 0, 0))
+}
+
+.login-form-container form{
+ padding: 10px 40px 50px 30px;
+}
+
+.login-form-container .login-form-field{
+ position: relative;
+ height: 50px;
+ width: 100%;
+ margin-top: 20px;
+}
+
+.login-form-container form .login-form-field input{
+ height: 100%;
+ width: 100%;
+ outline: none;
+ font-size: 17px;
+ padding-left: 20px;
+ padding-right: 30px;
+ border: 1px solid lightgray;
+ border-radius: 15px;
+ transition: all 0.3s ease;
+}
+
+.login-form-container form .login-form-field input:focus,
+form .login-form-field input:valid{
+ border-color: #4158d0;
+}
+
+.login-form-container form .login-form-field label{
+ position: absolute;
+ top: 50%;
+ left: 20px;
+ color: #999999;
+ font-weight: 400;
+ font-size: 17px;
+ pointer-events: none;
+ transform: all 0.3s ease;
+ transform: translateY(-50%);
+}
+
+.login-form-container form .login-form-field .pass-visibility-button{
+ position: absolute;
+ top: 50%;
+ right: 5px;
+ transform: translateY(-50%);
+ transform: all 0.3s ease;
+ cursor: pointer;
+}
+
+
+form .login-form-field input:focus ~ label,
+form .login-form-field input:valid ~ label,
+form .login-form-field input[type="email"]:not(:placeholder-shown) ~ label,
+form .login-form-field input[type="email"]:focus ~ label {
+ top: 0%;
+ color: #4158d0;
+ font-size: 16px;
+ background-color: white;
+ transform: translateY(-50%);
+}
+
+.login-form-container form .login-form-button {
+ height: 50px;
+ width: 100%;
+ margin-top: 20px;
+ position: relative;
+}
+
+form .login-form-button input{
+ color: white;
+ border: none;
+ padding-left: 0;
+ margin-top: -10px;
+ font-size: 20px;
+ font-weight: 500;
+ cursor: pointer;
+ transition: all 0.3s ease;
+ background: black;
+ width: 100%;
+ border-radius: 5px;
+}
+
+form .login-form-button input:active {
+ transform: scale(0.95);
+}
\ No newline at end of file
--
GitLab
From dbc3e70b6efb7678e884359e83d8b0c8b4c5b968 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Omar=20Luna=20Hern=C3=A1ndez?= <42101656@uaz.edu.mx>
Date: Fri, 22 Mar 2024 13:28:42 -0600
Subject: [PATCH 05/34] Se crean las constantes para los roles de SUPERADMIN y
ADMIN
---
web/src/infraestructure/entities/user.ts | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
create mode 100644 web/src/infraestructure/entities/user.ts
diff --git a/web/src/infraestructure/entities/user.ts b/web/src/infraestructure/entities/user.ts
new file mode 100644
index 00000000..a600d77e
--- /dev/null
+++ b/web/src/infraestructure/entities/user.ts
@@ -0,0 +1,19 @@
+import { UserRole } from "../../constants/roles";
+
+export interface UserEntity {
+ name?: string;
+ lastName?: string;
+ email: string;
+ role: UserRole;
+}
+
+export interface LoggedInUser {
+ user: UserEntity;
+ token: string;
+}
+
+export interface UserInfo {
+ name?: string;
+ lastName?: string;
+ email: string;
+}
\ No newline at end of file
--
GitLab
From 8eaa84fc53741a51c052d1a1f7299fc3af0a0414 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Omar=20Luna=20Hern=C3=A1ndez?= <42101656@uaz.edu.mx>
Date: Fri, 22 Mar 2024 13:28:58 -0600
Subject: [PATCH 06/34] Se crea el enumerado para los roles
---
web/src/constants/roles.ts | 7 +++++++
1 file changed, 7 insertions(+)
create mode 100644 web/src/constants/roles.ts
diff --git a/web/src/constants/roles.ts b/web/src/constants/roles.ts
new file mode 100644
index 00000000..02cddf70
--- /dev/null
+++ b/web/src/constants/roles.ts
@@ -0,0 +1,7 @@
+export enum UserRole {
+ ADMIN = "admin",
+ SUPERADMIN = "superadmin",
+}
+
+export const SUPERADMIN_ROLES = [UserRole.SUPERADMIN];
+export const ADMIN_ROLES = [UserRole.ADMIN, UserRole.SUPERADMIN];
\ No newline at end of file
--
GitLab
From b305f09c1e7dc2e77cff9387aff523be6b06ad1b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Omar=20Luna=20Hern=C3=A1ndez?= <42101656@uaz.edu.mx>
Date: Fri, 22 Mar 2024 13:29:32 -0600
Subject: [PATCH 07/34] Se crea la constante para la ruta de la API
---
web/src/constants/api_url.ts | 1 +
1 file changed, 1 insertion(+)
create mode 100644 web/src/constants/api_url.ts
diff --git a/web/src/constants/api_url.ts b/web/src/constants/api_url.ts
new file mode 100644
index 00000000..43f27f05
--- /dev/null
+++ b/web/src/constants/api_url.ts
@@ -0,0 +1 @@
+export const APIUrl: String = "";
\ No newline at end of file
--
GitLab
From 28c2979410eea0dca9c5e043122bf64a6600d1ae Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Omar=20Luna=20Hern=C3=A1ndez?= <42101656@uaz.edu.mx>
Date: Fri, 22 Mar 2024 13:29:56 -0600
Subject: [PATCH 08/34] Se crea el modelo para un usuario logeado
---
web/src/data/models/prod/LoggedInUserModel.ts | 5 +++++
1 file changed, 5 insertions(+)
create mode 100644 web/src/data/models/prod/LoggedInUserModel.ts
diff --git a/web/src/data/models/prod/LoggedInUserModel.ts b/web/src/data/models/prod/LoggedInUserModel.ts
new file mode 100644
index 00000000..e69909a9
--- /dev/null
+++ b/web/src/data/models/prod/LoggedInUserModel.ts
@@ -0,0 +1,5 @@
+export interface LoggedInUserModel {
+ email: string;
+ role: string;
+ token: string;
+}
\ No newline at end of file
--
GitLab
From 07d1611314dd2a2339b39a6b1b47935347318b2a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Omar=20Luna=20Hern=C3=A1ndez?= <42101656@uaz.edu.mx>
Date: Fri, 22 Mar 2024 13:30:19 -0600
Subject: [PATCH 09/34] =?UTF-8?q?Se=20crea=20el=20hook=20para=20cambiar=20?=
=?UTF-8?q?el=20estado=20de=20la=20visibilidad=20de=20la=20contrase=C3=B1a?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
web/src/hooks/usePasswordVisibility.tsx | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
create mode 100644 web/src/hooks/usePasswordVisibility.tsx
diff --git a/web/src/hooks/usePasswordVisibility.tsx b/web/src/hooks/usePasswordVisibility.tsx
new file mode 100644
index 00000000..23108a82
--- /dev/null
+++ b/web/src/hooks/usePasswordVisibility.tsx
@@ -0,0 +1,20 @@
+import { useState } from "react"
+
+export const usePasswoordVisibility = () => {
+ const [values, setValues] = useState({
+ showPassword: false,
+ });
+
+ const handleClickShowPassword = () => {
+ setValues({
+ ...values,
+ showPassword: !values.showPassword,
+ });
+ };
+
+ const handleMouseDownPassword = (event: any) => {
+ event.preventDefault();
+ };
+
+ return {values, handleClickShowPassword, handleMouseDownPassword};
+}
\ No newline at end of file
--
GitLab
From 1f00f2e7dc1fd0047955bd1992f0826f08b712d6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Omar=20Luna=20Hern=C3=A1ndez?= <42101656@uaz.edu.mx>
Date: Fri, 22 Mar 2024 13:30:43 -0600
Subject: [PATCH 10/34] Se crea la interface para los valores que van a ser
enviados en el POST
---
web/src/infraestructure/entities/login_form_values.ts | 4 ++++
1 file changed, 4 insertions(+)
create mode 100644 web/src/infraestructure/entities/login_form_values.ts
diff --git a/web/src/infraestructure/entities/login_form_values.ts b/web/src/infraestructure/entities/login_form_values.ts
new file mode 100644
index 00000000..78456b1e
--- /dev/null
+++ b/web/src/infraestructure/entities/login_form_values.ts
@@ -0,0 +1,4 @@
+export interface LoginFormValues {
+ email : string
+ password : string
+};
\ No newline at end of file
--
GitLab
From ec1879768b3b7177272d0a1ecdd69ee2507ff5f5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Omar=20Luna=20Hern=C3=A1ndez?= <42101656@uaz.edu.mx>
Date: Fri, 22 Mar 2024 13:31:05 -0600
Subject: [PATCH 11/34] =?UTF-8?q?Se=20crea=20la=20l=C3=B3gica=20del=20inic?=
=?UTF-8?q?io=20de=20sesi=C3=B3n?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../data/datasources/prod/login_datasource.ts | 29 +++++++++++++++++++
.../repositories/prod/login_repository.ts | 13 +++++++++
.../datasources/login_datasource.ts | 6 ++++
.../repositories/login_repository.ts | 6 ++++
4 files changed, 54 insertions(+)
create mode 100644 web/src/data/datasources/prod/login_datasource.ts
create mode 100644 web/src/data/repositories/prod/login_repository.ts
create mode 100644 web/src/infraestructure/datasources/login_datasource.ts
create mode 100644 web/src/infraestructure/repositories/login_repository.ts
diff --git a/web/src/data/datasources/prod/login_datasource.ts b/web/src/data/datasources/prod/login_datasource.ts
new file mode 100644
index 00000000..7c006413
--- /dev/null
+++ b/web/src/data/datasources/prod/login_datasource.ts
@@ -0,0 +1,29 @@
+import { LoginDatasourceInf } from "../../../infraestructure/datasources/login_datasource";
+import { LoginFormValues } from "../../../infraestructure/entities/login_form_values";
+import axios from "axios";
+import { LoggedInUser } from "../../../infraestructure/entities/user";
+import { LoggedInUserModel } from "../../models/prod/LoggedInUserModel";
+import { UserRole } from "../../../constants/roles";
+import { APIUrl } from "../../../constants/api_url";
+
+export class LoginDatasourceProd implements LoginDatasourceInf{
+ async getToken(form: LoginFormValues): Promise {
+ const {email, password} = form;
+ const {data} = await axios.post(
+ APIUrl + "/api/auth/login",
+ {
+ email: email,
+ password: password,
+ }
+ );
+ const user: LoggedInUser = {
+ user: {
+ email: data.email,
+ role: data.role === UserRole.SUPERADMIN ? UserRole.SUPERADMIN : UserRole.ADMIN,
+ },
+ token: data.token,
+ };
+
+ return user;
+ }
+}
\ No newline at end of file
diff --git a/web/src/data/repositories/prod/login_repository.ts b/web/src/data/repositories/prod/login_repository.ts
new file mode 100644
index 00000000..69c0694f
--- /dev/null
+++ b/web/src/data/repositories/prod/login_repository.ts
@@ -0,0 +1,13 @@
+import { LoginDatasourceInf } from "../../../infraestructure/datasources/login_datasource";
+import { LoginFormValues } from "../../../infraestructure/entities/login_form_values";
+import { LoggedInUser } from "../../../infraestructure/entities/user";
+import { LoginRepositoryInf } from "../../../infraestructure/repositories/login_repository";
+
+export class LoginRepositoryProd implements LoginRepositoryInf{
+ constructor(
+ private datasource: LoginDatasourceInf
+ ){}
+ async getToken(form: LoginFormValues): Promise {
+ return this.datasource.getToken(form);
+ }
+}
\ No newline at end of file
diff --git a/web/src/infraestructure/datasources/login_datasource.ts b/web/src/infraestructure/datasources/login_datasource.ts
new file mode 100644
index 00000000..762def1d
--- /dev/null
+++ b/web/src/infraestructure/datasources/login_datasource.ts
@@ -0,0 +1,6 @@
+import { LoginFormValues } from "../entities/login_form_values";
+import { LoggedInUser } from "../entities/user";
+
+export interface LoginDatasourceInf {
+ getToken(form: LoginFormValues): Promise;
+}
diff --git a/web/src/infraestructure/repositories/login_repository.ts b/web/src/infraestructure/repositories/login_repository.ts
new file mode 100644
index 00000000..886c8ecc
--- /dev/null
+++ b/web/src/infraestructure/repositories/login_repository.ts
@@ -0,0 +1,6 @@
+import { LoginFormValues } from "../entities/login_form_values";
+import { LoggedInUser } from "../entities/user";
+
+export interface LoginRepositoryInf{
+ getToken(form: LoginFormValues): Promise;
+}
\ No newline at end of file
--
GitLab
From f15f250e621a905ed34e0809b4a55a5bd789182a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Omar=20Luna=20Hern=C3=A1ndez?= <42101656@uaz.edu.mx>
Date: Fri, 22 Mar 2024 13:31:23 -0600
Subject: [PATCH 12/34] =?UTF-8?q?Se=20crea=20el=20hook=20para=20el=20inici?=
=?UTF-8?q?o=20de=20sesi=C3=B3n=20(vac=C3=ADo)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
web/src/hooks/useLogin.tsx | 0
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 web/src/hooks/useLogin.tsx
diff --git a/web/src/hooks/useLogin.tsx b/web/src/hooks/useLogin.tsx
new file mode 100644
index 00000000..e69de29b
--
GitLab
From 82c0200ac4d13851d230e84514d64b2d2a23e472 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Omar=20Luna=20Hern=C3=A1ndez?= <42101656@uaz.edu.mx>
Date: Fri, 12 Apr 2024 10:23:09 -0600
Subject: [PATCH 13/34] Se agregaron las librerias de react router y react hook
form
---
web/package-lock.json | 55 +++++++++++++++++++++++++++++++++++++++++++
web/package.json | 2 ++
2 files changed, 57 insertions(+)
diff --git a/web/package-lock.json b/web/package-lock.json
index 56b6f8ca..f63ba279 100644
--- a/web/package-lock.json
+++ b/web/package-lock.json
@@ -20,6 +20,8 @@
"axios": "^1.6.8",
"react": "^18.2.0",
"react-dom": "^18.2.0",
+ "react-hook-form": "^7.51.2",
+ "react-router-dom": "^6.22.3",
"react-scripts": "5.0.1",
"typescript": "^4.9.5",
"web-vitals": "^2.1.4"
@@ -3390,6 +3392,14 @@
}
}
},
+ "node_modules/@remix-run/router": {
+ "version": "1.15.3",
+ "resolved": "https://registry.npmjs.org/@remix-run/router/-/router-1.15.3.tgz",
+ "integrity": "sha512-Oy8rmScVrVxWZVOpEF57ovlnhpZ8CCPlnIIumVcV9nFdiSIrus99+Lw78ekXyGvVDlIsFJbSfmSovJUhCWYV3w==",
+ "engines": {
+ "node": ">=14.0.0"
+ }
+ },
"node_modules/@rollup/plugin-babel": {
"version": "5.3.1",
"resolved": "https://registry.npmjs.org/@rollup/plugin-babel/-/plugin-babel-5.3.1.tgz",
@@ -14885,6 +14895,21 @@
"resolved": "https://registry.npmjs.org/react-error-overlay/-/react-error-overlay-6.0.11.tgz",
"integrity": "sha512-/6UZ2qgEyH2aqzYZgQPxEnz33NJ2gNsnHA2o5+o4wW9bLM/JYQitNP9xPhsXwC08hMMovfGe/8retsdDsczPRg=="
},
+ "node_modules/react-hook-form": {
+ "version": "7.51.2",
+ "resolved": "https://registry.npmjs.org/react-hook-form/-/react-hook-form-7.51.2.tgz",
+ "integrity": "sha512-y++lwaWjtzDt/XNnyGDQy6goHskFualmDlf+jzEZvjvz6KWDf7EboL7pUvRCzPTJd0EOPpdekYaQLEvvG6m6HA==",
+ "engines": {
+ "node": ">=12.22.0"
+ },
+ "funding": {
+ "type": "opencollective",
+ "url": "https://opencollective.com/react-hook-form"
+ },
+ "peerDependencies": {
+ "react": "^16.8.0 || ^17 || ^18"
+ }
+ },
"node_modules/react-is": {
"version": "17.0.2",
"resolved": "https://registry.npmjs.org/react-is/-/react-is-17.0.2.tgz",
@@ -14898,6 +14923,36 @@
"node": ">=0.10.0"
}
},
+ "node_modules/react-router": {
+ "version": "6.22.3",
+ "resolved": "https://registry.npmjs.org/react-router/-/react-router-6.22.3.tgz",
+ "integrity": "sha512-dr2eb3Mj5zK2YISHK++foM9w4eBnO23eKnZEDs7c880P6oKbrjz/Svg9+nxqtHQK+oMW4OtjZca0RqPglXxguQ==",
+ "dependencies": {
+ "@remix-run/router": "1.15.3"
+ },
+ "engines": {
+ "node": ">=14.0.0"
+ },
+ "peerDependencies": {
+ "react": ">=16.8"
+ }
+ },
+ "node_modules/react-router-dom": {
+ "version": "6.22.3",
+ "resolved": "https://registry.npmjs.org/react-router-dom/-/react-router-dom-6.22.3.tgz",
+ "integrity": "sha512-7ZILI7HjcE+p31oQvwbokjk6OA/bnFxrhJ19n82Ex9Ph8fNAq+Hm/7KchpMGlTgWhUxRHMMCut+vEtNpWpowKw==",
+ "dependencies": {
+ "@remix-run/router": "1.15.3",
+ "react-router": "6.22.3"
+ },
+ "engines": {
+ "node": ">=14.0.0"
+ },
+ "peerDependencies": {
+ "react": ">=16.8",
+ "react-dom": ">=16.8"
+ }
+ },
"node_modules/react-scripts": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/react-scripts/-/react-scripts-5.0.1.tgz",
diff --git a/web/package.json b/web/package.json
index 0df47da9..51d196f7 100644
--- a/web/package.json
+++ b/web/package.json
@@ -15,6 +15,8 @@
"axios": "^1.6.8",
"react": "^18.2.0",
"react-dom": "^18.2.0",
+ "react-hook-form": "^7.51.2",
+ "react-router-dom": "^6.22.3",
"react-scripts": "5.0.1",
"typescript": "^4.9.5",
"web-vitals": "^2.1.4"
--
GitLab
From 568e805fb7c3e540f67d1b4e4b41b9fd2211b6c1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Omar=20Luna=20Hern=C3=A1ndez?= <42101656@uaz.edu.mx>
Date: Fri, 12 Apr 2024 10:27:41 -0600
Subject: [PATCH 14/34] Se crea la constante que contiene el url de la API
---
web/src/constants/api_url.ts | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/web/src/constants/api_url.ts b/web/src/constants/api_url.ts
index 43f27f05..b712d339 100644
--- a/web/src/constants/api_url.ts
+++ b/web/src/constants/api_url.ts
@@ -1 +1 @@
-export const APIUrl: String = "";
\ No newline at end of file
+export const APIUrl: String = "http://localhost:3005";
\ No newline at end of file
--
GitLab
From 17453fe94a4fe536d4b288fc4fd400b0d33bd76f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Omar=20Luna=20Hern=C3=A1ndez?= <42101656@uaz.edu.mx>
Date: Fri, 12 Apr 2024 10:28:22 -0600
Subject: [PATCH 15/34] Se agrega el campo de nombre del usuario logeado
---
web/src/data/models/prod/LoggedInUserModel.ts | 1 +
1 file changed, 1 insertion(+)
diff --git a/web/src/data/models/prod/LoggedInUserModel.ts b/web/src/data/models/prod/LoggedInUserModel.ts
index e69909a9..8f73d45b 100644
--- a/web/src/data/models/prod/LoggedInUserModel.ts
+++ b/web/src/data/models/prod/LoggedInUserModel.ts
@@ -1,5 +1,6 @@
export interface LoggedInUserModel {
email: string;
+ name: string;
role: string;
token: string;
}
\ No newline at end of file
--
GitLab
From 6c34ebf6b278e4dba3e485d0fbad9e88f38a89d6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Omar=20Luna=20Hern=C3=A1ndez?= <42101656@uaz.edu.mx>
Date: Fri, 12 Apr 2024 10:28:58 -0600
Subject: [PATCH 16/34] =?UTF-8?q?Se=20modifica=20la=20ruta=20de=20inicio?=
=?UTF-8?q?=20de=20sesi=C3=B3n=20en=20la=20API?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
web/src/data/datasources/prod/login_datasource.ts | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/web/src/data/datasources/prod/login_datasource.ts b/web/src/data/datasources/prod/login_datasource.ts
index 7c006413..c2d7f535 100644
--- a/web/src/data/datasources/prod/login_datasource.ts
+++ b/web/src/data/datasources/prod/login_datasource.ts
@@ -10,7 +10,7 @@ export class LoginDatasourceProd implements LoginDatasourceInf{
async getToken(form: LoginFormValues): Promise {
const {email, password} = form;
const {data} = await axios.post(
- APIUrl + "/api/auth/login",
+ APIUrl + "/admin/signin",
{
email: email,
password: password,
@@ -19,6 +19,7 @@ export class LoginDatasourceProd implements LoginDatasourceInf{
const user: LoggedInUser = {
user: {
email: data.email,
+ name: data.name,
role: data.role === UserRole.SUPERADMIN ? UserRole.SUPERADMIN : UserRole.ADMIN,
},
token: data.token,
--
GitLab
From 0fa871270ba7e7f671466d634a1b857b57829740 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Omar=20Luna=20Hern=C3=A1ndez?= <42101656@uaz.edu.mx>
Date: Fri, 12 Apr 2024 10:30:06 -0600
Subject: [PATCH 17/34] =?UTF-8?q?Se=20crea=20el=20archivo=20para=20revisar?=
=?UTF-8?q?,=20iniciar=20y=20cerrar=20la=20sesi=C3=B3n=20de=20usuario?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
web/src/context/auth_context.tsx | 68 ++++++++++++++++++++++++++++++++
1 file changed, 68 insertions(+)
create mode 100644 web/src/context/auth_context.tsx
diff --git a/web/src/context/auth_context.tsx b/web/src/context/auth_context.tsx
new file mode 100644
index 00000000..2648700d
--- /dev/null
+++ b/web/src/context/auth_context.tsx
@@ -0,0 +1,68 @@
+import { UserEntity } from "../infraestructure/entities/user";
+import axios from "axios";
+import { UserRole } from "../constants/roles";
+import { ReactNode, createContext, useContext, useEffect, useState } from "react";
+
+type AuthContextType = {
+ user: UserEntity | null;
+ login: (user: UserEntity, token: string) => void;
+ logout: () => void;
+};
+
+const AuthContext = createContext({
+ user: null,
+ login: () => {},
+ logout: () => {}
+});
+
+type AuthContextProviderProps = {
+ children: ReactNode;
+}
+
+export const AuthContextProvider = ({children} : AuthContextProviderProps) => {
+ const [user, setUser] = useState(null);
+ const saveSession = async (user: UserEntity, token: string) => {
+ setUser(user);
+ localStorage.setItem("token",token);
+ localStorage.setItem("user",JSON.stringify(user));
+ axios.defaults.headers.common["Authorization"] = `${token}`;
+ }
+
+ const deleteSession = async () => {
+ setUser(null);
+ localStorage.removeItem("token");
+ localStorage.removeItem("user");
+ axios.defaults.headers.common["Authorization"] = "";
+ }
+
+ const login = async (user: UserEntity, token: string) => {
+ await saveSession(user, token);
+ }
+
+ const logout = async () => {
+ await deleteSession();
+ }
+
+ const checkSession = async () => {
+ const token = localStorage.getItem("token");
+ const user = localStorage.getItem("user");
+ if(token && user){
+ const sessionUser = JSON.parse(user);
+ await saveSession({email: sessionUser.email as string, role: sessionUser.role as UserRole}, token);
+ }
+ }
+
+ useEffect(() => {
+ checkSession();
+ }, []);
+
+ const value = {user, login, logout};
+ return {children}
+};
+
+export const useAuth = () => {
+ if(AuthContext == undefined){
+ throw new Error("useAuth debe se usado dentro de un AuthContextProvider");
+ }
+ return useContext(AuthContext);
+};
\ No newline at end of file
--
GitLab
From 9487d853d196a3593001a945a0847c49c5fda2ee Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Omar=20Luna=20Hern=C3=A1ndez?= <42101656@uaz.edu.mx>
Date: Fri, 12 Apr 2024 10:30:42 -0600
Subject: [PATCH 18/34] =?UTF-8?q?Se=20crea=20el=20custom=20hook=20para=20i?=
=?UTF-8?q?niciar=20sesi=C3=B3n?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
web/src/hooks/useLogin.tsx | 41 ++++++++++++++++++++++++++++++++++++++
1 file changed, 41 insertions(+)
diff --git a/web/src/hooks/useLogin.tsx b/web/src/hooks/useLogin.tsx
index e69de29b..6a8ec169 100644
--- a/web/src/hooks/useLogin.tsx
+++ b/web/src/hooks/useLogin.tsx
@@ -0,0 +1,41 @@
+import { SubmitHandler, useForm } from "react-hook-form"
+import { LoginFormValues } from "../infraestructure/entities/login_form_values"
+import { LoginRepositoryProd } from "../data/repositories/prod/login_repository";
+import { LoginDatasourceProd } from "../data/datasources/prod/login_datasource";
+import { useEffect } from "react";
+import { useNavigate } from "react-router-dom";
+import { useAuth } from "../context/auth_context";
+const loginDatasource = new LoginDatasourceProd();
+const loginRepository = new LoginRepositoryProd(loginDatasource);
+
+export const useLogin = () => {
+ const {login, user} = useAuth();
+ const navigate = useNavigate();
+ const {
+ register,
+ handleSubmit,
+ setError,
+ formState: {errors},
+ } = useForm();
+
+ const onSubmit: SubmitHandler = (data: LoginFormValues) => {
+ const authenticate = async () => {
+ try{
+ const {user, token } = await loginRepository.getToken(data);
+ await login(user, token);
+ navigate("/");
+ }catch(error: any){
+
+ }
+ }
+ authenticate();
+ }
+
+ useEffect(() => {
+ if(user) {
+ navigate("/");
+ }
+ }, []);
+
+ return { register, handleSubmit, onSubmit, errors };
+}
\ No newline at end of file
--
GitLab
From 1068e87539c0fc4c30c72e30868745b337ddd30a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Omar=20Luna=20Hern=C3=A1ndez?= <42101656@uaz.edu.mx>
Date: Fri, 12 Apr 2024 10:31:28 -0600
Subject: [PATCH 19/34] =?UTF-8?q?Se=20modifica=20el=20archivo=20para=20inc?=
=?UTF-8?q?orporar=20el=20uso=20del=20hook=20de=20inicio=20de=20sesi=C3=B3?=
=?UTF-8?q?n?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
web/src/pages/login_page/login_page.tsx | 93 +++++++++++++------------
1 file changed, 50 insertions(+), 43 deletions(-)
diff --git a/web/src/pages/login_page/login_page.tsx b/web/src/pages/login_page/login_page.tsx
index cb9b0f6d..6cbc8ce2 100644
--- a/web/src/pages/login_page/login_page.tsx
+++ b/web/src/pages/login_page/login_page.tsx
@@ -2,52 +2,59 @@ import { usePasswoordVisibility } from "../../hooks/usePasswordVisibility"
import "./styles/styles.css"
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faEye , faEyeSlash} from "@fortawesome/free-solid-svg-icons";
+import { useLogin } from "../../hooks/useLogin";
export const LoginPage = () => {
- const {
- values,
- handleClickShowPassword,
- handleMouseDownPassword,
- } = usePasswoordVisibility();
+ const {
+ values,
+ handleClickShowPassword,
+ handleMouseDownPassword,
+ } = usePasswoordVisibility();
+ const {
+ register,
+ handleSubmit,
+ errors,
+ onSubmit
+ } = useLogin();
- return (
-