X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=src%2Fservices%2FAuthenticationService.ts;h=36cf476b8ce3e149dc0bc8a44623e587705e352b;hb=1b17c432991a95035a1732426f0c11db57e511c9;hp=0399c597a8ee944b368277985cecd2cca0c90389;hpb=a9816553feb848341a8c3214861d5479c3688578;p=osm%2FNG-UI.git diff --git a/src/services/AuthenticationService.ts b/src/services/AuthenticationService.ts index 0399c59..36cf476 100644 --- a/src/services/AuthenticationService.ts +++ b/src/services/AuthenticationService.ts @@ -18,6 +18,7 @@ /** * @file Auth service */ +import { isNullOrUndefined } from 'util'; import { HttpHeaders } from '@angular/common/http'; import { Injectable, Injector } from '@angular/core'; import { Router } from '@angular/router'; @@ -27,7 +28,7 @@ import { APIURLHEADER, ERRORDATA } from 'CommonModel'; import { environment } from 'environment'; import { BehaviorSubject, Observable } from 'rxjs'; import { map } from 'rxjs/operators'; -import { isNullOrUndefined } from 'util'; +import { SharedService } from 'SharedService'; import { ProjectModel } from '../models/VNFDModel'; import { RestService } from './RestService'; @@ -76,6 +77,9 @@ export class AuthenticationService { /** handle idle time out service @private */ private idle: Idle; + /** Contains all methods related to shared @private */ + private sharedService: SharedService; + /** create the instance of the component */ constructor(injector: Injector) { this.injector = injector; @@ -83,6 +87,7 @@ export class AuthenticationService { this.restService = this.injector.get(RestService); this.modalService = this.injector.get(NgbModal); this.idle = this.injector.get(Idle); + this.sharedService = this.injector.get(SharedService); if (localStorage.getItem('username') !== null) { this.loggedIn.next(true); this.changePassword.next(false); @@ -181,6 +186,11 @@ export class AuthenticationService { localStorage.setItem('project_id', data.project_id); localStorage.setItem('project', data.project_name); localStorage.setItem('token_state', data.id); + localStorage.setItem('user_id', data.user_id); + localStorage.setItem('user_show', String(data.user_show)); + localStorage.setItem('admin_show', String(data.admin_show)); + localStorage.setItem('last_login', this.sharedService.convertEpochTime(!isNullOrUndefined(data.last_login) ? data.last_login : null)); + localStorage.setItem('failed_count', data.login_count); this.projectName$.next(data.project_name); } /** Destory tokens API response handling @public */ @@ -196,7 +206,9 @@ export class AuthenticationService { localStorage.setItem('token_state', null); localStorage.setItem('osmVersion', osmVersion); this.idle.stop(); - this.router.navigate(['login']).catch(); + this.router.navigate(['login']).catch((): void => { + // Catch Navigation Error + }); } /** * Logout the user & clearing the token. @@ -225,7 +237,9 @@ export class AuthenticationService { if (window.location.pathname === '/changepassword' && localStorage.getItem('username') !== null) { window.history.back(); } else if (window.location.pathname === '/' && localStorage.getItem('firstLogin') === 'true') { - this.router.navigate(['/login']).catch(); + this.router.navigate(['/login']).catch((): void => { + // Catch Navigation Error + }); } } }