diff --git a/src/app/admin-component/add-restau/add-restau.component.ts b/src/app/admin-component/add-restau/add-restau.component.ts index 0b1921a..9f86c08 100644 --- a/src/app/admin-component/add-restau/add-restau.component.ts +++ b/src/app/admin-component/add-restau/add-restau.component.ts @@ -72,7 +72,7 @@ export class AddRestauComponent implements OnInit { latitudeFc: new FormControl(restau.latitude, [Validators.required]), adresseFc: new FormControl(restau.adresse, [Validators.required]), telephoneFc: new FormControl(restau.telephone), - websiteFc: new FormControl(restau.website, [Validators.pattern("/^(http[s]?:\/\/){0,1}(www\.){0,1}[a-zA-Z0-9\.\-]+\.[a-zA-Z]{2,5}[\.]{0,1}/")]), + websiteFc: new FormControl(restau.website, [Validators.pattern("/^(http[s]?:\/\/){0,1}(www\.){0,1}[a-zA-Z0-9\.\-]+\.[a-zA-Z]{2,5}[\.]{0,1}/")]), // voir une autre regex surPlaceFc: new FormControl(restau.surPlace), aEmporterFc: new FormControl(restau.aEmporter), accesPMRFc: new FormControl(restau.accesPMR), diff --git a/src/app/services/auth.guard.ts b/src/app/services/auth.guard.ts index 0d34584..b81deeb 100644 --- a/src/app/services/auth.guard.ts +++ b/src/app/services/auth.guard.ts @@ -24,11 +24,6 @@ export class AuthGuard implements CanActivate { if(token) { const decodedToken = jwt_decode(token); - - // TODO boucle sur le ['auth'] pour controler le role et en fonction de ca renvoyer true ou false ac redirection page403 - //console.log(decodedToken['auth'][0]['authority']); - - console.log('decodedToken : ', decodedToken); @@ -42,8 +37,14 @@ export class AuthGuard implements CanActivate { return false; } - if(route.data['ROLE'] && route.data['ROLE'] != localStorage.getItem('ROLE')){ - this.router.navigate(['page-denied']); + if(route.data['ROLE'] ){ + for (let index = 0; index < decodedToken['auth'].length; index++) { + if(route.data['ROLE'] == decodedToken['auth'][index]['authority']){ + return true; + } + } + + this.router.navigate(['page-denied']); return false; } } diff --git a/src/app/services/auth.service.ts b/src/app/services/auth.service.ts index 0ffb722..986f9ee 100644 --- a/src/app/services/auth.service.ts +++ b/src/app/services/auth.service.ts @@ -36,12 +36,9 @@ export class AuthService { map((x: any) => { //console.log(x); - const decodedToken = jwt_decode(x.token); //console.log('Service : ', x.token); // Modification à faire ici localStorage.setItem(this.tokenKey, x.token); - - localStorage.setItem('ROLE', decodedToken['auth'][0]['authority']); return x; // permet de renvoyer la réponse à l'initiateur (page Signin) après le traitement du map }) );