diff --git a/src/app/core/auth/auth.service.ts b/src/app/core/auth/auth.service.ts index 7252e45aeb7fbbc6424c9b00ec622bc7672a286a..72594ac573f42a24563915c42b842ecf08e4a7bb 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 dff78f80fd0230cea93101f9cb65c2b4c47dbbf6..904e16e0efa8e920c8a0b4e3163e607e2a31398b 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