connexion avec le back
This commit is contained in:
parent
91e4bba793
commit
4620f0dff9
16 changed files with 178 additions and 110 deletions
|
|
@ -40,10 +40,10 @@ export class PageProfilComponent implements OnInit
|
|||
else if(this.router.url.startsWith("/admin")) this.from = "admin" ;
|
||||
|
||||
let params = new HttpParams()
|
||||
params = params.set("order", "");
|
||||
params = params.set("order_by", "nickname");
|
||||
params = params.set("id", this.profilService.getId());
|
||||
this.messageService
|
||||
.get("user", params)
|
||||
.get("users", params)
|
||||
.subscribe(ret => this.ngOnInitCallback(ret), err => this.ngOnInitCallback(err));
|
||||
}
|
||||
|
||||
|
|
@ -103,7 +103,7 @@ export class PageProfilComponent implements OnInit
|
|||
onSupprimerCallback(retour: any): void
|
||||
{
|
||||
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 === "error") this.snackBar.open(retour.error.message, "", this.configSnackbar);
|
||||
else if(retour.status === "success") this.router.navigateByUrl("/login");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -39,10 +39,9 @@ export class PopupDeleteProfilComponent implements OnInit
|
|||
.subscribe(ret => this.onValiderCallback(ret), err => this.onValiderCallback(err));
|
||||
}
|
||||
else {
|
||||
let params = new HttpParams();
|
||||
params = params.set("id", this.id);
|
||||
//let params = (new HttpParams()).set("id", this.id);
|
||||
this.messageService
|
||||
.delete("admin/delete", params)
|
||||
.delete("admin/delete/user/"+this.id)
|
||||
.subscribe(ret => this.onValiderCallback(ret), err => this.onValiderCallback(err));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
16
frontend/src/app/common/guards/admin/admin.guard.spec.ts
Normal file
16
frontend/src/app/common/guards/admin/admin.guard.spec.ts
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { AdminGuard } from './admin.guard';
|
||||
|
||||
describe('AdminGuard', () => {
|
||||
let guard: AdminGuard;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
guard = TestBed.inject(AdminGuard);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(guard).toBeTruthy();
|
||||
});
|
||||
});
|
||||
31
frontend/src/app/common/guards/admin/admin.guard.ts
Normal file
31
frontend/src/app/common/guards/admin/admin.guard.ts
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
import { Injectable } from '@angular/core';
|
||||
import {ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot, UrlTree} from '@angular/router';
|
||||
import { Observable } from 'rxjs';
|
||||
import {ProfilService} from "../../services/profil/profil.service";
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class AdminGuard implements CanActivate
|
||||
{
|
||||
|
||||
constructor(private profilService: ProfilService, private router: Router) {}
|
||||
|
||||
|
||||
canActivate( route: ActivatedRouteSnapshot, state: RouterStateSnapshot ): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree
|
||||
{
|
||||
if(this.profilService.getId() === -1) // si non connecté
|
||||
{
|
||||
this.router.navigateByUrl("/login");
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
if(this.profilService.isAdmin()) return true;
|
||||
else {
|
||||
this.router.navigateByUrl("/login");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
16
frontend/src/app/common/guards/user/user.guard.spec.ts
Normal file
16
frontend/src/app/common/guards/user/user.guard.spec.ts
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { UserGuard } from './user.guard';
|
||||
|
||||
describe('UserGuard', () => {
|
||||
let guard: UserGuard;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
guard = TestBed.inject(UserGuard);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(guard).toBeTruthy();
|
||||
});
|
||||
});
|
||||
31
frontend/src/app/common/guards/user/user.guard.ts
Normal file
31
frontend/src/app/common/guards/user/user.guard.ts
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
import { Injectable } from '@angular/core';
|
||||
import {ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot, UrlTree} from '@angular/router';
|
||||
import { Observable } from 'rxjs';
|
||||
import {ProfilService} from "../../services/profil/profil.service";
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class UserGuard implements CanActivate
|
||||
{
|
||||
|
||||
constructor(private profilService: ProfilService, private router: Router) {}
|
||||
|
||||
|
||||
canActivate( route: ActivatedRouteSnapshot, state: RouterStateSnapshot ): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree
|
||||
{
|
||||
if(this.profilService.getId() === -1) // si non connecté
|
||||
{
|
||||
this.router.navigateByUrl("/login");
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
if(!this.profilService.isAdmin()) return true;
|
||||
else {
|
||||
this.router.navigateByUrl("/login");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -8,8 +8,8 @@ export class ProfilService
|
|||
|
||||
constructor()
|
||||
{
|
||||
this.setId(-1);
|
||||
this.setIsAdmin(false);
|
||||
if(localStorage.getItem('id') === null) this.setId(-1);
|
||||
if(localStorage.getItem('isAdmin') === null) this.setIsAdmin(false);
|
||||
}
|
||||
|
||||
getId(): number
|
||||
|
|
@ -24,7 +24,7 @@ export class ProfilService
|
|||
localStorage.setItem('id', id.toString());
|
||||
}
|
||||
|
||||
getIsAdmin(): boolean
|
||||
isAdmin(): boolean
|
||||
{
|
||||
let isAdminString = localStorage.getItem('isAdmin');
|
||||
if(isAdminString === "T") return true;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue