This commit is contained in:
Thomas Cardon 2022-03-10 09:40:46 +01:00
parent a204a18e99
commit 734a7f9068
4 changed files with 10 additions and 12 deletions

View File

@ -72,7 +72,7 @@ export class AddRestauComponent implements OnInit {
latitudeFc: new FormControl(restau.latitude, [Validators.required]), latitudeFc: new FormControl(restau.latitude, [Validators.required]),
adresseFc: new FormControl(restau.adresse, [Validators.required]), adresseFc: new FormControl(restau.adresse, [Validators.required]),
telephoneFc: new FormControl(restau.telephone), 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), surPlaceFc: new FormControl(restau.surPlace),
aEmporterFc: new FormControl(restau.aEmporter), aEmporterFc: new FormControl(restau.aEmporter),
accesPMRFc: new FormControl(restau.accesPMR), accesPMRFc: new FormControl(restau.accesPMR),

View File

@ -28,7 +28,7 @@ export class SignupComponent implements OnInit {
this.signupForm = new FormGroup({ this.signupForm = new FormGroup({
firstNameFc : new FormControl(''), firstNameFc : new FormControl(''),
lastNameFc : 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]), passwordFc : new FormControl('', [Validators.minLength(8), Validators.required]),
roleFc : new FormControl('') roleFc : new FormControl('')
}) })

View File

@ -24,11 +24,6 @@ export class AuthGuard implements CanActivate {
if(token) { if(token) {
const decodedToken = jwt_decode<any>(token); const decodedToken = jwt_decode<any>(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); console.log('decodedToken : ', decodedToken);
@ -42,8 +37,14 @@ export class AuthGuard implements CanActivate {
return false; return false;
} }
if(route.data['ROLE'] && route.data['ROLE'] != localStorage.getItem('ROLE')){ if(route.data['ROLE'] ){
this.router.navigate(['page-not-found']); 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; return false;
} }
} }

View File

@ -36,12 +36,9 @@ export class AuthService {
map((x: any) => { map((x: any) => {
//console.log(x); //console.log(x);
const decodedToken = jwt_decode<any>(x.token);
//console.log('Service : ', x.token); //console.log('Service : ', x.token);
// Modification à faire ici // Modification à faire ici
localStorage.setItem(this.tokenKey, x.token); 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 return x; // permet de renvoyer la réponse à l'initiateur (page Signin) après le traitement du map
}) })
); );