commencement de la connexion avec le back de 'user/myProfil' et de 'user/myPlaylists'
This commit is contained in:
parent
cf3c596c7b
commit
7f6d089f1d
20 changed files with 279 additions and 149 deletions
|
|
@ -6,7 +6,6 @@ import {MessageService} from "../../../utils/services/message/message.service";
|
|||
import {map, startWith} from "rxjs/operators";
|
||||
import {MatChipInputEvent} from "@angular/material/chips";
|
||||
import {MatAutocompleteSelectedEvent} from "@angular/material/autocomplete";
|
||||
import {FictitiousUtilsService} from "../../../utils/services/fictitiousDatas/fictitiousUtils/fictitious-utils.service";
|
||||
|
||||
|
||||
|
||||
|
|
@ -28,8 +27,7 @@ export class InputInterestsProfilComponent implements OnInit
|
|||
@ViewChild('tagInput') tagInput: ElementRef<HTMLInputElement>;
|
||||
|
||||
|
||||
constructor( private fictitiousUtilsService: FictitiousUtilsService,
|
||||
private messageService: MessageService ) {}
|
||||
constructor( private messageService: MessageService ) {}
|
||||
|
||||
|
||||
ngOnInit(): void
|
||||
|
|
@ -38,9 +36,19 @@ export class InputInterestsProfilComponent implements OnInit
|
|||
startWith(null),
|
||||
map((fruit: string | null) => fruit ? this._filter(fruit) : this.allInterests.slice()));
|
||||
|
||||
// --- FAUX CODE ---
|
||||
this.allInterests = this.fictitiousUtilsService.getTags();
|
||||
this.allInterests.sort();
|
||||
this.messageService
|
||||
.get("misc/getInterests")
|
||||
.subscribe( retour => {
|
||||
|
||||
if(retour.status !== "success") {
|
||||
console.log(retour);
|
||||
}
|
||||
else {
|
||||
this.allInterests = [];
|
||||
for(let elt of retour.data) this.allInterests.push(elt.interest);
|
||||
this.allInterests.sort();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@ import {User} from "../../../utils/interfaces/user";
|
|||
import {MatDialog} from "@angular/material/dialog";
|
||||
import {MatSnackBar} from "@angular/material/snack-bar";
|
||||
import {PopupUpdateUserComponent} from "../popup-update-user/popup-update-user.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 PageProfilUserComponent implements OnInit
|
||||
{
|
||||
user: User;
|
||||
user: User = {
|
||||
_id: "",
|
||||
login: "",
|
||||
hashPass: "",
|
||||
email: "",
|
||||
role: {
|
||||
name: "user",
|
||||
permission: 0,
|
||||
},
|
||||
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.user = this.fictitiousUsersService.getUser();
|
||||
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.user = retour.data;
|
||||
this.profilService.id = retour.data.id;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
import {Component, Inject, OnInit} from '@angular/core';
|
||||
import {MAT_DIALOG_DATA, MatDialogRef} from "@angular/material/dialog";
|
||||
import {User} from "../../../utils/interfaces/user";
|
||||
import {MessageService} from "../../../utils/services/message/message.service";
|
||||
import {ProfilService} from "../../../utils/services/profil/profil.service";
|
||||
|
||||
|
||||
|
||||
|
|
@ -20,7 +22,9 @@ export class PopupUpdateUserComponent implements OnInit
|
|||
|
||||
|
||||
constructor( public dialogRef: MatDialogRef<PopupUpdateUserComponent>,
|
||||
@Inject(MAT_DIALOG_DATA) public data) { }
|
||||
@Inject(MAT_DIALOG_DATA) public data,
|
||||
private messageService: MessageService,
|
||||
private profilService: ProfilService ) { }
|
||||
|
||||
|
||||
ngOnInit(): void
|
||||
|
|
@ -55,11 +59,30 @@ export class PopupUpdateUserComponent implements OnInit
|
|||
this.checkField();
|
||||
if(!this.hasError)
|
||||
{
|
||||
if(this.changePassword) this.userCopy.hashPass = this.hashage(this.newPassword);
|
||||
const data = { user: this.userCopy };
|
||||
if(this.changePassword) this.userCopy.hashPass = this.newPassword;
|
||||
const data = {
|
||||
login: this.userCopy.login,
|
||||
hashPass: this.userCopy.hashPass,
|
||||
email: this.userCopy.email,
|
||||
profileImageUrl: this.userCopy.profileImageUrl,
|
||||
dateOfBirth: this.userCopy.dateOfBirth,
|
||||
gender: this.userCopy.gender,
|
||||
interests: this.userCopy.interests,
|
||||
};
|
||||
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.userCopy);
|
||||
}
|
||||
}
|
||||
|
|
@ -106,17 +129,4 @@ export class PopupUpdateUserComponent implements OnInit
|
|||
this.userCopy.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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue