From 190a0287e9524f42e5a84fb6b36ae0a124a1151a Mon Sep 17 00:00:00 2001 From: salazard <hamzatouizrat@yahoo.com> Date: Sat, 12 Nov 2022 00:54:53 +0100 Subject: [PATCH] add redirect to charter --- src/app/core/auth/auth.service.ts | 7 ++-- src/app/login/login.component.ts | 67 +++++++++++++++++-------------- 2 files changed, 40 insertions(+), 34 deletions(-) diff --git a/src/app/core/auth/auth.service.ts b/src/app/core/auth/auth.service.ts index 7252e45..72594ac 100644 --- a/src/app/core/auth/auth.service.ts +++ b/src/app/core/auth/auth.service.ts @@ -7,6 +7,7 @@ import { environment } from 'environments/environment'; import { User } from './models'; import { ObjectStoredItem, SimpleStoredItem } from '../storage'; import { UserAdapter } from './adapters'; +import { HttpParams } from '@angular/common/http'; class StoredUser extends ObjectStoredItem<User> { key = 'oser-cs-user-info'; } @@ -21,7 +22,7 @@ export class AuthService { private loginUrl = environment.apiUrl + 'auth/get-token/'; private resetUrl = environment.apiUrl + 'rest-auth/password/reset/'; private resetConfirmUrl = environment.apiUrl + 'rest-auth/password/reset/confirm/'; - private mandatorySignatureUrl = environment.apiUrl + ''; + private mandatorySignatureUrl = environment.apiUrl + 'charter'; //add the corresponding path in backend interface @@ -86,10 +87,10 @@ export class AuthService { } checkSignatureCharter(email: any) : Observable<Boolean> { - return this.http.get<any>( this.mandatorySignatureUrl, { params: email }).pipe( + const parm = new HttpParams({fromString: 'email='+ email}) + return this.http.get<Boolean>( this.mandatorySignatureUrl, { params: parm}).pipe( map((data: any) => { return data}), - ); } get isLoggedIn(): boolean { diff --git a/src/app/login/login.component.ts b/src/app/login/login.component.ts index dff78f8..904e16e 100644 --- a/src/app/login/login.component.ts +++ b/src/app/login/login.component.ts @@ -14,8 +14,9 @@ import { filter, map, tap, catchError } from 'rxjs/operators'; export class LoginComponent implements OnInit { loading: boolean = false; + hassignedCharter = true; defaultRedirectUrl: string = '/membres'; - charterUrl : string = 'inscription/student-charter'; + charterUrl: string = 'inscription/student-charter'; formGroup: FormGroup; constructor( @@ -47,36 +48,40 @@ export class LoginComponent implements OnInit { this.loading = true; const { email, password } = this.formGroup.value; this.messageService.clear(); - 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(); + 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. + ).subscribe(); + + this.auth.checkSignatureCharter(email).pipe( + catchError(() => { + this.hassignedCharter = false; + + this.messageService.error("Vous n'avez pas signé le(s) charte(s)."); + map(() => this.auth.redirectUrl ? this.auth.redirectUrl : this.defaultRedirectUrl), + tap((redirectUrl: string) => this.router.navigate([redirectUrl])); + return of(false); + }), + map(() => this.auth.redirectUrl ? this.auth.redirectUrl : this.defaultRedirectUrl), + tap(() => this.snackBar.open('Connexion réussie !', 'OK', { duration: 2000 })), + ).subscribe().add(() => + { + if(this.hassignedCharter == false) + { + this.router.navigate([this.charterUrl]); } - 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(); + else + { + this.router.navigate([this.defaultRedirectUrl]); } -} + }); + + } +} \ No newline at end of file -- GitLab