From be3956818bddb4c96bc6904431c2a1db9118bd6c Mon Sep 17 00:00:00 2001 From: MiharyR Date: Sun, 5 Dec 2021 16:44:47 +0100 Subject: [PATCH] connexion au back avec la partie 'beforeConnexion' --- .../navbar-admin/navbar-admin.component.html | 2 +- .../navbar-admin/navbar-admin.component.ts | 19 +++++++++-- .../navbar-advertiser.component.html | 2 +- .../navbar-advertiser.component.ts | 19 +++++++++-- .../login/page-login/page-login.component.ts | 10 ++++-- .../popup-forgotten-password.component.html | 2 +- .../page-register/page-register.component.ts | 34 ++++--------------- .../popup-confirmation.component.ts | 3 +- .../navbar-user/navbar-user.component.html | 2 +- .../navbar-user/navbar-user.component.ts | 19 +++++++++-- .../services/profil/profil.service.spec.ts | 16 +++++++++ .../utils/services/profil/profil.service.ts | 9 +++++ 12 files changed, 93 insertions(+), 44 deletions(-) create mode 100644 src/app/utils/services/profil/profil.service.spec.ts create mode 100644 src/app/utils/services/profil/profil.service.ts diff --git a/src/app/admin/utils/navbar-admin/navbar-admin.component.html b/src/app/admin/utils/navbar-admin/navbar-admin.component.html index 90f0cbc..322bf13 100644 --- a/src/app/admin/utils/navbar-admin/navbar-admin.component.html +++ b/src/app/admin/utils/navbar-admin/navbar-admin.component.html @@ -23,7 +23,7 @@ - diff --git a/src/app/admin/utils/navbar-admin/navbar-admin.component.ts b/src/app/admin/utils/navbar-admin/navbar-admin.component.ts index f9c0f04..e23ae05 100644 --- a/src/app/admin/utils/navbar-admin/navbar-admin.component.ts +++ b/src/app/admin/utils/navbar-admin/navbar-admin.component.ts @@ -1,5 +1,7 @@ import {Component} from '@angular/core'; import {Router} from "@angular/router"; +import {ProfilService} from "../../../utils/services/profil/profil.service"; +import {MessageService} from "../../../utils/services/message/message.service"; @@ -19,9 +21,20 @@ export class NavbarAdminComponent url = this.router.url; - urlImage: string = "https://www.reference-gaming.com/assets/media/product/41195/figurine-pop-duck-tales-n-309-loulou.jpg?format=product-cover-large&k=1519639530" ; + constructor( private router: Router, + public profilService: ProfilService, + private messageService: MessageService ) { } - constructor(private router: Router) { } + onDeconnexion(): void + { + this.messageService + .delete('user/logout', {}) + .subscribe(retour => this.onDeconnexionCallback(retour), err => this.onDeconnexionCallback(err)); + } + + onDeconnexionCallback(retour: any): void + { + console.log(retour); + } - onDeconnexion(): void {} } diff --git a/src/app/advertiser/utils/navbar-advertiser/navbar-advertiser.component.html b/src/app/advertiser/utils/navbar-advertiser/navbar-advertiser.component.html index 1b16354..c1a8267 100644 --- a/src/app/advertiser/utils/navbar-advertiser/navbar-advertiser.component.html +++ b/src/app/advertiser/utils/navbar-advertiser/navbar-advertiser.component.html @@ -27,7 +27,7 @@ - diff --git a/src/app/advertiser/utils/navbar-advertiser/navbar-advertiser.component.ts b/src/app/advertiser/utils/navbar-advertiser/navbar-advertiser.component.ts index 0b9440d..a0e5181 100644 --- a/src/app/advertiser/utils/navbar-advertiser/navbar-advertiser.component.ts +++ b/src/app/advertiser/utils/navbar-advertiser/navbar-advertiser.component.ts @@ -1,5 +1,7 @@ import { Component } from '@angular/core'; import {Router} from "@angular/router"; +import {ProfilService} from "../../../utils/services/profil/profil.service"; +import {MessageService} from "../../../utils/services/message/message.service"; @@ -20,9 +22,20 @@ export class NavbarAdvertiserComponent url = this.router.url; - urlImage: string = "https://www.figurines-goodies.com/1188-large_default/dewey-duck-tales-disney-funko-pop.jpg" ; + constructor( private router: Router, + public profilService: ProfilService, + private messageService: MessageService ) { } - constructor(private router: Router) { } + onDeconnexion(): void + { + this.messageService + .delete('user/logout', {}) + .subscribe(retour => this.onDeconnexionCallback(retour), err => this.onDeconnexionCallback(err)); + } + + onDeconnexionCallback(retour: any): void + { + console.log(retour); + } - onDeconnexion(): void {} } diff --git a/src/app/beforeConnexion/login/page-login/page-login.component.ts b/src/app/beforeConnexion/login/page-login/page-login.component.ts index 8bbd022..d53bf46 100644 --- a/src/app/beforeConnexion/login/page-login/page-login.component.ts +++ b/src/app/beforeConnexion/login/page-login/page-login.component.ts @@ -5,6 +5,7 @@ import {ThemeService} from "../../../utils/services/theme/theme.service"; import {MatDialog} from "@angular/material/dialog"; import {PopupForgottenPasswordComponent} from "../popup-forgotten-password/popup-forgotten-password.component"; import {MatSnackBar} from "@angular/material/snack-bar"; +import {ProfilService} from "../../../utils/services/profil/profil.service"; @@ -25,7 +26,8 @@ export class PageLoginComponent implements OnInit private router: Router, public themeService: ThemeService, public dialog: MatDialog, - private snackBar: MatSnackBar ) { } + private snackBar: MatSnackBar, + private profilService: ProfilService) { } ngOnInit(): void {} @@ -50,12 +52,16 @@ export class PageLoginComponent implements OnInit onSeConnecterCallback(retour): void { + console.log(retour); if(retour.status !== "success") { this.errorMessage = retour.error.data.reason; this.hasError = true; } else { - this.router.navigateByUrl( '/user/search'); + this.profilService.profileImageUrl = retour.data.profileImageUrl; + if(retour.data.role.name === "user") this.router.navigateByUrl( '/user/search'); + else if(retour.data.role.name === "advertiser") this.router.navigateByUrl( '/advertiser/adList'); + else if(retour.data.role.name === "admin") this.router.navigateByUrl( '/admin/userList'); } } diff --git a/src/app/beforeConnexion/login/popup-forgotten-password/popup-forgotten-password.component.html b/src/app/beforeConnexion/login/popup-forgotten-password/popup-forgotten-password.component.html index 80a2fc9..c34b58e 100644 --- a/src/app/beforeConnexion/login/popup-forgotten-password/popup-forgotten-password.component.html +++ b/src/app/beforeConnexion/login/popup-forgotten-password/popup-forgotten-password.component.html @@ -1,4 +1,4 @@ -

