connexion avec le back de toutes les pages 'myProfil'

This commit is contained in:
MiharyR 2021-12-11 21:59:15 +01:00
parent 7f6d089f1d
commit 526e5fbbbf
6 changed files with 129 additions and 58 deletions

View file

@ -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;
}
}

View file

@ -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<PopupUpdateAdminComponent>,
@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();
}
}

View file

@ -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)
{

View file

@ -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;
}
}

View file

@ -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<PopupUpdateAdvertiserComponent>,
@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();
}
}

View file

@ -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();
}
}