connexion avec le back (non testé)
This commit is contained in:
parent
22f6d316b4
commit
6b9a6d7c73
14 changed files with 215 additions and 130 deletions
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
|
|
||||||
<div class="btnContainer">
|
<div class="btnContainer">
|
||||||
<button mat-button class="btnAjouter" (click)="onAdd()">
|
<button mat-button class="btnAjouter" (click)="onCreate()">
|
||||||
<mat-icon>add_circle</mat-icon> Ajouter un utilisateur
|
<mat-icon>add_circle</mat-icon> Ajouter un utilisateur
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
import {AfterViewInit, Component, ViewChild} from '@angular/core';
|
import {AfterViewInit, Component, ViewChild} from '@angular/core';
|
||||||
import {MatTableDataSource} from "@angular/material/table";
|
import {MatTableDataSource} from "@angular/material/table";
|
||||||
import {FictitiousDatasService} from "../../../common/services/fictitiousDatas/fictitious-datas.service";
|
|
||||||
import {MatSort} from "@angular/material/sort";
|
import {MatSort} from "@angular/material/sort";
|
||||||
import {MatPaginator} from "@angular/material/paginator";
|
import {MatPaginator} from "@angular/material/paginator";
|
||||||
import {MatDialog} from "@angular/material/dialog";
|
import {MatDialog} from "@angular/material/dialog";
|
||||||
|
|
@ -8,6 +7,7 @@ import {PopupCreatePersonComponent} from "../popup-create-person/popup-create-pe
|
||||||
import {MatSnackBar} from "@angular/material/snack-bar";
|
import {MatSnackBar} from "@angular/material/snack-bar";
|
||||||
import {PopupUpdatePersonAdminComponent} from "../popup-update-person-admin/popup-update-person-admin.component";
|
import {PopupUpdatePersonAdminComponent} from "../popup-update-person-admin/popup-update-person-admin.component";
|
||||||
import {PopupDeleteProfilComponent} from "../../../common/components/popup-delete-profil/popup-delete-profil.component";
|
import {PopupDeleteProfilComponent} from "../../../common/components/popup-delete-profil/popup-delete-profil.component";
|
||||||
|
import {MessageService} from "../../../common/services/message/message.service";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -25,17 +25,26 @@ export class PageUserListComponent implements AfterViewInit
|
||||||
configSnackBar = { duration: 2000, panelClass: "custom-class" };
|
configSnackBar = { duration: 2000, panelClass: "custom-class" };
|
||||||
|
|
||||||
|
|
||||||
constructor( private fictitiousDatasService: FictitiousDatasService,
|
constructor( private messageService: MessageService,
|
||||||
public dialog: MatDialog,
|
public dialog: MatDialog,
|
||||||
private snackBar: MatSnackBar) { }
|
private snackBar: MatSnackBar) { }
|
||||||
|
|
||||||
|
|
||||||
ngAfterViewInit(): void
|
ngAfterViewInit(): void
|
||||||
{
|
{
|
||||||
// Faux code
|
this.messageService
|
||||||
let tabPerson = this.fictitiousDatasService.getTabPerson(5);
|
.get('users?order_by=nickname')
|
||||||
|
.subscribe(retour => this.ngAfterViewInitCallback(retour), err => this.ngAfterViewInitCallback(err));
|
||||||
|
}
|
||||||
|
|
||||||
// Vrai code ...
|
|
||||||
|
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 => {
|
tabPerson = tabPerson.map( person => {
|
||||||
if(!person.is_admin) return Object.assign(person, {role: "utilisateur"});
|
if(!person.is_admin) return Object.assign(person, {role: "utilisateur"});
|
||||||
else return Object.assign(person, {role: "admin"});
|
else return Object.assign(person, {role: "admin"});
|
||||||
|
|
@ -44,6 +53,7 @@ export class PageUserListComponent implements AfterViewInit
|
||||||
this.dataSource.sort = this.sort;
|
this.dataSource.sort = this.sort;
|
||||||
this.dataSource.paginator = this.paginator;
|
this.dataSource.paginator = this.paginator;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
applyFilter(event: Event)
|
applyFilter(event: Event)
|
||||||
|
|
@ -53,20 +63,21 @@ export class PageUserListComponent implements AfterViewInit
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Appuie sur le bouton "add"
|
// Appuie sur le bouton "create"
|
||||||
onAdd(): void
|
onCreate(): void
|
||||||
{
|
{
|
||||||
const config = { width: '50%' };
|
const config = { width: '50%' };
|
||||||
this.dialog
|
this.dialog
|
||||||
.open(PopupCreatePersonComponent, config)
|
.open(PopupCreatePersonComponent, config)
|
||||||
.afterClosed()
|
.afterClosed()
|
||||||
.subscribe( person => {
|
.subscribe( retour => {
|
||||||
|
|
||||||
if((person === null) || (person === undefined)) {
|
if((retour === null) || (retour === undefined))
|
||||||
|
{
|
||||||
this.snackBar.open( "Opération annulée", "", this.configSnackBar);
|
this.snackBar.open( "Opération annulée", "", this.configSnackBar);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.dataSource.data.push(person);
|
this.dataSource.data.push(retour.data);
|
||||||
this.dataSource.data = this.dataSource.data;
|
this.dataSource.data = this.dataSource.data;
|
||||||
this.dataSource = this.dataSource;
|
this.dataSource = this.dataSource;
|
||||||
this.snackBar.open( "L'utilisateur a bien été créé ✔", "", this.configSnackBar);
|
this.snackBar.open( "L'utilisateur a bien été créé ✔", "", this.configSnackBar);
|
||||||
|
|
@ -85,14 +96,15 @@ export class PageUserListComponent implements AfterViewInit
|
||||||
this.dialog
|
this.dialog
|
||||||
.open(PopupUpdatePersonAdminComponent, config)
|
.open(PopupUpdatePersonAdminComponent, config)
|
||||||
.afterClosed()
|
.afterClosed()
|
||||||
.subscribe( personUpdated => {
|
.subscribe( retour => {
|
||||||
|
|
||||||
if((personUpdated === null) || (personUpdated === undefined)) {
|
if((retour === null) || (retour === undefined))
|
||||||
|
{
|
||||||
this.snackBar.open("Opération annulée", "", this.configSnackBar);
|
this.snackBar.open("Opération annulée", "", this.configSnackBar);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
const index = this.dataSource.data.findIndex( elt => (elt.id === personToUpdate.id));
|
const index = this.dataSource.data.findIndex( elt => (elt.id === personToUpdate.id));
|
||||||
this.dataSource.data.splice(index, 1, personUpdated);
|
this.dataSource.data.splice(index, 1, retour.data);
|
||||||
this.dataSource.data = this.dataSource.data;
|
this.dataSource.data = this.dataSource.data;
|
||||||
this.dataSource = this.dataSource;
|
this.dataSource = this.dataSource;
|
||||||
this.snackBar.open("L'utilisateur a bien été modifié ✔", "", this.configSnackBar);
|
this.snackBar.open("L'utilisateur a bien été modifié ✔", "", this.configSnackBar);
|
||||||
|
|
@ -115,11 +127,16 @@ export class PageUserListComponent implements AfterViewInit
|
||||||
this.dialog
|
this.dialog
|
||||||
.open(PopupDeleteProfilComponent, config)
|
.open(PopupDeleteProfilComponent, config)
|
||||||
.afterClosed()
|
.afterClosed()
|
||||||
.subscribe( personUpdated => {
|
.subscribe( retour => {
|
||||||
|
|
||||||
if((personUpdated === null) || (personUpdated === undefined)) {
|
if((retour === null) || (retour === undefined))
|
||||||
|
{
|
||||||
this.snackBar.open("Opération annulée", "", this.configSnackBar);
|
this.snackBar.open("Opération annulée", "", this.configSnackBar);
|
||||||
}
|
}
|
||||||
|
else if(retour.status === "error")
|
||||||
|
{
|
||||||
|
this.snackBar.open(retour.message, "", this.configSnackBar);
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
const index = this.dataSource.data.findIndex( elt => (elt.id === personToDelete.id));
|
const index = this.dataSource.data.findIndex( elt => (elt.id === personToDelete.id));
|
||||||
this.dataSource.data.splice(index, 1);
|
this.dataSource.data.splice(index, 1);
|
||||||
|
|
@ -127,7 +144,6 @@ export class PageUserListComponent implements AfterViewInit
|
||||||
this.dataSource = this.dataSource;
|
this.dataSource = this.dataSource;
|
||||||
this.snackBar.open("L'utilisateur a bien été supprimé ✔", "", this.configSnackBar);
|
this.snackBar.open("L'utilisateur a bien été supprimé ✔", "", this.configSnackBar);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -52,13 +52,19 @@ export class PopupCreatePersonComponent
|
||||||
// Callback de 'onValider'
|
// Callback de 'onValider'
|
||||||
onValiderCallback(retour: any)
|
onValiderCallback(retour: any)
|
||||||
{
|
{
|
||||||
if(retour.status === 'error')
|
if(retour.status === 'success')
|
||||||
|
{
|
||||||
|
this.dialogRef.close(retour);
|
||||||
|
}
|
||||||
|
else if(retour.status === 'error')
|
||||||
{
|
{
|
||||||
console.log(retour);
|
console.log(retour);
|
||||||
this.dialogRef.close(null);
|
this.errorMessage = retour.message;
|
||||||
|
this.hasError = true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.dialogRef.close(this.person);
|
console.log(retour);
|
||||||
|
this.dialogRef.close(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,7 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Deconnexion -->
|
<!-- Deconnexion -->
|
||||||
<button mat-button class="btnDeconnexion" (click)="onDeconnexion()" routerLink="/">
|
<button mat-button class="btnDeconnexion" (click)="onDeconnexion()" routerLink="/login">
|
||||||
Deconnexion
|
Deconnexion
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
|
|
@ -100,7 +100,7 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Deconnexion -->
|
<!-- Deconnexion -->
|
||||||
<button mat-button class="btnDeconnexion" (click)="onDeconnexion()" routerLink="/">
|
<button mat-button class="btnDeconnexion" (click)="onDeconnexion()" routerLink="/login">
|
||||||
Deconnexion
|
Deconnexion
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import {Component, Input, OnInit} from '@angular/core';
|
import {Component, Input, OnInit} from '@angular/core';
|
||||||
|
import {ProfilService} from "../../services/profil/profil.service";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-navbar',
|
selector: 'app-navbar',
|
||||||
|
|
@ -9,9 +10,14 @@ export class NavbarComponent implements OnInit
|
||||||
{
|
{
|
||||||
@Input() pour = "login";
|
@Input() pour = "login";
|
||||||
|
|
||||||
constructor() { }
|
constructor(private profilService: ProfilService) { }
|
||||||
|
|
||||||
ngOnInit(): void {}
|
ngOnInit(): void {}
|
||||||
|
|
||||||
onDeconnexion(): void {}
|
onDeconnexion(): void
|
||||||
|
{
|
||||||
|
this.profilService.setId(-1);
|
||||||
|
this.profilService.setIsAdmin(false);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,8 @@
|
||||||
<div class="row myRow">
|
<div class="row myRow">
|
||||||
<div class="col-6 myLabel">Rôle:</div>
|
<div class="col-6 myLabel">Rôle:</div>
|
||||||
<div class="col-6 myValue">
|
<div class="col-6 myValue">
|
||||||
<span *ngIf="!person.is_admin">utilisateur</span>
|
<span *ngIf="this.from === 'user'">utilisateur</span>
|
||||||
<span *ngIf="person.is_admin">admin</span>
|
<span *ngIf="this.from === 'admin'">admin</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- boutons -->
|
<!-- boutons -->
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,11 @@ import { Component, OnInit } from '@angular/core';
|
||||||
import {MatDialog} from "@angular/material/dialog";
|
import {MatDialog} from "@angular/material/dialog";
|
||||||
import {MatSnackBar} from "@angular/material/snack-bar";
|
import {MatSnackBar} from "@angular/material/snack-bar";
|
||||||
import {PopupUpdateProfilComponent} from "../popup-update-profil/popup-update-profil.component";
|
import {PopupUpdateProfilComponent} from "../popup-update-profil/popup-update-profil.component";
|
||||||
import {FictitiousDatasService} from "../../services/fictitiousDatas/fictitious-datas.service";
|
|
||||||
import {Router} from "@angular/router";
|
import {Router} from "@angular/router";
|
||||||
import {PopupDeleteProfilComponent} from "../popup-delete-profil/popup-delete-profil.component";
|
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: "",
|
id: "",
|
||||||
nickname: "",
|
nickname: "",
|
||||||
email: "",
|
email: "",
|
||||||
hash_pass: "",
|
|
||||||
is_admin: false,
|
is_admin: false,
|
||||||
};
|
};
|
||||||
from: string = "" ;
|
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 snackBar: MatSnackBar,
|
||||||
private fictitiousDatasService: FictitiousDatasService,
|
|
||||||
private router: Router ) { }
|
private router: Router ) { }
|
||||||
|
|
||||||
|
|
||||||
ngOnInit(): void
|
ngOnInit(): void
|
||||||
{
|
{
|
||||||
// faux code
|
if(this.router.url.startsWith("/user")) this.from = "user" ;
|
||||||
if(this.router.url.startsWith("/user")) {
|
else if(this.router.url.startsWith("/admin")) this.from = "admin" ;
|
||||||
this.person = this.fictitiousDatasService.getUser();
|
|
||||||
this.from = "user" ;
|
let params = new HttpParams()
|
||||||
}
|
params = params.set("order", "");
|
||||||
else if(this.router.url.startsWith("/admin")){
|
params = params.set("id", this.profilService.getId());
|
||||||
this.person = this.fictitiousDatasService.getAdmin();
|
this.messageService
|
||||||
this.from = "admin" ;
|
.get("user", params)
|
||||||
|
.subscribe(ret => this.ngOnInitCallback(ret), err => this.ngOnInitCallback(err));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Vrai code ...
|
|
||||||
|
// 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
|
// Callback de onModifier
|
||||||
onModifierCallback(retour: any): void
|
onModifierCallback(retour: any): void
|
||||||
{
|
{
|
||||||
if((retour === null) || (retour === undefined))
|
if((retour === null) || (retour === undefined)) this.snackBar.open( "Opération annulé", "", this.configSnackbar);
|
||||||
{
|
else if(retour.status === "success") this.person = retour.data;
|
||||||
const config = { duration: 1000, panelClass: "custom-class" };
|
|
||||||
this.snackBar.open( "Opération annulé", "", config);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this.person = retour;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -96,15 +102,9 @@ export class PageProfilComponent implements OnInit
|
||||||
// Callback de onSupprimer
|
// Callback de onSupprimer
|
||||||
onSupprimerCallback(retour: any): void
|
onSupprimerCallback(retour: any): void
|
||||||
{
|
{
|
||||||
if((retour === null) || (retour === undefined))
|
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);
|
||||||
const config = { duration: 1000, panelClass: "custom-class" };
|
else if(retour.status === "success") this.router.navigateByUrl("/login");
|
||||||
this.snackBar.open( "Opération annulé", "", config);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this.router.navigateByUrl("/login");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
import {Component, Inject, OnInit} from '@angular/core';
|
import {Component, Inject, OnInit} from '@angular/core';
|
||||||
import {MAT_DIALOG_DATA, MatDialogRef} from "@angular/material/dialog";
|
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
|
export class PopupDeleteProfilComponent implements OnInit
|
||||||
{
|
{
|
||||||
|
id: number;
|
||||||
me: boolean = false; // on se supprime soi-même
|
me: boolean = false; // on se supprime soi-même
|
||||||
email: string = "";
|
email: string = "";
|
||||||
|
|
||||||
constructor( public dialogRef: MatDialogRef<PopupDeleteProfilComponent>,
|
|
||||||
|
constructor( private messageService: MessageService,
|
||||||
|
public dialogRef: MatDialogRef<PopupDeleteProfilComponent>,
|
||||||
@Inject(MAT_DIALOG_DATA) public data: any ) { }
|
@Inject(MAT_DIALOG_DATA) public data: any ) { }
|
||||||
|
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
|
this.id = this.data.id;
|
||||||
this.me = this.data.me;
|
this.me = this.data.me;
|
||||||
this.email = this.data.email;
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import {Component, Inject, OnInit} from '@angular/core';
|
import {Component, Inject, OnInit} from '@angular/core';
|
||||||
import {MAT_DIALOG_DATA, MatDialogRef} from "@angular/material/dialog";
|
import {MAT_DIALOG_DATA, MatDialogRef} from "@angular/material/dialog";
|
||||||
import {CheckEmailService} from "../../services/checkEmail/check-email.service";
|
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 = "" ;
|
errorMessage: string = "" ;
|
||||||
|
|
||||||
|
|
||||||
constructor( public dialogRef: MatDialogRef<PopupUpdateProfilComponent>,
|
constructor( private checkEmailService: CheckEmailService,
|
||||||
@Inject(MAT_DIALOG_DATA) public data: any,
|
private messageService: MessageService,
|
||||||
private checkEmailService: CheckEmailService,
|
public dialogRef: MatDialogRef<PopupUpdateProfilComponent>,
|
||||||
private hashageService: HashageService ) { }
|
@Inject(MAT_DIALOG_DATA) public data: any ) { }
|
||||||
|
|
||||||
|
|
||||||
ngOnInit(): void
|
ngOnInit(): void
|
||||||
|
|
@ -33,7 +33,6 @@ export class PopupUpdateProfilComponent implements OnInit
|
||||||
id: person.id,
|
id: person.id,
|
||||||
nickname: person.nickname,
|
nickname: person.nickname,
|
||||||
email: person.email,
|
email: person.email,
|
||||||
hash_pass: person.hash_pass,
|
|
||||||
is_admin: person.is_admin
|
is_admin: person.is_admin
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -45,13 +44,14 @@ export class PopupUpdateProfilComponent implements OnInit
|
||||||
this.checkField();
|
this.checkField();
|
||||||
if(!this.hasError)
|
if(!this.hasError)
|
||||||
{
|
{
|
||||||
if(this.changePassword) this.personCopy.hash_pass = this.hashageService.run(this.newPassword);
|
let data: any = {nickname: this.personCopy.nickname};
|
||||||
const data = { user: this.personCopy };
|
if(this.changePassword) data = {
|
||||||
|
nickname: this.personCopy.nickname,
|
||||||
// ...
|
password: this.newPassword
|
||||||
|
};
|
||||||
// Faux code
|
this.messageService
|
||||||
this.onValiderCallback({ status: "success"});
|
.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'
|
// Callback de 'onValider'
|
||||||
onValiderCallback(retour: any)
|
onValiderCallback(retour: any)
|
||||||
{
|
{
|
||||||
if(retour.status === 'error')
|
if(retour.status === "success")
|
||||||
|
{
|
||||||
|
this.dialogRef.close(retour);
|
||||||
|
}
|
||||||
|
else if(retour.status === "error")
|
||||||
{
|
{
|
||||||
console.log(retour);
|
console.log(retour);
|
||||||
this.dialogRef.close(null);
|
this.errorMessage = retour.message;
|
||||||
|
this.hasError = true;
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
console.log(retour);
|
||||||
this.dialogRef.close(this.personCopy);
|
this.dialogRef.close(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ export class MessageService
|
||||||
return this.http.put<any>(urlComplete, data, {withCredentials: true});
|
return this.http.put<any>(urlComplete, data, {withCredentials: true});
|
||||||
}
|
}
|
||||||
|
|
||||||
delete(url: string): Observable<any>
|
delete(url: string, params:HttpParams = new HttpParams()): Observable<any>
|
||||||
{
|
{
|
||||||
const urlComplete = environment.debutUrl + url ;
|
const urlComplete = environment.debutUrl + url ;
|
||||||
return this.http.delete<any>(urlComplete,{withCredentials: true});
|
return this.http.delete<any>(urlComplete,{withCredentials: true});
|
||||||
|
|
|
||||||
|
|
@ -6,10 +6,16 @@ import { Injectable } from '@angular/core';
|
||||||
export class ProfilService
|
export class ProfilService
|
||||||
{
|
{
|
||||||
|
|
||||||
getId(): number | null
|
constructor()
|
||||||
|
{
|
||||||
|
this.setId(-1);
|
||||||
|
this.setIsAdmin(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
getId(): number
|
||||||
{
|
{
|
||||||
let idString = localStorage.getItem('id');
|
let idString = localStorage.getItem('id');
|
||||||
if(idString === null) return null;
|
if(idString === null) return -1;
|
||||||
else return parseInt(idString);
|
else return parseInt(idString);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -43,16 +43,16 @@ export class PageLoginComponent
|
||||||
// Callback de "onSeConnecter"
|
// Callback de "onSeConnecter"
|
||||||
onSeConnecterCallback(retour: any): void
|
onSeConnecterCallback(retour: any): void
|
||||||
{
|
{
|
||||||
console.log(retour);
|
|
||||||
if(retour.status !== "success")
|
if(retour.status !== "success")
|
||||||
{
|
{
|
||||||
|
console.log(retour);
|
||||||
this.errorMessage = retour.message;
|
this.errorMessage = retour.message;
|
||||||
this.hasError = true;
|
this.hasError = true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.profilService.setId(retour.data.id);
|
this.profilService.setId(retour.data.id);
|
||||||
this.profilService.setIsAdmin(retour.data.is_admin)
|
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');
|
else this.router.navigateByUrl('user/userList');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import {Router} from "@angular/router";
|
||||||
import {CheckEmailService} from "../../common/services/checkEmail/check-email.service";
|
import {CheckEmailService} from "../../common/services/checkEmail/check-email.service";
|
||||||
import {MatDialog} from "@angular/material/dialog";
|
import {MatDialog} from "@angular/material/dialog";
|
||||||
import {PopupConfirmRegisterComponent} from "../popup-confirm-register/popup-confirm-register.component";
|
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 = "";
|
errorMessage: string = "";
|
||||||
|
|
||||||
|
|
||||||
constructor( private hashageService: HashageService,
|
constructor( private checkEmailService: CheckEmailService,
|
||||||
private checkEmailService: CheckEmailService,
|
private messageService: MessageService,
|
||||||
private router: Router,
|
private router: Router,
|
||||||
public dialog: MatDialog ) { }
|
public dialog: MatDialog ) { }
|
||||||
|
|
||||||
|
|
@ -39,18 +40,14 @@ export class PageRegisterComponent
|
||||||
this.checkField();
|
this.checkField();
|
||||||
if(!this.hasError)
|
if(!this.hasError)
|
||||||
{
|
{
|
||||||
this.person.hash_pass = this.hashageService.run(this.password);
|
const data = {
|
||||||
|
email: this.person.email,
|
||||||
// FAUX CODE
|
nickname: this.person.nickname,
|
||||||
const retour = { status: "succes", data: {} };
|
is_admin: false
|
||||||
this.onValiderCallback(retour);
|
};
|
||||||
|
|
||||||
// VRAI CODE
|
|
||||||
/*
|
|
||||||
this.messageService
|
this.messageService
|
||||||
.sendMessage('register', this.user)
|
.post('register', data)
|
||||||
.subscribe(retour => this.onValiderCallback(retour));
|
.subscribe( retour => this.onValiderCallback(retour), err => this.onValiderCallback(err));
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -58,16 +55,17 @@ export class PageRegisterComponent
|
||||||
// Callback de "onValider"
|
// Callback de "onValider"
|
||||||
onValiderCallback(retour: any): void
|
onValiderCallback(retour: any): void
|
||||||
{
|
{
|
||||||
if(retour.status === "error")
|
if(retour.status !== "success")
|
||||||
{
|
{
|
||||||
console.log(retour);
|
console.log(retour);
|
||||||
|
this.errorMessage = retour.message;
|
||||||
|
this.hasError = true;
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
this.dialog
|
this.dialog
|
||||||
.open(PopupConfirmRegisterComponent, {})
|
.open(PopupConfirmRegisterComponent, {})
|
||||||
.afterClosed()
|
.afterClosed()
|
||||||
.subscribe(retour => this.router.navigateByUrl("/"));
|
.subscribe(retour => this.router.navigateByUrl("/login"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,7 @@ import {AfterViewInit, Component, ViewChild} from '@angular/core';
|
||||||
import {MatTableDataSource} from "@angular/material/table";
|
import {MatTableDataSource} from "@angular/material/table";
|
||||||
import {MatSort} from "@angular/material/sort";
|
import {MatSort} from "@angular/material/sort";
|
||||||
import {MatPaginator} from "@angular/material/paginator";
|
import {MatPaginator} from "@angular/material/paginator";
|
||||||
import {FictitiousDatasService} from "../../common/services/fictitiousDatas/fictitious-datas.service";
|
import {MessageService} from "../../common/services/message/message.service";
|
||||||
import {MatDialog} from "@angular/material/dialog";
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -15,22 +14,29 @@ import {MatDialog} from "@angular/material/dialog";
|
||||||
export class PageRegistryComponent implements AfterViewInit
|
export class PageRegistryComponent implements AfterViewInit
|
||||||
{
|
{
|
||||||
displayedColumns: string[] = [ "nickname", "email", "role" ];
|
displayedColumns: string[] = [ "nickname", "email", "role" ];
|
||||||
dataSource: MatTableDataSource<any>;
|
dataSource: MatTableDataSource<any> = new MatTableDataSource<any>();
|
||||||
@ViewChild(MatSort) sort: MatSort;
|
@ViewChild(MatSort) sort: MatSort;
|
||||||
@ViewChild(MatPaginator) paginator: MatPaginator;
|
@ViewChild(MatPaginator) paginator: MatPaginator;
|
||||||
|
|
||||||
|
|
||||||
constructor( private fictitiousDatasService: FictitiousDatasService,
|
constructor( private messageService: MessageService ) { }
|
||||||
public dialog: MatDialog ) { }
|
|
||||||
|
|
||||||
|
|
||||||
ngAfterViewInit(): void
|
ngAfterViewInit(): void
|
||||||
{
|
{
|
||||||
// Faux code
|
this.messageService
|
||||||
let tabPerson = this.fictitiousDatasService.getTabPerson(5);
|
.get('users?order_by=nickname')
|
||||||
|
.subscribe(retour => this.ngAfterViewInitCallback(retour), err => this.ngAfterViewInitCallback(err));
|
||||||
|
}
|
||||||
|
|
||||||
// Vrai code ...
|
|
||||||
|
|
||||||
|
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 => {
|
tabPerson = tabPerson.map( person => {
|
||||||
if(!person.is_admin) return Object.assign(person, {role: "utilisateur"});
|
if(!person.is_admin) return Object.assign(person, {role: "utilisateur"});
|
||||||
else return Object.assign(person, {role: "admin"});
|
else return Object.assign(person, {role: "admin"});
|
||||||
|
|
@ -39,9 +45,10 @@ export class PageRegistryComponent implements AfterViewInit
|
||||||
this.dataSource.sort = this.sort;
|
this.dataSource.sort = this.sort;
|
||||||
this.dataSource.paginator = this.paginator;
|
this.dataSource.paginator = this.paginator;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
applyFilter(event: Event)
|
applyFilter(event: Event): void
|
||||||
{
|
{
|
||||||
const filterValue = (event.target as HTMLInputElement).value;
|
const filterValue = (event.target as HTMLInputElement).value;
|
||||||
this.dataSource.filter = filterValue.trim().toLowerCase();
|
this.dataSource.filter = filterValue.trim().toLowerCase();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue