diff --git a/src/app/config/auth-constants.ts b/src/app/config/auth-constants.ts index 4cee9ccc0..e6769cfd5 100644 --- a/src/app/config/auth-constants.ts +++ b/src/app/config/auth-constants.ts @@ -3,4 +3,5 @@ export class AuthConnstants{ /* My reference key */ public static readonly AUTH = 'userDataKey'; public static readonly PROFILE = 'profile'; + public static readonly USER = 'userId'; } \ No newline at end of file diff --git a/src/app/pages/events/events.page.ts b/src/app/pages/events/events.page.ts index 79128f750..bbefc65d6 100644 --- a/src/app/pages/events/events.page.ts +++ b/src/app/pages/events/events.page.ts @@ -99,6 +99,11 @@ export class EventsPage implements OnInit { } */ + this.storageService.get(AuthConnstants.USER).then(res=>{ + console.log(res); + + }); + this.showGreeting(); this.router.events.forEach((event) => { diff --git a/src/app/services/auth.service.ts b/src/app/services/auth.service.ts index bdb4ca88e..9529f4bb1 100644 --- a/src/app/services/auth.service.ts +++ b/src/app/services/auth.service.ts @@ -13,12 +13,17 @@ import { AuthConnstants } from '../config/auth-constants'; }) export class AuthService { userData$ = new BehaviorSubject(''); + userId$ = new BehaviorSubject(''); + headers: HttpHeaders; + opts:any; constructor( private http: HttpClient, private httpService: HttpService, private storageService:StorageService, private router:Router - ) { } + ) { + this.headers = new HttpHeaders(); + } public ValidatedUser:User; @@ -26,11 +31,21 @@ export class AuthService { user.BasicAuthKey = 'Basic ' + btoa(user.domainName + '\\' + user.username + ':' + user.password); //conversão em base64 das credenciais inseridas const options = { headers: {'Authorization': user.BasicAuthKey }}; + this.headers = this.headers.set('Authorization',user.BasicAuthKey); + this.opts = { + headers: this.headers, + } const service = environment.apiURL + "userauthentication/GetValidateAuth"; let result: boolean | PromiseLike; + let response: any; result = await this.http.get(service, options).toPromise(); + this.http.post(environment.apiURL + "UserAuthentication/Login", '', this.opts).subscribe(res=>{ + this.storageService.store(AuthConnstants.USER, res); + }); + + if (result) { @@ -56,6 +71,12 @@ export class AuthService { this.userData$.next(res); }); } + //Get user Id | global object + getUserId(){ + this.storageService.get(AuthConnstants.USER).then(res=>{ + this.userId$.next(res); + }); + } getProfile(){ this.storageService.get(AuthConnstants.PROFILE).then(res=>{