Rôle:
- utilisateur
- admin
+ utilisateur
+ admin
diff --git a/frontend/src/app/common/components/page-profil/page-profil.component.ts b/frontend/src/app/common/components/page-profil/page-profil.component.ts
index 90f67bd..f1f8349 100644
--- a/frontend/src/app/common/components/page-profil/page-profil.component.ts
+++ b/frontend/src/app/common/components/page-profil/page-profil.component.ts
@@ -2,9 +2,11 @@ import { Component, OnInit } from '@angular/core';
import {MatDialog} from "@angular/material/dialog";
import {MatSnackBar} from "@angular/material/snack-bar";
import {PopupUpdateProfilComponent} from "../popup-update-profil/popup-update-profil.component";
-import {FictitiousDatasService} from "../../services/fictitiousDatas/fictitious-datas.service";
import {Router} from "@angular/router";
import {PopupDeleteProfilComponent} from "../popup-delete-profil/popup-delete-profil.component";
+import {MessageService} from "../../services/message/message.service";
+import {HttpParams} from "@angular/common/http";
+import {ProfilService} from "../../services/profil/profil.service";
@@ -19,31 +21,42 @@ export class PageProfilComponent implements OnInit
id: "",
nickname: "",
email: "",
- hash_pass: "",
is_admin: false,
};
from: string = "" ;
+ configSnackbar = { duration: 3000, panelClass: "custom-class" };
- constructor( public dialog: MatDialog,
+ constructor( private messageService: MessageService,
+ private profilService: ProfilService,
+ public dialog: MatDialog,
private snackBar: MatSnackBar,
- private fictitiousDatasService: FictitiousDatasService,
private router: Router ) { }
ngOnInit(): void
{
- // faux code
- if(this.router.url.startsWith("/user")) {
- this.person = this.fictitiousDatasService.getUser();
- this.from = "user" ;
- }
- else if(this.router.url.startsWith("/admin")){
- this.person = this.fictitiousDatasService.getAdmin();
- this.from = "admin" ;
- }
+ if(this.router.url.startsWith("/user")) this.from = "user" ;
+ else if(this.router.url.startsWith("/admin")) this.from = "admin" ;
- // Vrai code ...
+ let params = new HttpParams()
+ params = params.set("order", "");
+ params = params.set("id", this.profilService.getId());
+ this.messageService
+ .get("user", params)
+ .subscribe(ret => this.ngOnInitCallback(ret), err => this.ngOnInitCallback(err));
+ }
+
+
+ // Callback de ngOnInit
+ ngOnInitCallback(retour: any): void
+ {
+ if(retour.status !== "success") {
+ console.log(retour);
+ }
+ else {
+ this.person = retour.data[0];
+ }
}
@@ -64,15 +77,8 @@ export class PageProfilComponent implements OnInit
// Callback de onModifier
onModifierCallback(retour: any): void
{
- if((retour === null) || (retour === undefined))
- {
- const config = { duration: 1000, panelClass: "custom-class" };
- this.snackBar.open( "Opération annulé", "", config);
- }
- else
- {
- this.person = retour;
- }
+ if((retour === null) || (retour === undefined)) this.snackBar.open( "Opération annulé", "", this.configSnackbar);
+ else if(retour.status === "success") this.person = retour.data;
}
@@ -96,15 +102,9 @@ export class PageProfilComponent implements OnInit
// Callback de onSupprimer
onSupprimerCallback(retour: any): void
{
- if((retour === null) || (retour === undefined))
- {
- const config = { duration: 1000, panelClass: "custom-class" };
- this.snackBar.open( "Opération annulé", "", config);
- }
- else
- {
- this.router.navigateByUrl("/login");
- }
+ if((retour === null) || (retour === undefined)) this.snackBar.open( "Opération annulé", "", this.configSnackbar);
+ else if(retour.status === "error") this.snackBar.open(retour.message, "", this.configSnackbar);
+ else if(retour.status === "success") this.router.navigateByUrl("/login");
}
}
diff --git a/frontend/src/app/common/components/popup-delete-profil/popup-delete-profil.component.ts b/frontend/src/app/common/components/popup-delete-profil/popup-delete-profil.component.ts
index e5efad8..2b3065a 100644
--- a/frontend/src/app/common/components/popup-delete-profil/popup-delete-profil.component.ts
+++ b/frontend/src/app/common/components/popup-delete-profil/popup-delete-profil.component.ts
@@ -1,5 +1,7 @@
import {Component, Inject, OnInit} from '@angular/core';
import {MAT_DIALOG_DATA, MatDialogRef} from "@angular/material/dialog";
+import {MessageService} from "../../services/message/message.service";
+import {HttpParams} from "@angular/common/http";
@@ -10,19 +12,58 @@ import {MAT_DIALOG_DATA, MatDialogRef} from "@angular/material/dialog";
})
export class PopupDeleteProfilComponent implements OnInit
{
+ id: number;
me: boolean = false; // on se supprime soi-même
email: string = "";
- constructor( public dialogRef: MatDialogRef
,
+
+ constructor( private messageService: MessageService,
+ public dialogRef: MatDialogRef,
@Inject(MAT_DIALOG_DATA) public data: any ) { }
+
ngOnInit(): void {
+ this.id = this.data.id;
this.me = this.data.me;
this.email = this.data.email;
}
- onValider(): void {
- this.dialogRef.close(true);
+
+ // Appuie sur 'valider'
+ onValider(): void
+ {
+ if(this.me)
+ {
+ this.messageService
+ .delete("user/delete")
+ .subscribe(ret => this.onValiderCallback(ret), err => this.onValiderCallback(err));
+ }
+ else {
+ let params = new HttpParams();
+ params = params.set("id", this.id);
+ this.messageService
+ .delete("admin/delete", params)
+ .subscribe(ret => this.onValiderCallback(ret), err => this.onValiderCallback(err));
+ }
+ }
+
+
+ // Callback de onValider
+ onValiderCallback(retour: any): void
+ {
+ if(retour.status === "success")
+ {
+ this.dialogRef.close(retour);
+ }
+ else if(retour.status === "error")
+ {
+ console.log(retour);
+ this.dialogRef.close(retour);
+ }
+ else {
+ console.log(retour);
+ this.dialogRef.close(null);
+ }
}
}
diff --git a/frontend/src/app/common/components/popup-update-profil/popup-update-profil.component.ts b/frontend/src/app/common/components/popup-update-profil/popup-update-profil.component.ts
index 9753ac7..4d92bc2 100644
--- a/frontend/src/app/common/components/popup-update-profil/popup-update-profil.component.ts
+++ b/frontend/src/app/common/components/popup-update-profil/popup-update-profil.component.ts
@@ -1,7 +1,7 @@
import {Component, Inject, OnInit} from '@angular/core';
import {MAT_DIALOG_DATA, MatDialogRef} from "@angular/material/dialog";
import {CheckEmailService} from "../../services/checkEmail/check-email.service";
-import {HashageService} from "../../services/hashage/hashage.service";
+import {MessageService} from "../../services/message/message.service";
@@ -20,10 +20,10 @@ export class PopupUpdateProfilComponent implements OnInit
errorMessage: string = "" ;
- constructor( public dialogRef: MatDialogRef,
- @Inject(MAT_DIALOG_DATA) public data: any,
- private checkEmailService: CheckEmailService,
- private hashageService: HashageService ) { }
+ constructor( private checkEmailService: CheckEmailService,
+ private messageService: MessageService,
+ public dialogRef: MatDialogRef,
+ @Inject(MAT_DIALOG_DATA) public data: any ) { }
ngOnInit(): void
@@ -33,7 +33,6 @@ export class PopupUpdateProfilComponent implements OnInit
id: person.id,
nickname: person.nickname,
email: person.email,
- hash_pass: person.hash_pass,
is_admin: person.is_admin
};
}
@@ -45,13 +44,14 @@ export class PopupUpdateProfilComponent implements OnInit
this.checkField();
if(!this.hasError)
{
- if(this.changePassword) this.personCopy.hash_pass = this.hashageService.run(this.newPassword);
- const data = { user: this.personCopy };
-
- // ...
-
- // Faux code
- this.onValiderCallback({ status: "success"});
+ let data: any = {nickname: this.personCopy.nickname};
+ if(this.changePassword) data = {
+ nickname: this.personCopy.nickname,
+ password: this.newPassword
+ };
+ this.messageService
+ .put("user/update", data)
+ .subscribe(ret => this.onValiderCallback(ret), err => this.onValiderCallback(err));
}
}
@@ -59,14 +59,19 @@ export class PopupUpdateProfilComponent implements OnInit
// Callback de 'onValider'
onValiderCallback(retour: any)
{
- if(retour.status === 'error')
+ if(retour.status === "success")
+ {
+ this.dialogRef.close(retour);
+ }
+ else if(retour.status === "error")
{
console.log(retour);
- this.dialogRef.close(null);
+ this.errorMessage = retour.message;
+ this.hasError = true;
}
- else
- {
- this.dialogRef.close(this.personCopy);
+ else {
+ console.log(retour);
+ this.dialogRef.close(null);
}
}
diff --git a/frontend/src/app/common/services/message/message.service.ts b/frontend/src/app/common/services/message/message.service.ts
index e67dc5a..4c4ec1c 100644
--- a/frontend/src/app/common/services/message/message.service.ts
+++ b/frontend/src/app/common/services/message/message.service.ts
@@ -29,7 +29,7 @@ export class MessageService
return this.http.put(urlComplete, data, {withCredentials: true});
}
- delete(url: string): Observable
+ delete(url: string, params:HttpParams = new HttpParams()): Observable
{
const urlComplete = environment.debutUrl + url ;
return this.http.delete(urlComplete,{withCredentials: true});
diff --git a/frontend/src/app/common/services/profil/profil.service.ts b/frontend/src/app/common/services/profil/profil.service.ts
index 0d209c0..4f1c55a 100644
--- a/frontend/src/app/common/services/profil/profil.service.ts
+++ b/frontend/src/app/common/services/profil/profil.service.ts
@@ -6,10 +6,16 @@ import { Injectable } from '@angular/core';
export class ProfilService
{
- getId(): number | null
+ constructor()
+ {
+ this.setId(-1);
+ this.setIsAdmin(false);
+ }
+
+ getId(): number
{
let idString = localStorage.getItem('id');
- if(idString === null) return null;
+ if(idString === null) return -1;
else return parseInt(idString);
}
diff --git a/frontend/src/app/login/page-login/page-login.component.ts b/frontend/src/app/login/page-login/page-login.component.ts
index 6dbfc62..d855ba1 100644
--- a/frontend/src/app/login/page-login/page-login.component.ts
+++ b/frontend/src/app/login/page-login/page-login.component.ts
@@ -43,16 +43,16 @@ export class PageLoginComponent
// Callback de "onSeConnecter"
onSeConnecterCallback(retour: any): void
{
- console.log(retour);
if(retour.status !== "success")
{
+ console.log(retour);
this.errorMessage = retour.message;
this.hasError = true;
}
else {
this.profilService.setId(retour.data.id);
this.profilService.setIsAdmin(retour.data.is_admin)
- if(!retour.data.is_admin) this.router.navigateByUrl('admin/userList');
+ if(retour.data.is_admin) this.router.navigateByUrl('admin/userList');
else this.router.navigateByUrl('user/userList');
}
}
diff --git a/frontend/src/app/register/page-register/page-register.component.ts b/frontend/src/app/register/page-register/page-register.component.ts
index d3ccf85..6638448 100644
--- a/frontend/src/app/register/page-register/page-register.component.ts
+++ b/frontend/src/app/register/page-register/page-register.component.ts
@@ -4,6 +4,7 @@ import {Router} from "@angular/router";
import {CheckEmailService} from "../../common/services/checkEmail/check-email.service";
import {MatDialog} from "@angular/material/dialog";
import {PopupConfirmRegisterComponent} from "../popup-confirm-register/popup-confirm-register.component";
+import {MessageService} from "../../common/services/message/message.service";
@@ -27,8 +28,8 @@ export class PageRegisterComponent
errorMessage: string = "";
- constructor( private hashageService: HashageService,
- private checkEmailService: CheckEmailService,
+ constructor( private checkEmailService: CheckEmailService,
+ private messageService: MessageService,
private router: Router,
public dialog: MatDialog ) { }
@@ -39,18 +40,14 @@ export class PageRegisterComponent
this.checkField();
if(!this.hasError)
{
- this.person.hash_pass = this.hashageService.run(this.password);
-
- // FAUX CODE
- const retour = { status: "succes", data: {} };
- this.onValiderCallback(retour);
-
- // VRAI CODE
- /*
+ const data = {
+ email: this.person.email,
+ nickname: this.person.nickname,
+ is_admin: false
+ };
this.messageService
- .sendMessage('register', this.user)
- .subscribe(retour => this.onValiderCallback(retour));
- */
+ .post('register', data)
+ .subscribe( retour => this.onValiderCallback(retour), err => this.onValiderCallback(err));
}
}
@@ -58,16 +55,17 @@ export class PageRegisterComponent
// Callback de "onValider"
onValiderCallback(retour: any): void
{
- if(retour.status === "error")
+ if(retour.status !== "success")
{
console.log(retour);
+ this.errorMessage = retour.message;
+ this.hasError = true;
}
- else
- {
+ else {
this.dialog
.open(PopupConfirmRegisterComponent, {})
.afterClosed()
- .subscribe(retour => this.router.navigateByUrl("/"));
+ .subscribe(retour => this.router.navigateByUrl("/login"));
}
}
diff --git a/frontend/src/app/user/page-registry/page-registry.component.ts b/frontend/src/app/user/page-registry/page-registry.component.ts
index 6d0e1b9..6fca3ed 100644
--- a/frontend/src/app/user/page-registry/page-registry.component.ts
+++ b/frontend/src/app/user/page-registry/page-registry.component.ts
@@ -2,8 +2,7 @@ import {AfterViewInit, Component, ViewChild} from '@angular/core';
import {MatTableDataSource} from "@angular/material/table";
import {MatSort} from "@angular/material/sort";
import {MatPaginator} from "@angular/material/paginator";
-import {FictitiousDatasService} from "../../common/services/fictitiousDatas/fictitious-datas.service";
-import {MatDialog} from "@angular/material/dialog";
+import {MessageService} from "../../common/services/message/message.service";
@@ -15,33 +14,41 @@ import {MatDialog} from "@angular/material/dialog";
export class PageRegistryComponent implements AfterViewInit
{
displayedColumns: string[] = [ "nickname", "email", "role" ];
- dataSource: MatTableDataSource;
+ dataSource: MatTableDataSource = new MatTableDataSource();
@ViewChild(MatSort) sort: MatSort;
@ViewChild(MatPaginator) paginator: MatPaginator;
- constructor( private fictitiousDatasService: FictitiousDatasService,
- public dialog: MatDialog ) { }
+ constructor( private messageService: MessageService ) { }
ngAfterViewInit(): void
{
- // Faux code
- let tabPerson = this.fictitiousDatasService.getTabPerson(5);
-
- // Vrai code ...
-
- tabPerson = tabPerson.map( person => {
- if(!person.is_admin) return Object.assign(person, {role: "utilisateur"});
- else return Object.assign(person, {role: "admin"});
- });
- this.dataSource = new MatTableDataSource(tabPerson);
- this.dataSource.sort = this.sort;
- this.dataSource.paginator = this.paginator;
+ this.messageService
+ .get('users?order_by=nickname')
+ .subscribe(retour => this.ngAfterViewInitCallback(retour), err => this.ngAfterViewInitCallback(err));
}
- applyFilter(event: Event)
+ ngAfterViewInitCallback(retour: any): void
+ {
+ if(retour.status !== "success") {
+ console.log(retour);
+ }
+ else {
+ let tabPerson: { id: number, email: string, nickname: string, is_admin: boolean }[] = retour.data;
+ tabPerson = tabPerson.map( person => {
+ if(!person.is_admin) return Object.assign(person, {role: "utilisateur"});
+ else return Object.assign(person, {role: "admin"});
+ });
+ this.dataSource = new MatTableDataSource(tabPerson);
+ this.dataSource.sort = this.sort;
+ this.dataSource.paginator = this.paginator;
+ }
+ }
+
+
+ applyFilter(event: Event): void
{
const filterValue = (event.target as HTMLInputElement).value;
this.dataSource.filter = filterValue.trim().toLowerCase();