diff --git a/src/app/admin/myProfil/page-profil-admin/page-profil-admin.component.ts b/src/app/admin/myProfil/page-profil-admin/page-profil-admin.component.ts index 33998a6..f6199c9 100644 --- a/src/app/admin/myProfil/page-profil-admin/page-profil-admin.component.ts +++ b/src/app/admin/myProfil/page-profil-admin/page-profil-admin.component.ts @@ -4,7 +4,8 @@ import {ThemeService} from "../../../utils/services/theme/theme.service"; import {MatDialog} from "@angular/material/dialog"; import {MatSnackBar} from "@angular/material/snack-bar"; import {PopupUpdateAdminComponent} from "../popup-update-admin/popup-update-admin.component"; -import {FictitiousUsersService} from "../../../utils/services/fictitiousDatas/fictitiousUsers/fictitious-users.service"; +import {MessageService} from "../../../utils/services/message/message.service"; +import {ProfilService} from "../../../utils/services/profil/profil.service"; @@ -15,19 +16,52 @@ import {FictitiousUsersService} from "../../../utils/services/fictitiousDatas/fi }) export class PageProfilAdminComponent implements OnInit { - - admin: User; + admin: User = { + _id: "", + login: "", + hashPass: "", + email: "", + role: { + name: "admin", + permission: 10, + }, + profileImageUrl: "", + dateOfBirth: null, + gender: "man", + interests: [], + company: "", + isActive: false, + isAccepted: false, + createdAt: new Date(), + updatedAt: new Date(), + lastConnexion: null + }; constructor( public themeService: ThemeService, - private fictitiousUsersService: FictitiousUsersService, public dialog: MatDialog, - private snackBar: MatSnackBar ) { } + private snackBar: MatSnackBar, + private messageService: MessageService, + private profilService: ProfilService ) { } ngOnInit(): void { - this.admin = this.fictitiousUsersService.getAdmin(); + this.messageService + .get( "user/findOne/"+this.profilService.id) + .subscribe( retour => this.ngOnInitCallback(retour), err => this.ngOnInitCallback(err) ) + } + + + ngOnInitCallback(retour: any) + { + if(retour.status !== "success") { + console.log(retour); + } + else { + this.admin = retour.data; + this.profilService.id = retour.data.id; + } } diff --git a/src/app/admin/myProfil/popup-update-admin/popup-update-admin.component.ts b/src/app/admin/myProfil/popup-update-admin/popup-update-admin.component.ts index 3ae595b..8ca8996 100644 --- a/src/app/admin/myProfil/popup-update-admin/popup-update-admin.component.ts +++ b/src/app/admin/myProfil/popup-update-admin/popup-update-admin.component.ts @@ -1,6 +1,8 @@ import {Component, Inject, OnInit} from '@angular/core'; import {User} from "../../../utils/interfaces/user"; import {MAT_DIALOG_DATA, MatDialogRef} from "@angular/material/dialog"; +import {MessageService} from "../../../utils/services/message/message.service"; +import {ProfilService} from "../../../utils/services/profil/profil.service"; @@ -20,7 +22,9 @@ export class PopupUpdateAdminComponent implements OnInit constructor( public dialogRef: MatDialogRef, - @Inject(MAT_DIALOG_DATA) public data) { } + @Inject(MAT_DIALOG_DATA) public data, + private messageService: MessageService, + private profilService: ProfilService ) { } ngOnInit(): void @@ -55,11 +59,27 @@ export class PopupUpdateAdminComponent implements OnInit this.checkField(); if(!this.hasError) { - if(this.changePassword) this.adminCopy.hashPass = this.hashage(this.newPassword); - const data = { user: this.adminCopy }; + if(this.changePassword) this.adminCopy.hashPass = this.newPassword; + const data = { + login: this.adminCopy.login, + hashPass: this.adminCopy.hashPass, + email: this.adminCopy.email, + profileImageUrl: this.adminCopy.profileImageUrl, + }; + this.messageService + .put("user/update/"+this.profilService.id, data) + .subscribe( ret => this.onValiderCallback(ret), err => this.onValiderCallback(err) ); + } + } - // VRAI CODE: envoie au back ... + onValiderCallback(retour: any) + { + if(retour.status !== "success") { + console.log(retour); + this.dialogRef.close(null); + } + else { this.dialogRef.close(this.adminCopy); } } @@ -100,17 +120,4 @@ export class PopupUpdateAdminComponent implements OnInit return re.test(email); } - - // 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/advertiser/adList/page-ad-list-advertiser/page-ad-list-advertiser.component.ts b/src/app/advertiser/adList/page-ad-list-advertiser/page-ad-list-advertiser.component.ts index 6b3306b..37ff560 100644 --- a/src/app/advertiser/adList/page-ad-list-advertiser/page-ad-list-advertiser.component.ts +++ b/src/app/advertiser/adList/page-ad-list-advertiser/page-ad-list-advertiser.component.ts @@ -168,7 +168,6 @@ export class PageAdListAdvertiserComponent implements AfterViewInit onFilter(): void { - console.log("b:" + this.formControlInterests.value); this.dataSource.data = []; for(let advert of this.tabAdvertWithCountViews) { diff --git a/src/app/advertiser/myProfil/page-profil-advertiser/page-profil-advertiser.component.ts b/src/app/advertiser/myProfil/page-profil-advertiser/page-profil-advertiser.component.ts index 671ce53..1213210 100644 --- a/src/app/advertiser/myProfil/page-profil-advertiser/page-profil-advertiser.component.ts +++ b/src/app/advertiser/myProfil/page-profil-advertiser/page-profil-advertiser.component.ts @@ -4,7 +4,8 @@ import {ThemeService} from "../../../utils/services/theme/theme.service"; import {MatDialog} from "@angular/material/dialog"; import {MatSnackBar} from "@angular/material/snack-bar"; import {PopupUpdateAdvertiserComponent} from "../popup-update-advertiser/popup-update-advertiser.component"; -import {FictitiousUsersService} from "../../../utils/services/fictitiousDatas/fictitiousUsers/fictitious-users.service"; +import {MessageService} from "../../../utils/services/message/message.service"; +import {ProfilService} from "../../../utils/services/profil/profil.service"; @@ -15,18 +16,52 @@ import {FictitiousUsersService} from "../../../utils/services/fictitiousDatas/fi }) export class PageProfilAdvertiserComponent implements OnInit { - advertiser: User; + advertiser: User = { + _id: "", + login: "", + hashPass: "", + email: "", + role: { + name: "advertiser", + permission: 5, + }, + profileImageUrl: "", + dateOfBirth: null, + gender: "man", + interests: [], + company: "", + isActive: false, + isAccepted: false, + createdAt: new Date(), + updatedAt: new Date(), + lastConnexion: null + }; constructor( public themeService: ThemeService, - private fictitiousUsersService: FictitiousUsersService, public dialog: MatDialog, - private snackBar: MatSnackBar ) { } + private snackBar: MatSnackBar, + private messageService: MessageService, + private profilService: ProfilService ) { } ngOnInit(): void { - this.advertiser = this.fictitiousUsersService.getAdvertiser(); + this.messageService + .get( "user/findOne/"+this.profilService.id) + .subscribe( retour => this.ngOnInitCallback(retour), err => this.ngOnInitCallback(err) ) + } + + + ngOnInitCallback(retour: any) + { + if(retour.status !== "success") { + console.log(retour); + } + else { + this.advertiser = retour.data; + this.profilService.id = retour.data.id; + } } diff --git a/src/app/advertiser/myProfil/popup-update-advertiser/popup-update-advertiser.component.ts b/src/app/advertiser/myProfil/popup-update-advertiser/popup-update-advertiser.component.ts index b224472..e32bbc7 100644 --- a/src/app/advertiser/myProfil/popup-update-advertiser/popup-update-advertiser.component.ts +++ b/src/app/advertiser/myProfil/popup-update-advertiser/popup-update-advertiser.component.ts @@ -1,6 +1,8 @@ import {Component, Inject, OnInit} from '@angular/core'; import {User} from "../../../utils/interfaces/user"; import {MAT_DIALOG_DATA, MatDialogRef} from "@angular/material/dialog"; +import {MessageService} from "../../../utils/services/message/message.service"; +import {ProfilService} from "../../../utils/services/profil/profil.service"; @@ -20,7 +22,9 @@ export class PopupUpdateAdvertiserComponent implements OnInit constructor( public dialogRef: MatDialogRef, - @Inject(MAT_DIALOG_DATA) public data) { } + @Inject(MAT_DIALOG_DATA) public data, + private messageService: MessageService, + private profilService: ProfilService ) { } ngOnInit(): void @@ -55,11 +59,28 @@ export class PopupUpdateAdvertiserComponent implements OnInit this.checkField(); if(!this.hasError) { - if(this.changePassword) this.advertiserCopy.hashPass = this.hashage(this.newPassword); - const data = { user: this.advertiserCopy }; + if(this.changePassword) this.advertiserCopy.hashPass = this.newPassword; + const data = { + login: this.advertiserCopy.login, + hashPass: this.advertiserCopy.hashPass, + email: this.advertiserCopy.email, + profileImageUrl: this.advertiserCopy.profileImageUrl, + company: this.advertiserCopy.company + }; + this.messageService + .put("user/update/"+this.profilService.id, data) + .subscribe( ret => this.onValiderCallback(ret), err => this.onValiderCallback(err) ); + } + } - // VRAI CODE: envoie au back ... + onValiderCallback(retour: any) + { + if(retour.status !== "success") { + console.log(retour); + this.dialogRef.close(null); + } + else { this.dialogRef.close(this.advertiserCopy); } } @@ -100,16 +121,4 @@ export class PopupUpdateAdvertiserComponent implements OnInit return re.test(email); } - - // 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/login/page-login/page-login.component.ts b/src/app/beforeConnexion/login/page-login/page-login.component.ts index ad2f03b..f864ee6 100644 --- a/src/app/beforeConnexion/login/page-login/page-login.component.ts +++ b/src/app/beforeConnexion/login/page-login/page-login.component.ts @@ -98,17 +98,4 @@ export class PageLoginComponent implements OnInit } } - - // 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(); - } - }