Oubli mot de passe

+

Récupération du mot de passe


diff --git a/src/app/beforeConnexion/register/page-register/page-register.component.ts b/src/app/beforeConnexion/register/page-register/page-register.component.ts index 66dd8bf..5eaf743 100644 --- a/src/app/beforeConnexion/register/page-register/page-register.component.ts +++ b/src/app/beforeConnexion/register/page-register/page-register.component.ts @@ -1,4 +1,4 @@ -import { Component, OnInit } from '@angular/core'; +import { Component } from '@angular/core'; import {MessageService} from "../../../utils/services/message/message.service"; import {Router} from "@angular/router"; import {MatDialog} from "@angular/material/dialog"; @@ -55,27 +55,18 @@ export class PageRegisterComponent { if(this.user.role.name === "user") this.user.role.permission = 0; else this.user.role.permission = 5; - this.user.hashPass = this.hashage(this.password); - - // FAUX CODE - const retour = { status: "succes" }; - this.myCallback(retour); - - // VRAI CODE - /* + this.user.hashPass = this.password; this.messageService - .sendMessage('register', this.user) - .subscribe(retour => this.myCallback(retour)); - */ + .post('user/create', this.user) + .subscribe(retour => this.onEnregistrerCallback(retour), err => this.onEnregistrerCallback(err)); } } // Gestion de la réponde du backend - myCallback(retour): void + onEnregistrerCallback(retour): void { - if(retour.status === "error") - { + if(retour.status !== "success") { console.log(retour); } else @@ -140,17 +131,4 @@ export class PageRegisterComponent this.user.interests = myInterets; } - - // Fonction de hashage (faible) - hashage(input: string): string - { - let hash = 0; - for (let i = 0; i < input.length; i++) { - let ch = input.charCodeAt(i); - hash = ((hash << 5) - hash) + ch; - hash = hash & hash; - } - return hash.toString(); - } - } diff --git a/src/app/beforeConnexion/register/popup-confirmation/popup-confirmation.component.ts b/src/app/beforeConnexion/register/popup-confirmation/popup-confirmation.component.ts index 4828dfc..2152f9b 100644 --- a/src/app/beforeConnexion/register/popup-confirmation/popup-confirmation.component.ts +++ b/src/app/beforeConnexion/register/popup-confirmation/popup-confirmation.component.ts @@ -1,6 +1,8 @@ import {Component, Inject} from '@angular/core'; import {MAT_DIALOG_DATA, MatDialogRef} from "@angular/material/dialog"; + + @Component({ selector: 'app-popup-confirmation', templateUrl: './popup-confirmation.component.html', @@ -10,5 +12,4 @@ export class PopupConfirmationComponent { constructor( public dialogRef: MatDialogRef, @Inject(MAT_DIALOG_DATA) public data) {} - } diff --git a/src/app/user/utils/components/navbar-user/navbar-user.component.html b/src/app/user/utils/components/navbar-user/navbar-user.component.html index eb7bf23..4770348 100644 --- a/src/app/user/utils/components/navbar-user/navbar-user.component.html +++ b/src/app/user/utils/components/navbar-user/navbar-user.component.html @@ -27,7 +27,7 @@ - diff --git a/src/app/user/utils/components/navbar-user/navbar-user.component.ts b/src/app/user/utils/components/navbar-user/navbar-user.component.ts index e49c490..ce92706 100644 --- a/src/app/user/utils/components/navbar-user/navbar-user.component.ts +++ b/src/app/user/utils/components/navbar-user/navbar-user.component.ts @@ -1,5 +1,7 @@ import {Component} from '@angular/core'; import {Router} from "@angular/router"; +import {ProfilService} from "../../../../utils/services/profil/profil.service"; +import {MessageService} from "../../../../utils/services/message/message.service"; @@ -20,9 +22,20 @@ export class NavbarUserComponent url = this.router.url; - urlImage: string = "https://www.figurines-goodies.com/1185-thickbox_default/huey-duck-tales-disney-funko-pop.jpg" ; + constructor( private router: Router, + public profilService: ProfilService, + private messageService: MessageService ) { } - constructor(private router: Router) { } + onDeconnexion(): void + { + this.messageService + .delete('user/logout', {}) + .subscribe(retour => this.onDeconnexionCallback(retour), err => this.onDeconnexionCallback(err)); + } + + onDeconnexionCallback(retour: any): void + { + console.log(retour); + } - onDeconnexion(): void {} } diff --git a/src/app/utils/services/profil/profil.service.spec.ts b/src/app/utils/services/profil/profil.service.spec.ts new file mode 100644 index 0000000..5cee000 --- /dev/null +++ b/src/app/utils/services/profil/profil.service.spec.ts @@ -0,0 +1,16 @@ +import { TestBed } from '@angular/core/testing'; + +import { ProfilService } from './profil.service'; + +describe('ProfilService', () => { + let service: ProfilService; + + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(ProfilService); + }); + + it('should be created', () => { + expect(service).toBeTruthy(); + }); +}); diff --git a/src/app/utils/services/profil/profil.service.ts b/src/app/utils/services/profil/profil.service.ts new file mode 100644 index 0000000..f32dac8 --- /dev/null +++ b/src/app/utils/services/profil/profil.service.ts @@ -0,0 +1,9 @@ +import { Injectable } from '@angular/core'; + +@Injectable({ + providedIn: 'root' +}) +export class ProfilService +{ + public profileImageUrl: string = ""; +}