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/pages/signup/signup.component.ts b/src/app/pages/signup/signup.component.ts index 6f9d703..5e304c7 100644 --- a/src/app/pages/signup/signup.component.ts +++ b/src/app/pages/signup/signup.component.ts @@ -28,7 +28,7 @@ export class SignupComponent implements OnInit { this.signupForm = new FormGroup({ firstNameFc : new FormControl(''), lastNameFc : new FormControl(''), - emailFc : new FormControl('', [Validators.email, Validators.required, Validators.pattern(/^([\w\.\-_]+)?\w+@[\w-_]+(\.\w+){1,}/igm)]), // chercher une meilleure regex + emailFc : new FormControl('', [Validators.email, Validators.required, Validators.pattern("^([A-Z|a-z|0-9](\.|_){0,1})+[A-Z|a-z|0-9]\@([A-Z|a-z|0-9])+((\.){0,1}[A-Z|a-z|0-9]){2}\.[a-z]{2,3}$")]), // chercher une meilleure regex passwordFc : new FormControl('', [Validators.minLength(8), Validators.required]), roleFc : new FormControl('') }) diff --git a/src/app/services/auth.guard.ts b/src/app/services/auth.guard.ts index 87a7b9e..7974e78 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-not-found']); + 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-not-found']); 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 }) );