From 6aa2b594f157d7b637b49f1af912f51feefdcc2f Mon Sep 17 00:00:00 2001
From: Marlene Simondant <msimondant@grandlyon.com>
Date: Tue, 25 Oct 2022 10:41:47 +0200
Subject: [PATCH 1/2] redirect to login page

---
 src/app/app-routing.module.ts |  3 +--
 src/app/app.module.ts         |  2 --
 src/app/guards/admin.guard.ts |  2 +-
 src/app/guards/auth.guard.ts  |  2 +-
 src/app/guards/login.guard.ts | 18 ------------------
 5 files changed, 3 insertions(+), 24 deletions(-)
 delete mode 100644 src/app/guards/login.guard.ts

diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts
index 5f82d11aa..32636a1d1 100644
--- a/src/app/app-routing.module.ts
+++ b/src/app/app-routing.module.ts
@@ -8,7 +8,6 @@ import { StructureListPrintComponent } from './form/orientation-form/component/s
 import { OrientationFormComponent } from './form/orientation-form/orientation-form.component';
 import { AdminGuard } from './guards/admin.guard';
 import { AuthGuard } from './guards/auth.guard';
-import { LoginGuard } from './guards/login.guard';
 import { LegalNoticeComponent } from './legal-notice/legal-notice.component';
 import { LoginComponent } from './login/login.component';
 import { NewsletterSubscriptionComponent } from './newsletter-subscription/newsletter-subscription.component';
@@ -167,7 +166,7 @@ const routes: Routes = [
     children: [
       {
         path: '',
-        canActivate: [LoginGuard],
+        canActivate: [AuthGuard],
         component: StructureExcludeComponent,
       },
       footerOutletRoute,
diff --git a/src/app/app.module.ts b/src/app/app.module.ts
index 0e71f948f..0a57db88a 100644
--- a/src/app/app.module.ts
+++ b/src/app/app.module.ts
@@ -22,7 +22,6 @@ import { LegalNoticeComponent } from './legal-notice/legal-notice.component';
 import { PageComponent } from './page/page.component';
 import { ContactComponent } from './contact/contact.component';
 import { AuthGuard } from './guards/auth.guard';
-import { LoginGuard } from './guards/login.guard';
 import { CustomHttpInterceptor } from './config/http-interceptor';
 import { ResetEmailComponent } from './reset-email/reset-email.component';
 import { ResetPasswordComponent } from './reset-password/reset-password.component';
@@ -102,7 +101,6 @@ import { FilterModalComponent } from './annuaire/filter-modal/filter-modal.compo
     AuthGuard,
     AdminGuard,
     RoleGuard,
-    LoginGuard,
     DeactivateGuard,
     TempUserResolver,
     StructureResolver,
diff --git a/src/app/guards/admin.guard.ts b/src/app/guards/admin.guard.ts
index 7d07a4d86..7b7ea1f4f 100644
--- a/src/app/guards/admin.guard.ts
+++ b/src/app/guards/admin.guard.ts
@@ -13,6 +13,6 @@ export class AdminGuard implements CanActivate {
     if (this.authService.isLoggedIn() && this.profileService.isAdmin()) {
       return true;
     }
-    return this.router.parseUrl('/home');
+    return this.router.parseUrl('/login');
   }
 }
diff --git a/src/app/guards/auth.guard.ts b/src/app/guards/auth.guard.ts
index d77c855f4..456ada45a 100644
--- a/src/app/guards/auth.guard.ts
+++ b/src/app/guards/auth.guard.ts
@@ -12,7 +12,7 @@ export class AuthGuard implements CanActivate {
     if (this.authService.isLoggedIn()) {
       return true;
     }
-    this.router.navigate(['/home'], { queryParams: { returnUrl: state.url } });
+    this.router.navigate(['/login'], { queryParams: { returnUrl: state.url } });
     return false;
   }
 }
diff --git a/src/app/guards/login.guard.ts b/src/app/guards/login.guard.ts
deleted file mode 100644
index b2d8e5b7f..000000000
--- a/src/app/guards/login.guard.ts
+++ /dev/null
@@ -1,18 +0,0 @@
-import { ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot } from '@angular/router';
-import { Injectable } from '@angular/core';
-import { AuthService } from '../services/auth.service';
-/**
- * Guard to assert that we are logged in. Otherwise redirect to home
- */
-@Injectable()
-export class LoginGuard implements CanActivate {
-  constructor(private authService: AuthService, private router: Router) {}
-
-  canActivate(_next: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
-    if (this.authService.isLoggedIn()) {
-      return true;
-    }
-    this.router.navigate(['/login'], { queryParams: { returnUrl: state.url } });
-    return false;
-  }
-}
-- 
GitLab


From 216884cd9b3ec618942f5a53d230c2c6f1cb6197 Mon Sep 17 00:00:00 2001
From: Marlene Simondant <msimondant@grandlyon.com>
Date: Tue, 25 Oct 2022 10:46:58 +0200
Subject: [PATCH 2/2] leave admin guard to /home

---
 src/app/guards/admin.guard.ts | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/app/guards/admin.guard.ts b/src/app/guards/admin.guard.ts
index 7b7ea1f4f..7d07a4d86 100644
--- a/src/app/guards/admin.guard.ts
+++ b/src/app/guards/admin.guard.ts
@@ -13,6 +13,6 @@ export class AdminGuard implements CanActivate {
     if (this.authService.isLoggedIn() && this.profileService.isAdmin()) {
       return true;
     }
-    return this.router.parseUrl('/login');
+    return this.router.parseUrl('/home');
   }
 }
-- 
GitLab