From 41a00fff8938f18e3f3386dd33b8858e2a33de67 Mon Sep 17 00:00:00 2001
From: Aidli Melissa <melissa.aidli@student-cs.fr>
Date: Fri, 11 Nov 2022 23:19:30 +0100
Subject: [PATCH] Syntax in login with get request for charter

---
 src/app/login/login.component.ts | 51 +++++++++++++++++++-------------
 1 file changed, 31 insertions(+), 20 deletions(-)

diff --git a/src/app/login/login.component.ts b/src/app/login/login.component.ts
index e438b48..dff78f8 100644
--- a/src/app/login/login.component.ts
+++ b/src/app/login/login.component.ts
@@ -47,25 +47,36 @@ export class LoginComponent implements OnInit {
     this.loading = true;
     const { email, password } = this.formGroup.value;
     this.messageService.clear();
-    this.auth.login(email, password).pipe(
-      catchError(() => {
-        this.messageService.error("L'identifiant ou le mot de passe est incorrect.");
-        return of(false);
-      }),
-      tap(() => this.loading = false),
-      // Only continue if no error
-      filter(Boolean),
-      // 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 })),
-    ).subscribe();
-    }
+    console.log(this.auth.checkFakeSignatureCharter(email))
+    if (this.auth.checkSignatureCharter(email)){
+      this.auth.login(email, password).pipe(
+        catchError(() => {
+          this.messageService.error("L'identifiant ou le mot de passe est incorrect.");
+          return of(false);
+        }),
+        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),
+        tap(() => this.snackBar.open('Connexion réussie !', 'OK', { duration: 2000 })),
+        tap((redirectUrl: string) => this.router.navigate([redirectUrl])),
+      ).subscribe();
 
+    }
+    else {
+      this.auth.login(email, password).pipe(
+        catchError(() => {
+          this.messageService.error("L'identifiant ou le mot de passe est incorrect.");
+          return of(false);
+        }),
+        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.charterUrl),
+        tap(() => this.snackBar.open('Connexion réussie ! Tu vas devoir signer des chartes', 'OK', { duration: 2000 })),
+        tap((redirectUrl: string) => this.router.navigate([redirectUrl])),
+      ).subscribe();
+    }
 }
-- 
GitLab