From 52474e7709f325bc4b6250190a20e98f7602fabf Mon Sep 17 00:00:00 2001 From: "SANDHYA.JS" Date: Mon, 10 Jun 2024 21:47:25 +0530 Subject: [PATCH] Fix Bug 2380:Static Inactive session timeout for a user - Backend will sharing timeout data through api. will store it in sessionstorage & using it in NGUI - To avoid runtime issues, if did'nt get data from api added constant value as 1200 Change-Id: Id00fced3ce26d9f9364d58a0d01ecef891f91262 Signed-off-by: SANDHYA.JS --- src/app/AppComponent.ts | 10 ++++++++-- src/models/VNFDModel.ts | 1 + src/services/AuthenticationService.ts | 7 ++++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/app/AppComponent.ts b/src/app/AppComponent.ts index 26d7aab..0571014 100644 --- a/src/app/AppComponent.ts +++ b/src/app/AppComponent.ts @@ -37,6 +37,8 @@ import { SharedService, isNullOrUndefined } from 'SharedService'; }) /** Exporting a class @exports AppComponent */ export class AppComponent { + /** Handle idle time out @public */ + public idleTime: number; /** To inject services @public */ public injector: Injector; /** Instance for modal service @public */ @@ -69,10 +71,14 @@ export class AppComponent { /** To handle handleIdle @public */ public handleIdle(): void { - const idleTime: number = 1200; + if (!isNullOrUndefined((sessionStorage.getItem('timeout')))) { + this.idleTime = Number(sessionStorage.getItem('timeout')); + } else { + this.idleTime = 1200; + } const idleTimeOutWarning: number = 5; // sets an idle timeout in seconds. - this.idle.setIdle(idleTime); + this.idle.setIdle(this.idleTime); //sets a timeout period in seconds. after idleTime seconds of inactivity, the user will be considered timed out. this.idle.setTimeout(idleTimeOutWarning); // sets the default interrupts, in this case, things like clicks, scrolls, touches to the document diff --git a/src/models/VNFDModel.ts b/src/models/VNFDModel.ts index 530ba48..9072431 100644 --- a/src/models/VNFDModel.ts +++ b/src/models/VNFDModel.ts @@ -38,6 +38,7 @@ export interface ProjectModel { login_count?: string; user_show?: boolean; admin_show?: boolean; + timeout?: string; } /** Interface for Roles */ diff --git a/src/services/AuthenticationService.ts b/src/services/AuthenticationService.ts index e839f75..9b0f525 100644 --- a/src/services/AuthenticationService.ts +++ b/src/services/AuthenticationService.ts @@ -189,6 +189,9 @@ export class AuthenticationService { /** set local storage on auth process @public */ public setLocalStorage(data: ProjectModel): void { + if (!isNullOrUndefined(data.timeout)) { + sessionStorage.setItem('timeout', data.timeout); + } sessionStorage.setItem('id_token', data.id); sessionStorage.setItem('expires', data.expires.toString()); sessionStorage.setItem('username', data.username); @@ -209,12 +212,14 @@ export class AuthenticationService { this.changePassword.next(false); const langCode: string = sessionStorage.getItem('languageCode'); const redirecturl: string = isNullOrUndefined(sessionStorage.getItem('returnUrl')) ? '/' : sessionStorage.getItem('returnUrl'); - const osmVersion: string = isNullOrUndefined(sessionStorage.getItem('version')) ? '' : sessionStorage.getItem('version'); + const osmVersion: string = isNullOrUndefined(sessionStorage.getItem('osmVersion')) ? '' : sessionStorage.getItem('osmVersion'); + const timeOut: string = isNullOrUndefined(sessionStorage.getItem('timeout')) ? '1200' : sessionStorage.getItem('timeout'); sessionStorage.clear(); sessionStorage.setItem('languageCode', langCode); sessionStorage.setItem('returnUrl', redirecturl); sessionStorage.setItem('token_state', null); sessionStorage.setItem('osmVersion', osmVersion); + sessionStorage.setItem('timeout', timeOut); this.idle.stop(); this.router.navigate(['login']).catch((): void => { // Catch Navigation Error -- 2.25.1