Skip to content

Commit

Permalink
Adding general user service
Browse files Browse the repository at this point in the history
  • Loading branch information
basshamut committed Jul 1, 2024
1 parent 08dfcea commit fa35604
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 27 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ jobs:
# Crear el archivo .env para el frontend
sshpass -p "${SSH_PASSWORD}" ssh -o StrictHostKeyChecking=no "${SSH_USERNAME}@${SSH_HOST}" <<EOF
echo "VITE_API_URL=${VITE_API_URL}" > /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
Expand Down
10 changes: 5 additions & 5 deletions backend/interceptor/AuthenticateInterceptorMiddleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' });
Expand Down
9 changes: 9 additions & 0 deletions frontend/src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -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%;
}
24 changes: 12 additions & 12 deletions frontend/src/components/card/PrincipalCardContainer.jsx
Original file line number Diff line number Diff line change
@@ -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 <div>Error: {error.message}</div>;
return <div>Error: {error.message}</div>
}

return (
<>
<div className="card flex justify-content-center background-image">
{isUserValue && (
<div className="dashboard-container" style={{ textAlign: 'center' }}>
{meets.map((meet) => (
Expand All @@ -31,6 +31,6 @@ export default function PrincipalCardContainer() {
</div>
</div>
)}
</>
);
</div>
)
}
8 changes: 4 additions & 4 deletions frontend/src/components/forms/login/Login.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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,
Expand Down Expand Up @@ -57,8 +58,7 @@ export default function Login() {
}

return (
<div className="card flex justify-content-center"
style={{backgroundImage: `url(${background})`, backgroundSize: 'cover', height: '100vh'}}>
<div className="card flex justify-content-center background-image">
<Dialog
visible={visible}
modal
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/components/forms/register/Register.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {Button} from 'primereact/button'
import {Dialog} from 'primereact/dialog'
import {InputText} from "primereact/inputtext"
import {useState} from "react"
import background from "/Shotokan_Fondo.svg"
import {Calendar} from "primereact/calendar"
import {useNavigate} from "react-router-dom";
import {getApplicationDomain} from "../../../utils/session";
Expand Down Expand Up @@ -61,10 +60,12 @@ export default function Register() {

function doRegister() {
if (validateForm()) {
const login = btoa(import.meta.env.VITE_SERVICE_USR + ':' + import.meta.env.VITE_SERVICE_PASS)
fetch(domain + '/api/users/register', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
'Content-Type': 'application/json',
'Authorization': `Basic ${login}`
},
body: JSON.stringify({user, date, password})
})
Expand All @@ -84,8 +85,7 @@ export default function Register() {
}

return (
<div className="card flex justify-content-center"
style={{backgroundImage: `url(${background})`, backgroundSize: 'cover', height: '100vh'}}>
<div className="card flex justify-content-center background-image">
<Dialog
visible={visible}
modal
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/dashboard/Dashboard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default function Dashboard() {
}, [navigate])

return (
<div style={{ backgroundImage: `url(${background})`, backgroundSize: 'cover', height: '100vh' }}>
<div>
<Menubar model={menuItems} start={start} end={end}/>
<PrincipalCardContainer/>
<div>
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/pages/validation/Validation.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 }),
})
Expand Down

0 comments on commit fa35604

Please sign in to comment.