@@ -5,40 +5,45 @@ import { Router } from '@angular/router';
55@Injectable ( {
66 providedIn : 'root'
77} )
8+
89export class AppService {
910 // Authentification
10- authenticated = false ;
11+ authenticated = false ;
1112 responseAll : any ;
1213 // Autorisation :
1314 isAdmin = false ;
1415 isGerant = false ;
1516 isClient = false ;
16- constructor ( private httpClient :HttpClient , private router :Router ) { }
17+ // Step 1
18+ idUser : any ;
19+ constructor ( private httpClient : HttpClient , private router : Router ) { }
1720
18- authenticate ( credentials :any , callback :any ) {
21+ authenticate ( credentials : any , callback : any ) {
1922 const headersAgency = new HttpHeaders (
2023 credentials ? {
21- authorization : 'Basic ' + btoa ( credentials . username + ':' + credentials . password )
24+ authorization : 'Basic ' + btoa ( credentials . username + ':' + credentials . password )
2225 } : { }
2326 ) ;
24- this . httpClient . get ( 'http://localhost:8080/login/user' , { headers :headersAgency } ) . subscribe ( response => {
27+ this . httpClient . get ( 'http://localhost:8080/login/user' , { headers : headersAgency } ) . subscribe ( response => {
2528 this . responseAll = response ; // objet = utilisateur
26- console . log ( "responseAll=" + this . responseAll ) ;
27- if ( this . responseAll [ 'username' ] ) {
29+ console . log ( "responseAll=" + this . responseAll ) ;
30+ // Step 2
31+ this . idUser = this . responseAll [ 'idUtilisateur' ] ;
32+ if ( this . responseAll [ 'username' ] ) {
2833 this . authenticated = true ;
2934 // vérification des profils :
30- for ( let i = 0 ; i < this . responseAll [ 'roles' ] . length ; i ++ ) {
31- if ( this . responseAll [ 'roles' ] [ i ] [ 'idRole' ] == 1 ) {
35+ for ( let i = 0 ; i < this . responseAll [ 'roles' ] . length ; i ++ ) {
36+ if ( this . responseAll [ 'roles' ] [ i ] [ 'idRole' ] == 1 ) {
3237 this . isAdmin = true ;
3338 }
34- if ( this . responseAll [ 'roles' ] [ i ] [ 'idRole' ] == 2 ) {
39+ if ( this . responseAll [ 'roles' ] [ i ] [ 'idRole' ] == 2 ) {
3540 this . isGerant = true ;
3641 }
37- if ( this . responseAll [ 'roles' ] [ i ] [ 'idRole' ] == 3 ) {
42+ if ( this . responseAll [ 'roles' ] [ i ] [ 'idRole' ] == 3 ) {
3843 this . isClient = true ;
3944 }
4045 }
41- } else {
46+ } else {
4247 this . authenticated = false ;
4348 }
4449 return callback && callback ( ) ;
0 commit comments