diff --git a/angular/RestClient/src/app/app.routes.ts b/angular/RestClient/src/app/app.routes.ts index 8a24a518d73cd82d34ebd7658472adbd237e17f9..c889563c2d7e4e5c07af018265c29076f167c4fb 100644 --- a/angular/RestClient/src/app/app.routes.ts +++ b/angular/RestClient/src/app/app.routes.ts @@ -16,14 +16,12 @@ export const routes: AppRoute[] = [ // Usuario { path: 'me', - canActivate: [rolGuard], canActivateChild: [rolGuardChild], loadChildren: () => import('./features/users').then((m) => m.USERS_ROUTES), }, // Administrador { path: 'admin', - canActivate: [rolGuard], canActivateChild: [rolGuardChild], data: { expectedRole: 'ADMIN' }, loadChildren: () => import('./features/admin').then((m) => m.ADMIN_ROUTES), @@ -33,9 +31,9 @@ export const routes: AppRoute[] = [ path: 'unauthorized', component: UnauthorizedComponent, }, - // { - // path: '**', - // redirectTo: '/login', - // pathMatch: 'full', - // }, + { + path: '**', + redirectTo: '/login', + pathMatch: 'full', + }, ]; diff --git a/angular/RestClient/src/app/core/guards/rol.guard.ts b/angular/RestClient/src/app/core/guards/rol.guard.ts index f63b9bc21aee027bf18b1ee5472f0464d1eb1079..4688794138c0606d922a497cb3f653752e49c41b 100644 --- a/angular/RestClient/src/app/core/guards/rol.guard.ts +++ b/angular/RestClient/src/app/core/guards/rol.guard.ts @@ -34,7 +34,7 @@ function verifyRol(expectedRole: UserRol) { if (!session) { console.log('no session'); - router.navigate(['/login']); + router.navigateByUrl(`/login?redirect=${router.url}`); return false; } @@ -75,7 +75,8 @@ export const rolGuard: CanActivateFn = (route, state) => { export const rolGuardChild: CanActivateChildFn = (childRoute, state) => { // Obtener el rol de la ruta hija si está especificado y en caso // de no especificarse se busca en el/los padres - let requiredRol = childRoute.data['rol'] ?? getInheritedRole(childRoute); + let requiredRol = + childRoute.data['expectedRole'] ?? getInheritedRole(childRoute); // Si no hay rol especificado se supone libre de verificación if (!requiredRol) return true; diff --git a/angular/RestClient/src/app/features/bookings/bookings.routes.ts b/angular/RestClient/src/app/features/bookings/bookings.routes.ts index a35688a9184f63633ed96f4e1a92d2d7ae402e3e..50991f2d06d12ff35e8f68957b53f3a97aa8f2e5 100644 --- a/angular/RestClient/src/app/features/bookings/bookings.routes.ts +++ b/angular/RestClient/src/app/features/bookings/bookings.routes.ts @@ -7,16 +7,13 @@ export const CLIENT_BOOKINGS_ROUTES: AppRoute[] = [ { path: '', component: UserBookingListComponent, - data: { expectedRole: 'CLIENT' }, }, { path: ':id', component: BookingComponent, - data: { expectedRole: 'CLIENT' }, }, { path: 'new', component: BookingComponent, - data: { expectedRole: 'CLIENT' }, }, ]; diff --git a/angular/RestClient/src/app/features/users/admin.routes.ts b/angular/RestClient/src/app/features/users/admin.routes.ts index 26ec32841bda62906699dd87be90500df17e586f..8441e25b2765e0748dba3bcd2c08413ffd78474f 100644 --- a/angular/RestClient/src/app/features/users/admin.routes.ts +++ b/angular/RestClient/src/app/features/users/admin.routes.ts @@ -2,7 +2,7 @@ import { AppRoute } from '@core/models/Route.interface'; import { MainPageComponent } from 'app/features/users/main-page/main-page.component'; import { UserFormRoute } from 'app/features/users/types/UserFormData'; import { UserFormComponent } from 'app/features/users/user-form/user-form.component'; -import { USERS_ROUTES } from 'app/features/users/users.routes'; +import { COMMON_USERS_ROUTES } from 'app/features/users/users.routes'; function changeToAdminScope(routes: UserFormRoute[]) { return routes.map((r) => { @@ -40,7 +40,7 @@ export const ADMIN_ROUTES: AppRoute[] = [ }, { path: ':id', - children: changeToAdminScope(USERS_ROUTES), + children: changeToAdminScope(COMMON_USERS_ROUTES), }, ], }, diff --git a/angular/RestClient/src/app/features/users/user-form/user-form.component.html b/angular/RestClient/src/app/features/users/user-form/user-form.component.html index 0e32cc87fe42b7e2073f4ffa885c2dc912ba46c1..052533f0738437c973c059fb9e63d17865a8a903 100644 --- a/angular/RestClient/src/app/features/users/user-form/user-form.component.html +++ b/angular/RestClient/src/app/features/users/user-form/user-form.component.html @@ -129,9 +129,9 @@ } @if (!isViewUser) { @if (isAuth) { <p class="text-right"> @if (isLogin) { - <a [routerLink]="['/register']">¿No tienes cuenta?</a> + <a [routerLink]="[getRegisterUrl()]">¿No tienes cuenta?</a> }@else { - <a [routerLink]="['/login']">¿Ya tienes cuenta?</a> + <a [routerLink]="[getLoginUrl()]">¿Ya tienes cuenta?</a> } </p> } diff --git a/angular/RestClient/src/app/features/users/user-form/user-form.component.ts b/angular/RestClient/src/app/features/users/user-form/user-form.component.ts index 2f310e1883404d59bc3823fd3c41653d01c965f1..2a0e8f34df65dc445e31b34cbc6e28c7e1e28fef 100644 --- a/angular/RestClient/src/app/features/users/user-form/user-form.component.ts +++ b/angular/RestClient/src/app/features/users/user-form/user-form.component.ts @@ -75,6 +75,8 @@ export class UserFormComponent implements OnInit { isManager = false; isAdmin = false; + redirect?: string; + constructor( private fb: FormBuilder, private sessionService: SessionService, @@ -86,13 +88,8 @@ export class UserFormComponent implements OnInit { ngOnInit(): void { this.setUp(); - - // const auth = this.session.getSession(); - // this.user = auth; - // this.userForm.patchValue({ - // name: this.user.name, - // email: this.user.email, - // }); + const { redirect } = this.route.snapshot.queryParams; + this.redirect = redirect; } private initializeForm(): void { @@ -112,14 +109,6 @@ export class UserFormComponent implements OnInit { const nameNotRequired = emailNotRequired || this.isLogin; // Solicitar rol const rolNotRequired = !this.isRegister; - // console.log({ - // confirmIdentity, - // isChangePassword, - // confirmPassword, - // emailNotRequired, - // nameNotRequired, - // rolNotRequired, - // }); this.userForm = this.fb.group({ name: [{ value: '', disabled: nameNotRequired }, Validators.required], @@ -204,6 +193,14 @@ export class UserFormComponent implements OnInit { } } + getRegisterUrl() { + return this.redirect ? `/register?redirect=${this.redirect}` : '/register'; + } + + getLoginUrl() { + return this.redirect ? `/login?redirect=${this.redirect}` : '/login'; + } + getHotelsUri() { const basePath = getBasePath(this.router.url); // Obtener la base: '/me' o '/users/:id' return `${basePath}/hotels`; @@ -326,11 +323,11 @@ export class UserFormComponent implements OnInit { private login(email: string, password: string) { this.sessionService.login(email, password).subscribe({ next: (r: any) => { - this.router.navigateByUrl(r.mainPage); + if (this.redirect) this.router.navigateByUrl(this.redirect); + else this.router.navigateByUrl(r.mainPage); }, error: (error) => { console.error(error); - // this.toastr.error('Invalid email or password'); }, }); } @@ -344,11 +341,11 @@ export class UserFormComponent implements OnInit { console.log({ name, email, password, rol }); this.sessionService.register(name, email, password, rol).subscribe({ next: (r: any) => { - this.router.navigateByUrl(r.mainPage); + if (this.redirect) this.router.navigateByUrl(this.redirect); + else this.router.navigateByUrl(r.mainPage); }, error: (error) => { console.error(error); - // this.toastr.error('Invalid email or password'); }, }); } @@ -360,7 +357,6 @@ export class UserFormComponent implements OnInit { }, error: (error) => { console.error(error); - // this.toastr.error('Invalid email or password'); }, }); } @@ -376,7 +372,6 @@ export class UserFormComponent implements OnInit { }, error: (error) => { console.error(error); - // this.toastr.error('Invalid email or password'); }, }); } @@ -399,7 +394,6 @@ export class UserFormComponent implements OnInit { }, error: (error) => { console.error(error); - // this.toastr.error('Invalid email or password'); }, }); } diff --git a/angular/RestClient/src/app/features/users/users.routes.ts b/angular/RestClient/src/app/features/users/users.routes.ts index b22713021db10c382d3f89a37999fc8975d1631a..8ed107a8baa86c682ecd20163698c506b3e66adf 100644 --- a/angular/RestClient/src/app/features/users/users.routes.ts +++ b/angular/RestClient/src/app/features/users/users.routes.ts @@ -1,7 +1,7 @@ import { UserFormComponent } from './user-form/user-form.component'; import { UserFormRoute } from './types/UserFormData'; -export const USERS_ROUTES: UserFormRoute[] = [ +export const COMMON_USERS_ROUTES: UserFormRoute[] = [ // Common { path: '', @@ -30,6 +30,10 @@ export const USERS_ROUTES: UserFormRoute[] = [ }, component: UserFormComponent, }, +]; + +export const USERS_ROUTES: UserFormRoute[] = [ + ...COMMON_USERS_ROUTES, { // Usuario administrador de hoteles path: 'hotels', diff --git a/docker-compose.yml b/docker-compose.yml index 2244d32ca089bb97babffde32e46f734637d88cd..522252ab10d4aef02d8cac7366f272302a799732 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -11,22 +11,22 @@ services: ####################################### # Cliente Angular ####################################### - # RoomsBooking-Web: - # image: roomsbooking-web-image - # build: - # context: ./angular/RestClient - # dockerfile: ./Dockerfile - # restart: unless-stopped - # ports: - # - 4200:80 - # networks: - # - kong-net - # depends_on: - # - kong - # - Auth-API - # - Users-API - # - Hotels-API - # - Bookings-API + RoomsBooking-Web: + image: roomsbooking-web-image + build: + context: ./angular/RestClient + dockerfile: ./Dockerfile + restart: unless-stopped + ports: + - 4200:80 + networks: + - kong-net + depends_on: + - kong + - Auth-API + - Users-API + - Hotels-API + - Bookings-API ####################################### # Kong