From df97cf010d2209ad0471695d8f225f903f2ce14e Mon Sep 17 00:00:00 2001 From: salazard <hamzatouizrat@yahoo.com> Date: Sun, 13 Nov 2022 21:37:00 +0100 Subject: [PATCH] post --- src/app/core/auth/auth.service.ts | 9 ++- src/app/login/login.component.ts | 67 ++++++++++++------- .../parents-charter.component.html | 2 +- .../parents-charter.component.ts | 12 +++- src/environments/environment.local.ts | 2 +- src/environments/environment.ts | 2 +- src/environments/tes-environment.ts | 9 +++ 7 files changed, 71 insertions(+), 32 deletions(-) create mode 100644 src/environments/tes-environment.ts diff --git a/src/app/core/auth/auth.service.ts b/src/app/core/auth/auth.service.ts index 72594ac..b628cdc 100644 --- a/src/app/core/auth/auth.service.ts +++ b/src/app/core/auth/auth.service.ts @@ -22,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 + 'charter'; + private mandatorySignatureUrl = environment.apiUrl + 'charter/'; //add the corresponding path in backend interface @@ -100,6 +100,13 @@ export class AuthService { return false; } + sendSignatureCharter(email: any) : Observable<Boolean> { + return this.http.post<Boolean>( this.mandatorySignatureUrl+'?email=' +email,{}).pipe( + map((data: any) => { + return data}), + ); + } + logout() { this.user.destroy(); this.token.destroy(); diff --git a/src/app/login/login.component.ts b/src/app/login/login.component.ts index 904e16e..6a6b64e 100644 --- a/src/app/login/login.component.ts +++ b/src/app/login/login.component.ts @@ -4,7 +4,7 @@ import { FormGroup, FormBuilder } from '@angular/forms'; import { MatSnackBar } from '@angular/material'; import { AuthService, MessageService } from 'app/core'; import { of } from 'rxjs'; -import { filter, map, tap, catchError } from 'rxjs/operators'; +import { filter, map, tap, catchError, subscribeOn } from 'rxjs/operators'; @Component({ selector: 'app-login', @@ -18,6 +18,7 @@ export class LoginComponent implements OnInit { defaultRedirectUrl: string = '/membres'; charterUrl: string = 'inscription/student-charter'; formGroup: FormGroup; + loginSuccess: boolean = false; constructor( private router: Router, @@ -44,44 +45,58 @@ export class LoginComponent implements OnInit { }); } - login() { + async login() { + var toto = false; this.loading = true; const { email, password } = this.formGroup.value; this.messageService.clear(); - this.auth.login(email, password).pipe( + await this.auth.login(email, password).pipe( + + map(() => this.loginSuccess = true), catchError(() => { this.messageService.error("L'identifiant ou le mot de passe est incorrect."); + this.loginSuccess = false; 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(); + ).subscribe({ + complete() { + console.log("login unsuccess"); + }, + }); - 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.router.navigate([this.defaultRedirectUrl]); - } - }); + if(this.loginSuccess == true){ + + 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.router.navigate([this.defaultRedirectUrl]); + } + }); +} - } +} } \ No newline at end of file diff --git a/src/app/signup/parents-charter/parents-charter.component.html b/src/app/signup/parents-charter/parents-charter.component.html index 039081d..b38f6a5 100644 --- a/src/app/signup/parents-charter/parents-charter.component.html +++ b/src/app/signup/parents-charter/parents-charter.component.html @@ -85,7 +85,7 @@ </p> <div class="text-center"> - <button mat-raised-button color="primary" [disabled]="!toggleSuivant()" routerLink='/membres/compte/modifier_donnees'> + <button mat-raised-button color="primary" (click)="signChart()" [disabled]="!toggleSuivant()" routerLink='/membres/compte/modifier_donnees'> Terminer l'inscription </button> </div> diff --git a/src/app/signup/parents-charter/parents-charter.component.ts b/src/app/signup/parents-charter/parents-charter.component.ts index 7e1fe20..378046e 100644 --- a/src/app/signup/parents-charter/parents-charter.component.ts +++ b/src/app/signup/parents-charter/parents-charter.component.ts @@ -1,4 +1,5 @@ import { Component, OnInit } from '@angular/core'; +import { AuthService } from 'app/core'; import { Registration, RegistrationService, PasswordErrorStateMatcher,PersonnalData,PersonnalDataService } from '../core'; import { StudentSignupComponent } from '../student-signup/student-signup.component'; @@ -16,7 +17,9 @@ export class ParentsCharterComponent implements OnInit { state_button:boolean; - constructor() { } + constructor( + private auth: AuthService, + ) { } ngOnInit() { @@ -42,5 +45,10 @@ export class ParentsCharterComponent implements OnInit { } - + // send post to url + signChart() + { + console.log("signChart"); + this.auth.sendSignatureCharter(this.auth.getUserSnapshot().email).subscribe(); + } } diff --git a/src/environments/environment.local.ts b/src/environments/environment.local.ts index 198da5d..316ece0 100644 --- a/src/environments/environment.local.ts +++ b/src/environments/environment.local.ts @@ -1,7 +1,7 @@ // For use when you have a local backend server running export const environment = { production: false, - showcaseApiUrl: 'https://oser-site-vitrine.herokuapp.com/api/', + showcaseApiUrl: 'https://oser-cs.fr/api/', apiUrl: 'http://localhost:8000/api/', numArticles: 3, donateUrl: "https://www.donnerenligne.fr/ouverture-sociale-pour-l-egalite-et-la-reussite/faire-un-don", diff --git a/src/environments/environment.ts b/src/environments/environment.ts index 549e327..c92a014 100644 --- a/src/environments/environment.ts +++ b/src/environments/environment.ts @@ -2,7 +2,7 @@ export const environment = { production: false, showcaseApiUrl: 'https://oser-site-vitrine.herokuapp.com/api/', - apiUrl: 'https://oser-backend-dev.herokuapp.com/api/', + apiUrl: 'http://localhost:8000/api/', numArticles: 3, donateUrl: "https://www.donnerenligne.fr/ouverture-sociale-pour-l-egalite-et-la-reussite/faire-un-don", currentCampaignUrl: "", diff --git a/src/environments/tes-environment.ts b/src/environments/tes-environment.ts new file mode 100644 index 0000000..2e3edf4 --- /dev/null +++ b/src/environments/tes-environment.ts @@ -0,0 +1,9 @@ +// Development environment (the default) +export const environment = { + production: false, + showcaseApiUrl: 'https://oser-site-vitrine.herokuapp.com/api/', + apiUrl: 'http://oser-backend:8000/api/', + numArticles: 3, + donateUrl: "https://www.donnerenligne.fr/ouverture-sociale-pour-l-egalite-et-la-reussite/faire-un-don", + currentCampaignUrl: "", +}; -- GitLab