From 9ac5c6996d7842e50acfcdad6c28d96425459611 Mon Sep 17 00:00:00 2001 From: Oriol Agost Batalla Date: Fri, 20 Oct 2023 20:03:16 +0200 Subject: [PATCH] feat: implement admin guard, add refuges skeleton --- app/src/app/app-routing.module.ts | 9 ++++++++- app/src/app/guards/admin.guard.ts | 14 ++++++++++++++ app/src/app/pages/login/login.page.html | 3 +-- .../refuges/refuges/refuges-routing.module.ts | 19 +++++++++++++++++++ .../pages/refuges/refuges/refuges.module.ts | 15 +++++++++++++++ .../pages/refuges/refuges/refuges.page.html | 13 +++++++++++++ .../pages/refuges/refuges/refuges.page.scss | 0 .../refuges/refuges/refuges.page.spec.ts | 17 +++++++++++++++++ .../app/pages/refuges/refuges/refuges.page.ts | 12 ++++++++++++ 9 files changed, 99 insertions(+), 3 deletions(-) create mode 100644 app/src/app/guards/admin.guard.ts create mode 100644 app/src/app/pages/refuges/refuges/refuges-routing.module.ts create mode 100644 app/src/app/pages/refuges/refuges/refuges.module.ts create mode 100644 app/src/app/pages/refuges/refuges/refuges.page.html create mode 100644 app/src/app/pages/refuges/refuges/refuges.page.scss create mode 100644 app/src/app/pages/refuges/refuges/refuges.page.spec.ts create mode 100644 app/src/app/pages/refuges/refuges/refuges.page.ts diff --git a/app/src/app/app-routing.module.ts b/app/src/app/app-routing.module.ts index 5a009d5..835067b 100644 --- a/app/src/app/app-routing.module.ts +++ b/app/src/app/app-routing.module.ts @@ -9,7 +9,7 @@ const routes: Routes = [ }, { path: '', - redirectTo: 'home', + redirectTo: 'refuges', pathMatch: 'full', }, { @@ -31,6 +31,13 @@ const routes: Routes = [ (m) => m.ProgrammingErrorPageModule, ), }, + { + path: 'refuges', + loadChildren: () => + import('./pages/refuges/refuges/refuges.module').then( + (m) => m.RefugesPageModule, + ), + }, ]; @NgModule({ diff --git a/app/src/app/guards/admin.guard.ts b/app/src/app/guards/admin.guard.ts new file mode 100644 index 0000000..ca249a0 --- /dev/null +++ b/app/src/app/guards/admin.guard.ts @@ -0,0 +1,14 @@ +import { CanActivateFn, Router } from '@angular/router'; +import { inject } from '@angular/core'; +import { AuthService } from '../services/auth/auth.service'; + +export const adminGuard: CanActivateFn = async () => { + const authService = inject(AuthService); + const router = inject(Router); + + if (await authService.isAuthenticated()) { + return true; + } + + return router.parseUrl('/login'); +}; diff --git a/app/src/app/pages/login/login.page.html b/app/src/app/pages/login/login.page.html index 6f9295e..f553977 100644 --- a/app/src/app/pages/login/login.page.html +++ b/app/src/app/pages/login/login.page.html @@ -22,8 +22,7 @@ label="Username" labelPlacement="stacked" [clearInput]="true" - placeholder="(+34) xxx xxx xxx" - type="tel" + placeholder="John Doe" fill="outline" [(ngModel)]="credentials.username" name="username" diff --git a/app/src/app/pages/refuges/refuges/refuges-routing.module.ts b/app/src/app/pages/refuges/refuges/refuges-routing.module.ts new file mode 100644 index 0000000..ef73c71 --- /dev/null +++ b/app/src/app/pages/refuges/refuges/refuges-routing.module.ts @@ -0,0 +1,19 @@ +import { NgModule } from '@angular/core'; +import { Routes, RouterModule } from '@angular/router'; + +import { RefugesPage } from './refuges.page'; +import { adminGuard } from '../../../guards/admin.guard'; + +const routes: Routes = [ + { + path: '', + component: RefugesPage, + canActivate: [adminGuard], + }, +]; + +@NgModule({ + imports: [RouterModule.forChild(routes)], + exports: [RouterModule], +}) +export class RefugesPageRoutingModule {} diff --git a/app/src/app/pages/refuges/refuges/refuges.module.ts b/app/src/app/pages/refuges/refuges/refuges.module.ts new file mode 100644 index 0000000..662b503 --- /dev/null +++ b/app/src/app/pages/refuges/refuges/refuges.module.ts @@ -0,0 +1,15 @@ +import { NgModule } from '@angular/core'; +import { CommonModule } from '@angular/common'; +import { FormsModule } from '@angular/forms'; + +import { IonicModule } from '@ionic/angular'; + +import { RefugesPageRoutingModule } from './refuges-routing.module'; + +import { RefugesPage } from './refuges.page'; + +@NgModule({ + imports: [CommonModule, FormsModule, IonicModule, RefugesPageRoutingModule], + declarations: [RefugesPage], +}) +export class RefugesPageModule {} diff --git a/app/src/app/pages/refuges/refuges/refuges.page.html b/app/src/app/pages/refuges/refuges/refuges.page.html new file mode 100644 index 0000000..82c5e23 --- /dev/null +++ b/app/src/app/pages/refuges/refuges/refuges.page.html @@ -0,0 +1,13 @@ + + + refuges + + + + + + + refuges + + + diff --git a/app/src/app/pages/refuges/refuges/refuges.page.scss b/app/src/app/pages/refuges/refuges/refuges.page.scss new file mode 100644 index 0000000..e69de29 diff --git a/app/src/app/pages/refuges/refuges/refuges.page.spec.ts b/app/src/app/pages/refuges/refuges/refuges.page.spec.ts new file mode 100644 index 0000000..5acb779 --- /dev/null +++ b/app/src/app/pages/refuges/refuges/refuges.page.spec.ts @@ -0,0 +1,17 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { RefugesPage } from './refuges.page'; + +describe('RefugesPage', () => { + let component: RefugesPage; + let fixture: ComponentFixture; + + beforeEach(async(() => { + fixture = TestBed.createComponent(RefugesPage); + component = fixture.componentInstance; + fixture.detectChanges(); + })); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/app/src/app/pages/refuges/refuges/refuges.page.ts b/app/src/app/pages/refuges/refuges/refuges.page.ts new file mode 100644 index 0000000..e1fed1b --- /dev/null +++ b/app/src/app/pages/refuges/refuges/refuges.page.ts @@ -0,0 +1,12 @@ +import { Component, OnInit } from '@angular/core'; + +@Component({ + selector: 'app-refuges', + templateUrl: './refuges.page.html', + styleUrls: ['./refuges.page.scss'], +}) +export class RefugesPage implements OnInit { + constructor() {} + + ngOnInit() {} +}