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

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