From fa35604753f57a2e975696405fada8b9053ce296 Mon Sep 17 00:00:00 2001 From: Jesus Fajardo Date: Mon, 1 Jul 2024 02:28:58 +0200 Subject: [PATCH] Adding general user service --- .github/workflows/deploy.yml | 2 ++ .../AuthenticateInterceptorMiddleware.js | 10 ++++---- frontend/src/App.css | 9 +++++++ .../card/PrincipalCardContainer.jsx | 24 +++++++++---------- frontend/src/components/forms/login/Login.jsx | 8 +++---- .../components/forms/register/Register.jsx | 8 +++---- frontend/src/pages/dashboard/Dashboard.jsx | 2 +- frontend/src/pages/validation/Validation.jsx | 4 +++- 8 files changed, 40 insertions(+), 27 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 1cfddd0..d2576b8 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -62,6 +62,8 @@ jobs: # Crear el archivo .env para el frontend sshpass -p "${SSH_PASSWORD}" ssh -o StrictHostKeyChecking=no "${SSH_USERNAME}@${SSH_HOST}" < /var/www/html/virtual-dojo/frontend/.env + echo "VITE_SERVICE_USR=${VITE_SERVICE_USR}" > /var/www/html/virtual-dojo/frontend/.env + echo "VITE_SERVICE_PASS=${VITE_SERVICE_PASS}" > /var/www/html/virtual-dojo/frontend/.env EOF # Copiar el backend al VPS diff --git a/backend/interceptor/AuthenticateInterceptorMiddleware.js b/backend/interceptor/AuthenticateInterceptorMiddleware.js index 3d12e1a..b646dc8 100644 --- a/backend/interceptor/AuthenticateInterceptorMiddleware.js +++ b/backend/interceptor/AuthenticateInterceptorMiddleware.js @@ -4,14 +4,14 @@ async function interceptorMiddleware(req, res, next) { const path = req.path.toLowerCase(); const excludedPaths = [ - /^\/api\/users\/login$/, - /^\/api\/users\/register$/, - /^\/api\/users\/validate$/, + '/api/users/login', + '/api/users/register', + '/api/users/validate' ]; - const isExcluded = excludedPaths.some((pattern) => pattern.test(path)); + console.log(!excludedPaths.includes(path)) - if (!isExcluded) { + if (!excludedPaths.includes(path)) { const authHeader = req.headers.authorization; if (!authHeader || !authHeader.startsWith('Basic ')) { return res.status(401).json({ message: 'Unauthorized' }); diff --git a/frontend/src/App.css b/frontend/src/App.css index bbe9e51..e739e53 100644 --- a/frontend/src/App.css +++ b/frontend/src/App.css @@ -51,4 +51,13 @@ body, html { .read-the-docs { color: #888; +} + +.background-image { + background-image: url('../public/Shotokan_Fondo.svg'); + background-size: contain; + background-repeat: no-repeat; + background-position: center; + height: 100%; + width: 100%; } \ No newline at end of file diff --git a/frontend/src/components/card/PrincipalCardContainer.jsx b/frontend/src/components/card/PrincipalCardContainer.jsx index 060b237..257aee0 100644 --- a/frontend/src/components/card/PrincipalCardContainer.jsx +++ b/frontend/src/components/card/PrincipalCardContainer.jsx @@ -1,20 +1,20 @@ -import PaymentCard from "../payment/PaymentCard.jsx"; -import MeetRegisterForm from "../forms/meet/MeetRegisterForm.jsx"; -import { hasSession, isAdmin, isUser } from "../../utils/session.jsx"; -import useFetchMeets from '../../hooks/useFetchMeets.js'; +import PaymentCard from "../payment/PaymentCard.jsx" +import MeetRegisterForm from "../forms/meet/MeetRegisterForm.jsx" +import { hasSession, isAdmin, isUser } from "../../utils/session.jsx" +import useFetchMeets from '../../hooks/useFetchMeets.js' export default function PrincipalCardContainer() { - const userSession = hasSession(); - const isUserValue = isUser(); - const isAdminValue = isAdmin(); - const { meets, error } = useFetchMeets(isUserValue, userSession); + const userSession = hasSession() + const isUserValue = isUser() + const isAdminValue = isAdmin() + const { meets, error } = useFetchMeets(isUserValue, userSession) if (error) { - return
Error: {error.message}
; + return
Error: {error.message}
} return ( - <> +
{isUserValue && (
{meets.map((meet) => ( @@ -31,6 +31,6 @@ export default function PrincipalCardContainer() {
)} - - ); + + ) } diff --git a/frontend/src/components/forms/login/Login.jsx b/frontend/src/components/forms/login/Login.jsx index 112d3a1..b70da08 100644 --- a/frontend/src/components/forms/login/Login.jsx +++ b/frontend/src/components/forms/login/Login.jsx @@ -4,7 +4,6 @@ import {InputText} from "primereact/inputtext" import {useState} from "react" import {useNavigate} from "react-router-dom" import {getApplicationDomain, startSession} from "../../../utils/session.jsx" -import background from "/Shotokan_Fondo.svg" export default function Login() { @@ -20,12 +19,14 @@ export default function Login() { function doLogin() { if (validateEmail(user)) { + const login = btoa(import.meta.env.VITE_SERVICE_USR + ':' + import.meta.env.VITE_SERVICE_PASS) const domain = getApplicationDomain() console.log("Domain: " + domain) fetch(domain + '/api/users/login', { method: 'POST', headers: { - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + 'Authorization': `Basic ${login}` }, body: JSON.stringify({ user: user, @@ -57,8 +58,7 @@ export default function Login() { } return ( -
+
+
+
diff --git a/frontend/src/pages/validation/Validation.jsx b/frontend/src/pages/validation/Validation.jsx index 0eeb015..d658768 100644 --- a/frontend/src/pages/validation/Validation.jsx +++ b/frontend/src/pages/validation/Validation.jsx @@ -10,10 +10,12 @@ export default function Validation() { useEffect(() => { const domain = getApplicationDomain() + const login = btoa(import.meta.env.VITE_SERVICE_USR + ':' + import.meta.env.VITE_SERVICE_PASS) fetch(`${domain}/api/users/validate`, { method: 'PATCH', headers: { - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + 'Authorization': `Basic ${login}` }, body: JSON.stringify({ userMail: mail }), })