diff --git a/angular/RestClient/angular.json b/angular/RestClient/angular.json index 2fe5dbb241e8371e452ea965dee70c7249575f0c..32760665f49d122760236268ce4124bfaa0b6bde 100644 --- a/angular/RestClient/angular.json +++ b/angular/RestClient/angular.json @@ -32,12 +32,7 @@ "scripts": [ "node_modules/jquery/dist/jquery.min.js", "node_modules/bootstrap/dist/js/bootstrap.min.js" - ], - "server": "src/main.server.ts", - "prerender": true, - "ssr": { - "entry": "server.ts" - } + ] }, "configurations": { "production": { diff --git a/angular/RestClient/environments/environment.ts b/angular/RestClient/environments/environment.ts index a58d68bab83a0e466fcaebffe09f96707af74628..d82bc7fa8278b4fb12dd2db673f4b2c116cf8e3b 100644 --- a/angular/RestClient/environments/environment.ts +++ b/angular/RestClient/environments/environment.ts @@ -1,9 +1,9 @@ -const monolithUrl = 'http://localhost:8080'; +const monolithUrl = 'localhost:8080'; export const environment = { production: true, authAPI: 'http://localhost:8101', - userAPI: `http://${monolithUrl}`, - hotelAPI: `http://${monolithUrl}`, - bookingAPI: `http://${monolithUrl}`, + userAPI: `http://${monolithUrl}/users`, + hotelAPI: `http://${monolithUrl}/hotels`, + bookingAPI: `http://${monolithUrl}/bookings`, }; diff --git a/angular/RestClient/package-lock.json b/angular/RestClient/package-lock.json index a5d201bf11869266cc967b0e328660d5d8870bc7..af241069cc8acddc06a48c70b6d1dd25125a07ac 100644 --- a/angular/RestClient/package-lock.json +++ b/angular/RestClient/package-lock.json @@ -25,6 +25,7 @@ "bootstrap": "^3.4.0", "express": "^4.18.2", "jquery": "^3.4.1", + "jwt-decode": "^4.0.0", "rxjs": "~7.8.0", "tslib": "^2.3.0", "zone.js": "~0.14.10" @@ -5468,9 +5469,9 @@ "license": "ISC" }, "node_modules/bootstrap": { - "version": "3.4.0", - "resolved": "https://registry.npmjs.org/bootstrap/-/bootstrap-3.4.0.tgz", - "integrity": "sha512-F1yTDO9OHKH0xjl03DsOe8Nu1OWBIeAugGMhy3UTIYDdbbIPesQIhCEbj+HEr6wqlwweGAlP8F3OBC6kEuhFuw==", + "version": "3.4.1", + "resolved": "https://registry.npmjs.org/bootstrap/-/bootstrap-3.4.1.tgz", + "integrity": "sha512-yN5oZVmRCwe5aKwzRj6736nSmKDX7pLYwsXiCj/EYmo16hODaBiT4En5btW/jhBF/seV+XMx3aYwukYC3A49DA==", "license": "MIT", "engines": { "node": ">=6" @@ -6329,9 +6330,9 @@ } }, "node_modules/cross-spawn": { - "version": "7.0.3", - "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", - "integrity": "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==", + "version": "7.0.6", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz", + "integrity": "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==", "dev": true, "license": "MIT", "dependencies": { @@ -8555,9 +8556,9 @@ } }, "node_modules/jquery": { - "version": "3.4.1", - "resolved": "https://registry.npmjs.org/jquery/-/jquery-3.4.1.tgz", - "integrity": "sha512-36+AdBzCL+y6qjw5Tx7HgzeGCzC81MDDgaUP8ld2zhx58HdqXGoBd+tHdrBMiyjGQs0Hxs/MLZTu/eHNJJuWPw==", + "version": "3.7.1", + "resolved": "https://registry.npmjs.org/jquery/-/jquery-3.7.1.tgz", + "integrity": "sha512-m4avr8yL8kmFN8psrbFFFmB/If14iN5o9nw/NgnnM+kybDJpRsAynV2BsfpTYrTRysYUdADVD7CkUUizgkpLfg==", "license": "MIT" }, "node_modules/js-tokens": { @@ -8654,6 +8655,15 @@ ], "license": "MIT" }, + "node_modules/jwt-decode": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/jwt-decode/-/jwt-decode-4.0.0.tgz", + "integrity": "sha512-+KJGIyHgkGuIq3IEBNftfhW/LfWhXUIY6OmyVWjliu5KH1y0fw7VQ8YndE2O4qZdMSd9SqbnC8GOcZEy0Om7sA==", + "license": "MIT", + "engines": { + "node": ">=18" + } + }, "node_modules/karma": { "version": "6.4.4", "resolved": "https://registry.npmjs.org/karma/-/karma-6.4.4.tgz", diff --git a/angular/RestClient/package.json b/angular/RestClient/package.json index 262eacd1144f0eaab113dda4aad24eedab9ff958..a17778b07370cfdb71c9dcc5f6137b413ab929cf 100644 --- a/angular/RestClient/package.json +++ b/angular/RestClient/package.json @@ -28,6 +28,7 @@ "bootstrap": "^3.4.0", "express": "^4.18.2", "jquery": "^3.4.1", + "jwt-decode": "^4.0.0", "rxjs": "~7.8.0", "tslib": "^2.3.0", "zone.js": "~0.14.10" diff --git a/angular/RestClient/src/app/app.config.ts b/angular/RestClient/src/app/app.config.ts index 1f668ea1741efbdb605f6d418a9a93f53f1327fa..a7435caa914532ca9a3c5f085f6b02b3f36aa603 100644 --- a/angular/RestClient/src/app/app.config.ts +++ b/angular/RestClient/src/app/app.config.ts @@ -1,19 +1,22 @@ import { ApplicationConfig, provideZoneChangeDetection } from '@angular/core'; import { provideRouter } from '@angular/router'; import { routes } from './app.routes'; -import { provideHttpClient, withFetch } from '@angular/common/http'; +import { + provideHttpClient, + withFetch, + withInterceptors, +} from '@angular/common/http'; import { provideAnimationsAsync } from '@angular/platform-browser/animations/async'; import { ReactiveFormsModule } from '@angular/forms'; // Added import for ReactiveFormsModule import { provideNativeDateAdapter } from '@angular/material/core'; -import { provideClientHydration } from '@angular/platform-browser'; +import { authRequest } from './auth/auth.interceptor'; export const appConfig: ApplicationConfig = { providers: [ provideNativeDateAdapter(), provideZoneChangeDetection({ eventCoalescing: true }), provideRouter(routes), - provideClientHydration(), - provideHttpClient(withFetch()), + provideHttpClient(withFetch(), withInterceptors([authRequest])), provideAnimationsAsync(), ReactiveFormsModule, ], diff --git a/angular/RestClient/src/app/app.routes.ts b/angular/RestClient/src/app/app.routes.ts index 51aacbb7f9be2b3f9af5d3a7d4eaafb164c5ba26..5bb87ab2d992781d5fc76a032136e593c152cbe3 100644 --- a/angular/RestClient/src/app/app.routes.ts +++ b/angular/RestClient/src/app/app.routes.ts @@ -10,40 +10,109 @@ import { UserFormComponent } from './core/features/user/user-form/user-form.comp export const routes: Routes = [ { path: '', // Ruta principal - component: MainPageComponent, // Componente de la página principal + component: MainPageComponent, }, + // auth { - path: 'bookings/search', - component: BookingListComponent, + path: 'login', }, { - path: 'bookings/new', - component: BookingComponent, + path: 'register', }, + // Hoteles { - path: 'users/:id/bookings', - component: UserBookingListComponent, + path: 'hotels', // Ruta para la lista de hoteles }, { - path: 'hotels', - component: HotelListComponent, + path: 'hotels/register', // Registrar nuevo hotel }, { - path: 'hotels/new', - component: HotelRegisterComponent, + path: 'hotels/:id', // Hotel concreto }, { - path: 'hotels/:id', - component: HotelRegisterComponent, + path: 'hotels/:id/edit', // Modificar hotel }, + // Usuario { - path: 'users/:id', - component: UserFormComponent, + path: 'me', // Main }, { - path: 'register', - component: UserFormComponent, + path: 'me/edit', // Main + }, + // Usuario HOTEL admin + { + path: 'me/hotels', + }, + { + path: 'me/hotels/:id', + }, + { + path: 'me/hotels/:id/bookings', + }, + { + path: 'me/hotels/:id/rooms', + }, + { + path: 'me/hotels/:id/rooms/:id', + }, + { + path: 'me/hotels/:id/rooms/:id/bookings', }, + // Usuario Cliente + { + path: 'me/bookings', + }, + { + path: 'me/bookings/:id', + }, + { + path: 'me/bookings/new', + }, + // Administrador + { + path: 'admin', // Main + }, + { + path: 'admin/users', // Main + }, + { + path: 'admin/users/:id', // Main + }, + + // ! OTRO // NO MIRAR + + // { + // path: 'bookings/search', + // component: BookingListComponent, + // }, + // { + // path: 'bookings/new', + // component: BookingComponent, + // }, + // { + // path: 'users/:id/bookings', + // component: UserBookingListComponent, + // }, + // { + // path: 'hotels', + // component: HotelListComponent, + // }, + // { + // path: 'hotels/new', + // component: HotelRegisterComponent, + // }, + // { + // path: 'hotels/:id', + // component: HotelRegisterComponent, + // }, + // { + // path: 'users/:id', + // component: UserFormComponent, + // }, + // { + // path: 'register', + // component: UserFormComponent, + // }, { path: '**', redirectTo: '', diff --git a/angular/RestClient/src/app/auth/auth.interceptor.ts b/angular/RestClient/src/app/auth/auth.interceptor.ts new file mode 100644 index 0000000000000000000000000000000000000000..63a139b74505e95db8b5c3c88f508696e7ff73be --- /dev/null +++ b/angular/RestClient/src/app/auth/auth.interceptor.ts @@ -0,0 +1,32 @@ +import { HttpInterceptorFn } from '@angular/common/http'; +import { inject } from '@angular/core'; +import { LocalStorageService } from '../shared/local-storage.service'; + +const excluded = ['/login', '/register']; + +function isExcludedUrl(url: string) { + return excluded.some((excluded) => url.includes(excluded)); +} + +export const authRequest: HttpInterceptorFn = (req, next) => { + // Obtener el token desde localStorage (o cualquier otro mecanismo) + const storage = inject(LocalStorageService); // Obtener instancia del servicio + const token = storage.read<{ token: string }>('token'); + + if (isExcludedUrl(req.url) || !token) { + return next(req); // No modificar la solicitud + } + + // Clonar la solicitud y agregar el token al encabezado si existe + const authReq = token + ? req.clone({ + setHeaders: { + Authorization: `Bearer ${token.token}`, + 'Content-Type': 'application/json', + }, + }) + : req; + + // Pasar la solicitud modificada al siguiente manejador + return next(authReq); +}; diff --git a/angular/RestClient/src/app/core/features/bookings/booking-list/booking-list.component.ts b/angular/RestClient/src/app/core/features/bookings/booking-list/booking-list.component.ts index 5789a064b18d4aa50d9c6d9f163a87fb89bb7afc..6fb90798ea3a10e2dece5c0b0661e4a43ec393a4 100644 --- a/angular/RestClient/src/app/core/features/bookings/booking-list/booking-list.component.ts +++ b/angular/RestClient/src/app/core/features/bookings/booking-list/booking-list.component.ts @@ -7,7 +7,7 @@ import { import { FormsModule } from '@angular/forms'; import { MatInputModule } from '@angular/material/input'; import { MatSelectModule } from '@angular/material/select'; -import { Hotel, Room, RoomType, roomTypeArray } from '../../../../../types'; +import { Hotel, Room, RoomType, roomTypeArray } from '../../../../types'; import { Router } from '@angular/router'; import { MatCardModule } from '@angular/material/card'; import { MatChipsModule } from '@angular/material/chips'; diff --git a/angular/RestClient/src/app/core/features/bookings/booking/booking.component.ts b/angular/RestClient/src/app/core/features/bookings/booking/booking.component.ts index 9b99737e243b360d543e3ae57ff88d570a39a970..6ad8c379ae5b2e117c10a160eb07df12890f45fb 100644 --- a/angular/RestClient/src/app/core/features/bookings/booking/booking.component.ts +++ b/angular/RestClient/src/app/core/features/bookings/booking/booking.component.ts @@ -7,7 +7,7 @@ import { } from '@angular/forms'; import { ActivatedRoute, Router } from '@angular/router'; -import { Booking, User } from '../../../../../types'; +import { Booking, User } from '../../../../types'; import { LocalStorageService } from '../../../../shared/local-storage.service'; import { BookingClientService } from '../../../../shared/booking-client.service'; import { UserClientService } from '../../../../shared/user-client.service'; diff --git a/angular/RestClient/src/app/core/features/hotel/hotel-list/hotel-list.component.ts b/angular/RestClient/src/app/core/features/hotel/hotel-list/hotel-list.component.ts index 1bcaf64719ede78b63593bf0c504db6bb263488d..d951865749ebd766b23898f9428d593341cd73d6 100644 --- a/angular/RestClient/src/app/core/features/hotel/hotel-list/hotel-list.component.ts +++ b/angular/RestClient/src/app/core/features/hotel/hotel-list/hotel-list.component.ts @@ -1,6 +1,6 @@ import { Component } from '@angular/core'; import { RouterModule, Router } from '@angular/router'; -import { Hotel } from '../../../../../types'; +import { Hotel } from '../../../../types'; import { MatAccordion, MatExpansionPanel, diff --git a/angular/RestClient/src/app/core/features/hotel/hotel-register/hotel-register.component.ts b/angular/RestClient/src/app/core/features/hotel/hotel-register/hotel-register.component.ts index fad7415511aa5a15fc72df3af768f77454f0018f..9e2c2d433b6fa68621be16b30b7841e34ec8829f 100644 --- a/angular/RestClient/src/app/core/features/hotel/hotel-register/hotel-register.component.ts +++ b/angular/RestClient/src/app/core/features/hotel/hotel-register/hotel-register.component.ts @@ -13,7 +13,7 @@ import { MatFormFieldModule } from '@angular/material/form-field'; import { MatSelectModule } from '@angular/material/select'; import { MatSlideToggleModule } from '@angular/material/slide-toggle'; import { CommonModule } from '@angular/common'; -import { Address, Hotel, Room } from '../../../../../types'; +import { Address, Hotel, Room } from '../../../../types'; import { ActivatedRoute, Router } from '@angular/router'; import { HotelClientService } from '../../../../shared/hotel-client.service'; diff --git a/angular/RestClient/src/app/core/features/user/main-page/main-page.component.ts b/angular/RestClient/src/app/core/features/user/main-page/main-page.component.ts index c3506bbd37ebb81f35189e481d64e9875bac28b3..14b5a9d6c0e871d0e71b3d2154554f83e8ecc50d 100644 --- a/angular/RestClient/src/app/core/features/user/main-page/main-page.component.ts +++ b/angular/RestClient/src/app/core/features/user/main-page/main-page.component.ts @@ -1,5 +1,5 @@ import { Component, OnInit } from '@angular/core'; -import { Client, User, UserStateFilter } from '../../../../../types'; +import { Client, User, UserStateFilter } from '../../../../types'; import { FormsModule } from '@angular/forms'; import { CommonModule } from '@angular/common'; import { RouterModule } from '@angular/router'; diff --git a/angular/RestClient/src/app/core/features/user/user-booking-list/user-booking-list.component.ts b/angular/RestClient/src/app/core/features/user/user-booking-list/user-booking-list.component.ts index 677a18d81df11aef347c455b31460af659e49d31..878e6446e5bc8a162d67e880edd8633a5cbb3a94 100644 --- a/angular/RestClient/src/app/core/features/user/user-booking-list/user-booking-list.component.ts +++ b/angular/RestClient/src/app/core/features/user/user-booking-list/user-booking-list.component.ts @@ -1,6 +1,6 @@ import { Component } from '@angular/core'; -import { Booking, User } from '../../../../../types'; +import { Booking, User } from '../../../../types'; import { ActivatedRoute, RouterModule } from '@angular/router'; import { CommonModule } from '@angular/common'; import { FormsModule } from '@angular/forms'; diff --git a/angular/RestClient/src/app/core/navigation/navigation.component.css b/angular/RestClient/src/app/core/navigation/navigation.component.css index 200c21a3a62ba294324b6a77c75d043c2bd5574b..e3b01c1fac3de8d58e16185d24ac3791394e7b67 100644 --- a/angular/RestClient/src/app/core/navigation/navigation.component.css +++ b/angular/RestClient/src/app/core/navigation/navigation.component.css @@ -4,7 +4,7 @@ nav { padding: 1em; } -ul { +ul.nav { list-style: none; padding: 0; display: flex; @@ -14,15 +14,15 @@ li { margin-right: 20px; } -a, -a:visited { +a.nav-link, +a.nav-link:visited { color: white; text-decoration: none; transform: scale(1); transition: transform 0.3s ease; } -a:hover { +a.nav-link:hover { font-weight: bold; text-decoration: underline; color: yellow; @@ -34,6 +34,12 @@ a:hover { font-weight: bold; } +a.simple, +a.simple:visited { + color: white; + text-decoration: none; +} + @keyframes escalar { 0% { transform: scale(1); diff --git a/angular/RestClient/src/app/core/navigation/navigation.component.html b/angular/RestClient/src/app/core/navigation/navigation.component.html index 6ba3f139cd79d2fdfae6deb883b6a91e995ce6fd..94a99ba6dbf61fec024f7818dce9c8cc41115c6a 100644 --- a/angular/RestClient/src/app/core/navigation/navigation.component.html +++ b/angular/RestClient/src/app/core/navigation/navigation.component.html @@ -1,69 +1,71 @@ <nav> - <ul> - <li><a class="btn" [routerLink]="['/']">Home - Usuarios</a></li> + <ul class="nav"> + <li><a class="btn nav-link" [routerLink]="['/']">Home - Usuarios</a></li> <li> - <a class="btn" [routerLink]="['/hotels', 'new']">Registrar Hotel</a> + <a class="btn nav-link" [routerLink]="['/hotels', 'new']" + >Registrar Hotel</a + > </li> - <li><a class="btn" [routerLink]="['/hotels']">Hoteles</a></li> + <li><a class="btn nav-link" [routerLink]="['/hotels']">Hoteles</a></li> <li> - <a class="btn" [routerLink]="['/bookings', 'search']">Nueva Reserva</a> + <a class="btn nav-link" [routerLink]="['/bookings', 'search']" + >Nueva Reserva</a + > </li> - <li class="ml-auto"> + <!-- Solucionar que no va --> + <!-- <li class="ml-auto"> --> + <li style="margin-left: auto"> @if (isLogged){ <!-- Dropdown para usuario registrado --> - <div class="relative ml-6"> + + <div class="btn bg-blue-500 text-white rounded hover:bg-blue-600"> + <!-- mat-icon-button --> <button - (click)="toggleDropdown()" - class="flex items-center space-x-2 p-2 bg-blue-500 text-white rounded hover:bg-blue-600 focus:outline-none" + [matMenuTriggerFor]="sessionOptions" + class="flex items-center gap-3" > - <span>{{ userName }}</span> - <svg - xmlns="http://www.w3.org/2000/svg" - class="h-5 w-5" - viewBox="0 0 20 20" - fill="currentColor" - > - <path - fill-rule="evenodd" - d="M5.23 7.21a.75.75 0 011.06.02L10 10.94l3.71-3.71a.75.75 0 111.06 1.06l-4 4a.75.75 0 01-1.06 0l-4-4a.75.75 0 01.02-1.06z" - clip-rule="evenodd" - /> - </svg> - </button> + <span class="text-4xl">{{ user.name }}</span> - <!-- Menú desplegable --> - @if (dropdownOpen) { - <div - class="absolute right-0 mt-2 w-48 bg-slate-700 border border-gray-500 rounded shadow-lg" - > - <ul> - <li> - <a - class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100" - [routerLink]="['/bookings']" - > - Mis Reservas - </a> - </li> - <li> - <a - class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100" - > - <!-- (click)="logout()" --> - Cerrar Sesión - </a> - </li> - </ul> - </div> - } + @if (trigger?.menuOpen) { + <mat-icon class="text-4xl">arrow_drop_up</mat-icon> + }@else { + <mat-icon class="text-4xl">arrow_drop_down</mat-icon> + } + </button> </div> + <mat-menu #sessionOptions="matMenu" xPosition="before"> + @for (section of sections; track section.id) { @if (section.link) { + <a [routerLink]="section.link" class="simple"> + <button mat-menu-item> + <mat-icon>{{ section.icon }}</mat-icon> + <span class="text-2xl">{{ section.text }}</span> + </button> + </a> + } @else { + <button mat-menu-item> + <mat-icon>{{ section.icon }}</mat-icon> + <span class="text-2xl">{{ section.text }}</span> + </button> + } } + <button mat-menu-item (click)="logout()"> + <mat-icon>logout</mat-icon> + <span class="text-2xl">Cerrar sesión</span> + </button> + </mat-menu> } @else { - <a - class="btn bg-blue-500 text-white ml-6 hover:bg-blue-600" - [routerLink]="['/login']" - >Login</a + <div + class="btn bg-blue-500 text-white hover:bg-blue-600 ml-auto" + (click)="login()" > + <!-- <a class="simple" [routerLink]="['/login']"> --> + <a class="simple"> + <button class="flex items-center gap-3"> + <span class="text-4xl">Login</span> + <mat-icon>login</mat-icon> + </button> + </a> + </div> } </li> </ul> diff --git a/angular/RestClient/src/app/core/navigation/navigation.component.ts b/angular/RestClient/src/app/core/navigation/navigation.component.ts index 69efb6ad2307d3ac4f6865450372e280ec639519..1e7a72d5eb50276981b4f00a3950847105e06f0d 100644 --- a/angular/RestClient/src/app/core/navigation/navigation.component.ts +++ b/angular/RestClient/src/app/core/navigation/navigation.component.ts @@ -1,31 +1,122 @@ -import { Component } from '@angular/core'; -import { Router, RouterModule } from '@angular/router'; +import { OnInit, Component, ViewChild } from '@angular/core'; +import { RouterModule } from '@angular/router'; +import { MatButtonModule } from '@angular/material/button'; +import { MatMenuModule, MatMenuTrigger } from '@angular/material/menu'; +import { MatIconModule } from '@angular/material/icon'; +import { User, UserRol } from '../../types'; +import { AuthInstance, SessionService } from '../../shared/session.service'; +import { UserClientService } from '../../shared/user-client.service'; import { AuthClientService } from '../../shared/auth-client.service'; + +var comp_id = 0; + +export function genId() { + const comp = 'navigation'; + return `${comp}-${comp_id++}`; +} + +interface Section { + id: string; + icon: string; + text: string; + link: string; + allowRoles?: UserRol[]; +} + @Component({ selector: 'app-navigation', standalone: true, - imports: [RouterModule], + imports: [RouterModule, MatButtonModule, MatMenuModule, MatIconModule], templateUrl: './navigation.component.html', styleUrl: './navigation.component.css', }) -export class NavigationComponent { - isLogged = true; - userName = 'User'; - dropdownOpen = false; +export class NavigationComponent implements OnInit { + @ViewChild(MatMenuTrigger) + trigger?: MatMenuTrigger; + isLogged = false; + user: AuthInstance = { + id: 0, + name: '', + email: '', + rol: 'CLIENT', + }; + sections: Section[] = []; + + constructor( + private sessionService: SessionService, + private auth: AuthClientService + ) {} + + ngOnInit() { + this.loadUser(); + } - constructor(private authClient: AuthClientService) {} + loadUser() { + const isLogged = this.sessionService.isValid(); + if (isLogged) { + this.user = this.sessionService.getSession(); + console.log({ user: this.user }); + this.sections = this.genSections(); + } + this.isLogged = isLogged; + } toggleDropdown() { - this.dropdownOpen = !this.dropdownOpen; - this.authClient.login('migudel@dev.com', 'NQSASorry').subscribe({ - next: (response) => { - console.log(response); - alert('OKEY! You are logged'); - }, - error: (error) => { - console.error(error); - alert('Error! You are not logged'); + if (this.trigger) { + if (this.trigger.menuOpen) this.trigger.closeMenu(); + else this.trigger.openMenu(); + } + } + + schemaSections: Section[] = [ + { + id: genId(), + icon: 'person', + text: 'Información personal', + link: '/me', + }, + { + id: genId(), + icon: 'calendar_today', + text: 'Reservas', + allowRoles: ['CLIENT'], + link: '/users/1/bookings', + // link: '/bookings', + }, + { + id: genId(), + icon: 'hotel', + text: 'Hoteles', + allowRoles: ['HOTEL_ADMIN'], + link: '/hotels', + }, + ]; + + genSections() { + return this.schemaSections.filter( + (section) => + this.user.rol === 'ADMIN' || // Es administrador del sistema + !section.allowRoles || + section.allowRoles.length === 0 || // No tiene limitación + section.allowRoles.includes(this.user.rol) // El rol del usuario es aceptado + ); + } + + login() { + const email = 'client@dev.com'; + this.auth.login(email, 'NQSASorry').subscribe({ + next: (data: any) => { + console.log(email, data); + this.sessionService.login(data); + this.loadUser(); }, }); } + + logout() { + if (confirm('You are trying to logout')) { + this.sessionService.logout(); + this.loadUser(); + } + } } diff --git a/angular/RestClient/src/app/shared/booking-client.service.ts b/angular/RestClient/src/app/shared/booking-client.service.ts index f05be5efb55bdfcc544d25a302626400c5cd2835..3e44163b0944263f937334320090ec3ee2ef786e 100644 --- a/angular/RestClient/src/app/shared/booking-client.service.ts +++ b/angular/RestClient/src/app/shared/booking-client.service.ts @@ -2,7 +2,7 @@ import { Injectable } from '@angular/core'; import { HttpClient, HttpHeaders } from '@angular/common/http'; import { Observable } from 'rxjs'; import { environment } from '../../../environments/environment'; -import { Booking } from '../../types/Booking'; // Ajusta la ruta a tu modelo Booking +import { Booking } from '../types/Booking'; // Ajusta la ruta a tu modelo Booking @Injectable({ providedIn: 'root', diff --git a/angular/RestClient/src/app/shared/hotel-client.service.ts b/angular/RestClient/src/app/shared/hotel-client.service.ts index f38bb2adf2c40e48cafe684ec7dcb12c79ddb524..87756a392895ecc95b745101b7accaef0e20a3e1 100644 --- a/angular/RestClient/src/app/shared/hotel-client.service.ts +++ b/angular/RestClient/src/app/shared/hotel-client.service.ts @@ -1,7 +1,7 @@ import { Injectable } from '@angular/core'; import { environment } from '../../../environments/environment'; import { HttpClient } from '@angular/common/http'; -import { Hotel, Room } from '../../types'; +import { Hotel, Room } from '../types'; @Injectable({ providedIn: 'root', diff --git a/angular/RestClient/src/app/shared/local-storage.service.ts b/angular/RestClient/src/app/shared/local-storage.service.ts index e1526f8aaa1b56903668de93697f4a2b072d97ab..dc328655c80df4c87132a25305026eb3f00d1fec 100644 --- a/angular/RestClient/src/app/shared/local-storage.service.ts +++ b/angular/RestClient/src/app/shared/local-storage.service.ts @@ -1,32 +1,21 @@ -import { isPlatformBrowser } from '@angular/common'; -import { Inject, Injectable, PLATFORM_ID } from '@angular/core'; +import { Injectable } from '@angular/core'; @Injectable({ providedIn: 'root', }) export class LocalStorageService { - // isBrowser: boolean; - - // constructor(@Inject(PLATFORM_ID) private platformId: Object) { - // this.isBrowser = isPlatformBrowser(this.platformId); - // } - - save(key: string, value: any) { - // if (!this.isBrowser) return; - localStorage.setItem(key, JSON.stringify(value)); + save(key: string, value: object) { + const content = JSON.stringify(value); + localStorage.setItem(key, content); } read<T>(key: string) { - // if (!this.isBrowser) return null; - const json = localStorage.getItem(key); const ret = json ? (JSON.parse(json) as T) : null; return ret; } consume<T>(key: string) { - // if (!this.isBrowser) return null; - const value = this.read<T>(key); if (value !== null) { this.remove(key); @@ -35,8 +24,6 @@ export class LocalStorageService { } remove(key: string) { - // if (!this.isBrowser) return; - localStorage.removeItem(key); } } diff --git a/angular/RestClient/src/app/shared/session.service.spec.ts b/angular/RestClient/src/app/shared/session.service.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..4238e142b07aad273072a64a6df73c7960707501 --- /dev/null +++ b/angular/RestClient/src/app/shared/session.service.spec.ts @@ -0,0 +1,16 @@ +import { TestBed } from '@angular/core/testing'; + +import { SessionService } from './session.service'; + +describe('SessionService', () => { + let service: SessionService; + + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(SessionService); + }); + + it('should be created', () => { + expect(service).toBeTruthy(); + }); +}); diff --git a/angular/RestClient/src/app/shared/session.service.ts b/angular/RestClient/src/app/shared/session.service.ts new file mode 100644 index 0000000000000000000000000000000000000000..82e9daaceed948aa6ed973b710f704421f5b30f5 --- /dev/null +++ b/angular/RestClient/src/app/shared/session.service.ts @@ -0,0 +1,58 @@ +import { Injectable } from '@angular/core'; +import { LocalStorageService } from './local-storage.service'; +import { UserRol } from '../types'; + +import { jwtDecode } from 'jwt-decode'; + +export interface AuthInstance { + id: number; + name: string; + email: string; + rol: UserRol; +} + +interface PersistenToken { + token: string; +} + +@Injectable({ + providedIn: 'root', +}) +export class SessionService { + constructor(private storage: LocalStorageService) {} + + private tokenKey = 'token'; + + login(session: PersistenToken) { + this.storage.save(this.tokenKey, session); + } + + logout() { + this.storage.remove(this.tokenKey); + } + + getToken() { + const savedToken = this.storage.read<PersistenToken>(this.tokenKey); + if (!savedToken) throw new Error('No session'); + return savedToken.token; + } + + getSession() { + const token = this.getToken(); + const r = jwtDecode<{ user: AuthInstance }>(token); + return r.user; + } + + isLogged() { + return !!this.storage.read<PersistenToken>(this.tokenKey); + } + + isValid() { + console.warn({ log: this.isLogged() }); + if (!this.isLogged()) return false; + const token = this.getToken(); + const r = jwtDecode(token); + // Validate if the token have been expired or not + return r.exp! > Math.floor(Date.now() / 1000); + } +} diff --git a/angular/RestClient/src/app/shared/user-client.service.ts b/angular/RestClient/src/app/shared/user-client.service.ts index 7383a72b9aefd100bc87ebba38ef287e27eff3dd..2b2592e00c49b292df6799a76b4a6feb95b48380 100644 --- a/angular/RestClient/src/app/shared/user-client.service.ts +++ b/angular/RestClient/src/app/shared/user-client.service.ts @@ -1,7 +1,7 @@ import { HttpClient } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { environment } from '../../../environments/environment'; -import { Client, User, UserState } from '../../types'; +import { Client, User, UserState } from '../types'; @Injectable({ providedIn: 'root', diff --git a/angular/RestClient/src/types/Address.d.ts b/angular/RestClient/src/app/types/Address.d.ts similarity index 100% rename from angular/RestClient/src/types/Address.d.ts rename to angular/RestClient/src/app/types/Address.d.ts diff --git a/angular/RestClient/src/types/Booking.d.ts b/angular/RestClient/src/app/types/Booking.d.ts similarity index 100% rename from angular/RestClient/src/types/Booking.d.ts rename to angular/RestClient/src/app/types/Booking.d.ts diff --git a/angular/RestClient/src/types/Hotel.d.ts b/angular/RestClient/src/app/types/Hotel.d.ts similarity index 100% rename from angular/RestClient/src/types/Hotel.d.ts rename to angular/RestClient/src/app/types/Hotel.d.ts diff --git a/angular/RestClient/src/types/Room.d.ts b/angular/RestClient/src/app/types/Room.d.ts similarity index 100% rename from angular/RestClient/src/types/Room.d.ts rename to angular/RestClient/src/app/types/Room.d.ts diff --git a/angular/RestClient/src/types/User.d.ts b/angular/RestClient/src/app/types/User.d.ts similarity index 100% rename from angular/RestClient/src/types/User.d.ts rename to angular/RestClient/src/app/types/User.d.ts diff --git a/angular/RestClient/src/types/index.ts b/angular/RestClient/src/app/types/index.ts similarity index 100% rename from angular/RestClient/src/types/index.ts rename to angular/RestClient/src/app/types/index.ts diff --git a/angular/RestClient/src/mocks/users.ts b/angular/RestClient/src/mocks/users.ts index ffdf8f23af07980429bbb8cbf6a1e351bb555958..f6fafe67e13993f0e5b1a48c5443d43f6d3c2c3d 100644 --- a/angular/RestClient/src/mocks/users.ts +++ b/angular/RestClient/src/mocks/users.ts @@ -1,4 +1,4 @@ -import { Client, User } from '../types'; +import { Client, User } from '../app/types'; export const users: Client[] = [ { diff --git a/java/roomBooking/src/main/java/com/uva/monolith/config/SecurityConfig.java b/java/roomBooking/src/main/java/com/uva/monolith/config/SecurityConfig.java index 75a466413e524c25806035c406f8987ca4353cfe..5cc2695222079be62bcb16f493158c0452920569 100644 --- a/java/roomBooking/src/main/java/com/uva/monolith/config/SecurityConfig.java +++ b/java/roomBooking/src/main/java/com/uva/monolith/config/SecurityConfig.java @@ -2,6 +2,7 @@ package com.uva.monolith.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.http.HttpMethod; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.web.SecurityFilterChain; @@ -24,6 +25,8 @@ public class SecurityConfig { public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { http.csrf(csrf -> csrf.disable()) .authorizeHttpRequests(authorize -> authorize + // Permitir OPTIONS sin autenticación + .requestMatchers(HttpMethod.OPTIONS, "/**").permitAll() // Acceso restringido a usuarios y administradores .requestMatchers("users", "users/**") .hasAnyRole(UserRol.ADMIN.toString(), UserRol.CLIENT.toString()) diff --git a/java/roomBooking/src/main/java/com/uva/monolith/filter/JwtAuthenticationFilter.java b/java/roomBooking/src/main/java/com/uva/monolith/filter/JwtAuthenticationFilter.java index 9a0b6f46b8b40d9088a4e265018173278b150db3..9b31d1a0e80f529075ef20bc4e9a955cfa825d30 100644 --- a/java/roomBooking/src/main/java/com/uva/monolith/filter/JwtAuthenticationFilter.java +++ b/java/roomBooking/src/main/java/com/uva/monolith/filter/JwtAuthenticationFilter.java @@ -25,6 +25,7 @@ import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.Filter; import java.io.IOException; import java.security.Key; +import java.time.LocalDateTime; import java.util.Collections; import java.util.Date; @@ -63,15 +64,15 @@ public class JwtAuthenticationFilter implements Filter { // Verifica que el token no esté expirado return claims.getExpiration().after(new Date()); } catch (ExpiredJwtException e) { - System.out.println("Token expirado: " + e.getMessage()); + System.out.println("[" + LocalDateTime.now().toString() + "] Token expirado: " + e.getMessage()); } catch (UnsupportedJwtException e) { - System.out.println("Token no soportado: " + e.getMessage()); + System.out.println("[" + LocalDateTime.now().toString() + "] Token no soportado: " + e.getMessage()); } catch (MalformedJwtException e) { - System.out.println("Token malformado: " + e.getMessage()); + System.out.println("[" + LocalDateTime.now().toString() + "] Token malformado: " + e.getMessage()); } catch (SignatureException e) { - System.out.println("Firma inválida: " + e.getMessage()); + System.out.println("[" + LocalDateTime.now().toString() + "] Firma inválida: " + e.getMessage()); } catch (IllegalArgumentException e) { - System.out.println("Token vacío o nulo: " + e.getMessage()); + System.out.println("[" + LocalDateTime.now().toString() + "] Token vacío o nulo: " + e.getMessage()); } return false; // Si ocurre cualquier excepción, el token es inválido @@ -96,6 +97,8 @@ public class JwtAuthenticationFilter implements Filter { HttpServletRequest httpRequest = (HttpServletRequest) request; String token = getTokenFromRequest(httpRequest); + System.out.println("[" + LocalDateTime.now().toString() + "] TOKEN " + token); + if (validateToken(token)) { String email = getEmailFromToken(token); diff --git a/java/roomBooking/src/main/java/com/uva/monolith/services/users/models/AuthResponse.java b/java/roomBooking/src/main/java/com/uva/monolith/services/users/models/AuthResponse.java new file mode 100644 index 0000000000000000000000000000000000000000..8f334813beee8cb95caa275c66e46c9c539f2bd5 --- /dev/null +++ b/java/roomBooking/src/main/java/com/uva/monolith/services/users/models/AuthResponse.java @@ -0,0 +1,51 @@ +package com.uva.monolith.services.users.models; + +public class AuthResponse { + + private int id; + private String username; + private String email; + private String password; + private UserRol rol; + + public int getId() { + return this.id; + } + + public void setId(int id) { + this.id = id; + } + + public String getUsername() { + return this.username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getEmail() { + return this.email; + } + + public void setEmail(String email) { + this.email = email; + } + + public String getPassword() { + return this.password; + } + + public void setPassword(String password) { + this.password = password; + } + + public UserRol getRol() { + return this.rol; + } + + public void setRol(UserRol rol) { + this.rol = rol; + } + +} diff --git a/java/roomBooking/src/main/java/com/uva/monolith/services/users/services/UserService.java b/java/roomBooking/src/main/java/com/uva/monolith/services/users/services/UserService.java index d25e835e30591cd78279b766fa4c81c098bba630..193d736853b1f0d84ff86a4b24cfd0f8db52172d 100644 --- a/java/roomBooking/src/main/java/com/uva/monolith/services/users/services/UserService.java +++ b/java/roomBooking/src/main/java/com/uva/monolith/services/users/services/UserService.java @@ -4,11 +4,13 @@ import java.time.LocalDate; import java.util.List; import java.util.Optional; +import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; import org.springframework.web.client.HttpClientErrorException; +import com.uva.monolith.services.users.models.AuthResponse; import com.uva.monolith.services.users.models.Client; import com.uva.monolith.services.users.models.User; import com.uva.monolith.services.users.models.UserStatus; @@ -36,8 +38,12 @@ public class UserService { return assertUser(userRepository.findById(id)); } - public User getUserByEmail(String email) { - return assertUser(userRepository.findByEmail(email)); + public AuthResponse getUserByEmail(String email) { + User u = assertUser(userRepository.findByEmail(email)); + AuthResponse auth = new AuthResponse(); + BeanUtils.copyProperties(u, auth); + auth.setUsername(u.getName()); + return auth; } public User addUser(User user) { diff --git a/java/services/auth/pom.xml b/java/services/auth/pom.xml index ab9de31eb2707016bf0997d538e82b1ac3e525d5..19b9923d7ad2a8b056e02681630234471de0a9d3 100644 --- a/java/services/auth/pom.xml +++ b/java/services/auth/pom.xml @@ -49,10 +49,12 @@ <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-security</artifactId> - </dependency> + <!-- https://mvnrepository.com/artifact/org.springframework.security/spring-security-core --> + <dependency> + <groupId>org.springframework.security</groupId> + <artifactId>spring-security-core</artifactId> + <version>6.4.1</version> + </dependency> <dependency> <groupId>io.jsonwebtoken</groupId> <artifactId>jjwt-api</artifactId> diff --git a/java/services/auth/src/main/java/com/uva/authentication/api/UserAPI.java b/java/services/auth/src/main/java/com/uva/authentication/api/UserAPI.java index 7df746bdab25e63aff5f895baa820564330638a2..d4aa44728a593f54275339d99c9e603b20b802e9 100644 --- a/java/services/auth/src/main/java/com/uva/authentication/api/UserAPI.java +++ b/java/services/auth/src/main/java/com/uva/authentication/api/UserAPI.java @@ -11,8 +11,8 @@ import org.springframework.web.client.HttpClientErrorException; import org.springframework.web.client.RestTemplate; import com.uva.authentication.models.RegisterRequest; -import com.uva.authentication.models.User; -import com.uva.authentication.models.UserRol; +import com.uva.authentication.models.remote.User; +import com.uva.authentication.models.remote.UserRol; import com.uva.authentication.utils.JwtUtil; @Component diff --git a/java/services/auth/src/main/java/com/uva/authentication/config/SecurityConfig.java b/java/services/auth/src/main/java/com/uva/authentication/config/SecurityConfig.java deleted file mode 100644 index 99715b0c854bd997e35fdde1e3cf76afa28f4f9e..0000000000000000000000000000000000000000 --- a/java/services/auth/src/main/java/com/uva/authentication/config/SecurityConfig.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.uva.authentication.config; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.security.config.annotation.web.builders.HttpSecurity; -import org.springframework.security.web.SecurityFilterChain; - -@Configuration -public class SecurityConfig { - - @Bean - public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { - http.csrf(crsf -> crsf.disable()) - .authorizeHttpRequests(auth -> auth.anyRequest().permitAll()); - return http.build(); - } -} diff --git a/java/services/auth/src/main/java/com/uva/authentication/controllers/AuthController.java b/java/services/auth/src/main/java/com/uva/authentication/controllers/AuthController.java index 72e4eab78ea1901308e0f9791922891aa96004c1..23625a6e7824cadda471d847ecede0b94cb565da 100644 --- a/java/services/auth/src/main/java/com/uva/authentication/controllers/AuthController.java +++ b/java/services/auth/src/main/java/com/uva/authentication/controllers/AuthController.java @@ -16,10 +16,10 @@ public class AuthController { private AuthService authService; @PostMapping("/login") - public ResponseEntity<String> login(@RequestBody LoginRequest loginRequest) { + public ResponseEntity<?> login(@RequestBody LoginRequest loginRequest) { try { String token = authService.login(loginRequest); - return ResponseEntity.ok(token); + return ResponseEntity.ok(new JwtAuthResponse(token)); } catch (HttpClientErrorException e) { if (e.getStatusCode() == HttpStatus.FORBIDDEN) { return new ResponseEntity<String>(e.getMessage(), HttpStatus.FORBIDDEN); @@ -29,7 +29,7 @@ public class AuthController { } @PostMapping("/register") - public ResponseEntity<String> register(@RequestBody RegisterRequest registerRequest) { + public ResponseEntity<?> register(@RequestBody RegisterRequest registerRequest) { try { LoginRequest loginRequest = new LoginRequest(); loginRequest.setEmail(registerRequest.getEmail()); diff --git a/java/services/auth/src/main/java/com/uva/authentication/models/AuthResponse.java b/java/services/auth/src/main/java/com/uva/authentication/models/AuthResponse.java index 0ec6ee5d2d5a9aa6b61a09d8e3a8550ba6a9b019..e943a69108d5da38d4956509242935a6e4eb659e 100644 --- a/java/services/auth/src/main/java/com/uva/authentication/models/AuthResponse.java +++ b/java/services/auth/src/main/java/com/uva/authentication/models/AuthResponse.java @@ -1,14 +1,53 @@ package com.uva.authentication.models; +import com.uva.authentication.models.remote.UserRol; + public class AuthResponse { - private String token; - public AuthResponse(String token) { - this.token = token; + private int id; + private String username; + private String email; + private String password; + private UserRol rol; + + public int getId() { + return this.id; + } + + public void setId(int id) { + this.id = id; + } + + public String getUsername() { + return this.username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getEmail() { + return this.email; } - // Getter - public String getToken() { - return token; + public void setEmail(String email) { + this.email = email; } + + public String getPassword() { + return this.password; + } + + public void setPassword(String password) { + this.password = password; + } + + public UserRol getRol() { + return this.rol; + } + + public void setRol(UserRol rol) { + this.rol = rol; + } + } diff --git a/java/services/auth/src/main/java/com/uva/authentication/models/JwtAuthResponse.java b/java/services/auth/src/main/java/com/uva/authentication/models/JwtAuthResponse.java new file mode 100644 index 0000000000000000000000000000000000000000..a9566954c35ce71864881e320843e270a998b9da --- /dev/null +++ b/java/services/auth/src/main/java/com/uva/authentication/models/JwtAuthResponse.java @@ -0,0 +1,14 @@ +package com.uva.authentication.models; + +public class JwtAuthResponse { + private String token; + + public JwtAuthResponse(String token) { + this.token = token; + } + + // Getter + public String getToken() { + return token; + } +} diff --git a/java/services/auth/src/main/java/com/uva/authentication/models/RegisterRequest.java b/java/services/auth/src/main/java/com/uva/authentication/models/RegisterRequest.java index d15ccb3726a4a8b323b894348b55d267feb8ed40..b3c98e8e71e7ff14f2bb90c9f1b4e0cecf7e8ae7 100644 --- a/java/services/auth/src/main/java/com/uva/authentication/models/RegisterRequest.java +++ b/java/services/auth/src/main/java/com/uva/authentication/models/RegisterRequest.java @@ -1,5 +1,7 @@ package com.uva.authentication.models; +import com.uva.authentication.models.remote.UserRol; + public class RegisterRequest extends LoginRequest { private UserRol rol; private String name; diff --git a/java/services/auth/src/main/java/com/uva/authentication/models/Client.java b/java/services/auth/src/main/java/com/uva/authentication/models/remote/Client.java similarity index 82% rename from java/services/auth/src/main/java/com/uva/authentication/models/Client.java rename to java/services/auth/src/main/java/com/uva/authentication/models/remote/Client.java index 896fe932aed9f3bcccc0cc783a9d230f5879a597..69bb23c34c2f3c47f53365fab16abfda76871c60 100644 --- a/java/services/auth/src/main/java/com/uva/authentication/models/Client.java +++ b/java/services/auth/src/main/java/com/uva/authentication/models/remote/Client.java @@ -1,18 +1,10 @@ -package com.uva.authentication.models; - -import java.util.ArrayList; -import java.util.List; - -import com.fasterxml.jackson.annotation.JsonIgnore; +package com.uva.authentication.models.remote; import jakarta.persistence.Basic; -import jakarta.persistence.CascadeType; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.EnumType; import jakarta.persistence.Enumerated; -import jakarta.persistence.FetchType; -import jakarta.persistence.OneToMany; import jakarta.persistence.Table; @Entity diff --git a/java/services/auth/src/main/java/com/uva/authentication/models/HotelManager.java b/java/services/auth/src/main/java/com/uva/authentication/models/remote/HotelManager.java similarity index 75% rename from java/services/auth/src/main/java/com/uva/authentication/models/HotelManager.java rename to java/services/auth/src/main/java/com/uva/authentication/models/remote/HotelManager.java index 5cc75cb14d6402371cd5e61c82b2c50018a9981e..584a33677a7a846d2896dc300c811b9759c9168f 100644 --- a/java/services/auth/src/main/java/com/uva/authentication/models/HotelManager.java +++ b/java/services/auth/src/main/java/com/uva/authentication/models/remote/HotelManager.java @@ -1,13 +1,6 @@ -package com.uva.authentication.models; +package com.uva.authentication.models.remote; -import java.util.ArrayList; -import java.util.List; -import com.fasterxml.jackson.annotation.JsonIgnore; - -import jakarta.persistence.CascadeType; import jakarta.persistence.Entity; -import jakarta.persistence.FetchType; -import jakarta.persistence.OneToMany; import jakarta.persistence.Table; @Entity diff --git a/java/services/auth/src/main/java/com/uva/authentication/models/User.java b/java/services/auth/src/main/java/com/uva/authentication/models/remote/User.java similarity index 97% rename from java/services/auth/src/main/java/com/uva/authentication/models/User.java rename to java/services/auth/src/main/java/com/uva/authentication/models/remote/User.java index ae4981ae99984bc58ee01b196fb7c0e8ca93f0f4..a72ecfa8ef8f896afda01b7b1ead124c09b81fab 100644 --- a/java/services/auth/src/main/java/com/uva/authentication/models/User.java +++ b/java/services/auth/src/main/java/com/uva/authentication/models/remote/User.java @@ -1,4 +1,4 @@ -package com.uva.authentication.models; +package com.uva.authentication.models.remote; import com.fasterxml.jackson.annotation.JsonIgnore; diff --git a/java/services/auth/src/main/java/com/uva/authentication/models/UserRol.java b/java/services/auth/src/main/java/com/uva/authentication/models/remote/UserRol.java similarity index 54% rename from java/services/auth/src/main/java/com/uva/authentication/models/UserRol.java rename to java/services/auth/src/main/java/com/uva/authentication/models/remote/UserRol.java index 5944a6845b11b3dbbf0796f7b7d28641ff98fb75..fe4d90dd1dd595f4c09ec699b452910352b406d5 100644 --- a/java/services/auth/src/main/java/com/uva/authentication/models/UserRol.java +++ b/java/services/auth/src/main/java/com/uva/authentication/models/remote/UserRol.java @@ -1,4 +1,4 @@ -package com.uva.authentication.models; +package com.uva.authentication.models.remote; public enum UserRol { ADMIN, HOTEL_ADMIN, CLIENT diff --git a/java/services/auth/src/main/java/com/uva/authentication/models/UserStatus.java b/java/services/auth/src/main/java/com/uva/authentication/models/remote/UserStatus.java similarity index 65% rename from java/services/auth/src/main/java/com/uva/authentication/models/UserStatus.java rename to java/services/auth/src/main/java/com/uva/authentication/models/remote/UserStatus.java index cdf51ada0dadf18de9b28caeedf0923c7100ade9..5dd62bc5c75271eafa9daa58ad332aa8ad56d413 100644 --- a/java/services/auth/src/main/java/com/uva/authentication/models/UserStatus.java +++ b/java/services/auth/src/main/java/com/uva/authentication/models/remote/UserStatus.java @@ -1,4 +1,4 @@ -package com.uva.authentication.models; +package com.uva.authentication.models.remote; public enum UserStatus { NO_BOOKINGS, WITH_ACTIVE_BOOKINGS, WITH_INACTIVE_BOOKINGS; diff --git a/java/services/auth/src/main/java/com/uva/authentication/repositories/ClientRepository.java b/java/services/auth/src/main/java/com/uva/authentication/repositories/ClientRepository.java index 11e4c125110b7b6505e3321fc6e92434e639bf22..3019f8145452aa3f8e1347ab9f9296b2ffeea71a 100644 --- a/java/services/auth/src/main/java/com/uva/authentication/repositories/ClientRepository.java +++ b/java/services/auth/src/main/java/com/uva/authentication/repositories/ClientRepository.java @@ -3,8 +3,8 @@ package com.uva.authentication.repositories; import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; -import com.uva.authentication.models.Client; -import com.uva.authentication.models.User; +import com.uva.authentication.models.remote.Client; +import com.uva.authentication.models.remote.User; public interface ClientRepository extends JpaRepository<User, Integer> { Optional<Client> findByEmail(String email); diff --git a/java/services/auth/src/main/java/com/uva/authentication/repositories/HotelManagerRepository.java b/java/services/auth/src/main/java/com/uva/authentication/repositories/HotelManagerRepository.java index a1e0ba81f6f380e670e67a42435506b28a09a7e7..2d50305d0fc98a1ca2fdfb55cf4dd8de4fd4b659 100644 --- a/java/services/auth/src/main/java/com/uva/authentication/repositories/HotelManagerRepository.java +++ b/java/services/auth/src/main/java/com/uva/authentication/repositories/HotelManagerRepository.java @@ -3,8 +3,8 @@ package com.uva.authentication.repositories; import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; -import com.uva.authentication.models.HotelManager; -import com.uva.authentication.models.User; +import com.uva.authentication.models.remote.HotelManager; +import com.uva.authentication.models.remote.User; public interface HotelManagerRepository extends JpaRepository<User, Integer> { Optional<HotelManager> findByEmail(String email); diff --git a/java/services/auth/src/main/java/com/uva/authentication/repositories/UserRepository.java b/java/services/auth/src/main/java/com/uva/authentication/repositories/UserRepository.java index c0695df1aae2f7640ee1d38e2cf0b449e7d40baa..65f98edd7f2d0700de933199ae54c484eb8c71a3 100644 --- a/java/services/auth/src/main/java/com/uva/authentication/repositories/UserRepository.java +++ b/java/services/auth/src/main/java/com/uva/authentication/repositories/UserRepository.java @@ -2,7 +2,8 @@ package com.uva.authentication.repositories; import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; -import com.uva.authentication.models.User; + +import com.uva.authentication.models.remote.User; public interface UserRepository extends JpaRepository<User, Integer> { Optional<User> findByEmail(String email); diff --git a/java/services/auth/src/main/java/com/uva/authentication/services/AuthService.java b/java/services/auth/src/main/java/com/uva/authentication/services/AuthService.java index 3bc823b5702309ff46462efd50fe7809a82f02b2..e392a7bb693ab2db0b176eae4dc69aafc44db6b3 100644 --- a/java/services/auth/src/main/java/com/uva/authentication/services/AuthService.java +++ b/java/services/auth/src/main/java/com/uva/authentication/services/AuthService.java @@ -8,12 +8,12 @@ import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; import org.springframework.web.client.HttpClientErrorException; -import com.uva.authentication.models.Client; -import com.uva.authentication.models.HotelManager; import com.uva.authentication.models.LoginRequest; import com.uva.authentication.models.RegisterRequest; -import com.uva.authentication.models.User; -import com.uva.authentication.models.UserRol; +import com.uva.authentication.models.remote.Client; +import com.uva.authentication.models.remote.HotelManager; +import com.uva.authentication.models.remote.User; +import com.uva.authentication.models.remote.UserRol; import com.uva.authentication.repositories.ClientRepository; import com.uva.authentication.repositories.HotelManagerRepository; import com.uva.authentication.repositories.UserRepository; diff --git a/java/services/auth/src/main/java/com/uva/authentication/utils/JwtUtil.java b/java/services/auth/src/main/java/com/uva/authentication/utils/JwtUtil.java index 4ac66887be6006d0b898efca3db8c61df2d42b7d..518261304ec00dc5c48dd4f860a519cb46b03f75 100644 --- a/java/services/auth/src/main/java/com/uva/authentication/utils/JwtUtil.java +++ b/java/services/auth/src/main/java/com/uva/authentication/utils/JwtUtil.java @@ -15,7 +15,7 @@ import java.util.function.Function; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; -import com.uva.authentication.models.User; +import com.uva.authentication.models.remote.User; @Component public class JwtUtil {