From 8e6b41976f0475258c4223b12f6eda8c724d3fc3 Mon Sep 17 00:00:00 2001
From: Aidli Melissa <melissa.aidli@student-cs.fr>
Date: Thu, 27 Oct 2022 16:55:01 +0200
Subject: [PATCH] Changed the route in login according to charter signature

---
 src/app/core/auth/auth.service.ts |  9 ++++++++-
 src/app/login/login.component.ts  | 15 +++++++++++----
 2 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/src/app/core/auth/auth.service.ts b/src/app/core/auth/auth.service.ts
index e7c506f..c80551d 100644
--- a/src/app/core/auth/auth.service.ts
+++ b/src/app/core/auth/auth.service.ts
@@ -18,9 +18,10 @@ class StoredToken extends SimpleStoredItem { key = 'oser-cs-user-token'; }
 })
 export class AuthService {
 
-  private loginUrl = environment.apiUrl + 'auth/get-token/';
+  private loginUrl = environment. + 'auth/get-token/';
   private resetUrl = environment.apiUrl + 'rest-auth/password/reset/';
   private resetConfirmUrl = environment.apiUrl + 'rest-auth/password/reset/confirm/';
+  private mandatorySignatureUrl = environment.apiUrl + ''; 
 
   fromGuard: boolean;
   redirectUrl: string;
@@ -82,6 +83,12 @@ export class AuthService {
     return new HttpHeaders({ Authorization: 'Token ' + this.getToken() });
   }
 
+  checkSignatureCharter(email: string) : Observable<boolean> {
+    return this.http.post<any>(this.mandatorySignatureUrl, {email : email}).pipe(
+      map(() => true),
+    );
+  }
+
   get isLoggedIn(): boolean {
     if (this.user.get()) {
       return true;
diff --git a/src/app/login/login.component.ts b/src/app/login/login.component.ts
index 5070b7c..e438b48 100644
--- a/src/app/login/login.component.ts
+++ b/src/app/login/login.component.ts
@@ -15,6 +15,7 @@ export class LoginComponent implements OnInit {
 
   loading: boolean = false;
   defaultRedirectUrl: string = '/membres';
+  charterUrl : string = 'inscription/student-charter';
   formGroup: FormGroup;
 
   constructor(
@@ -54,11 +55,17 @@ export class LoginComponent implements OnInit {
       tap(() => this.loading = false),
       // Only continue if no error
       filter(Boolean),
-      // Get redirect URL from the auth service, provided by the auth guard.
-      map(() =>this.auth.redirectUrl ? this.auth.redirectUrl : this.defaultRedirectUrl),
+      // Get redirect URL from the auth service, provided by the auth guard. 
+      map(() => {
+        if (this.auth.checkSignatureCharter) {
+          this.auth.redirectUrl ? this.auth.redirectUrl : this.defaultRedirectUrl
+        }
+        else {
+          this.auth.redirectUrl ? this.auth.redirectUrl : this.charterUrl
+        }
+      }),
       tap(() => this.snackBar.open('Connexion réussie !', 'OK', { duration: 2000 })),
-      tap((redirectUrl: string) => this.router.navigate([redirectUrl])),
     ).subscribe();
-  }
+    }
 
 }
-- 
GitLab