Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
157 changes: 102 additions & 55 deletions pre-registration-ui/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,61 +1,108 @@
import { Component, OnInit, OnDestroy, HostListener } from '@angular/core';
import { Event as NavigationEvent, Router, NavigationStart } from '@angular/router';
import { filter } from 'rxjs/operators';
import {Component, HostListener, OnDestroy, OnInit} from '@angular/core';
import {Event as NavigationEvent, NavigationStart, Router} from '@angular/router';
import {filter} from 'rxjs/operators';

import { AutoLogoutService } from 'src/app/core/services/auto-logout.service';
import { ConfigService } from './core/services/config.service';
import { Subscription } from 'rxjs';
import {AutoLogoutService} from 'src/app/core/services/auto-logout.service';
import {ConfigService} from './core/services/config.service';
import {Subscription} from 'rxjs';

@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit, OnDestroy {
title = 'pre-registration';
message: object;
subscriptions: Subscription[] = [];

constructor(private autoLogout: AutoLogoutService, private router: Router, private configService: ConfigService) {}

ngOnInit() {
this.subscriptions.push(this.autoLogout.currentMessageAutoLogout.subscribe(() => {
// This is intentional
}));
this.autoLogout.changeMessage({ timerFired: false });
this.routerType();
}

routerType() {
this.subscriptions.push(
this.router.events
.pipe(filter((event: NavigationEvent) => event instanceof NavigationStart))
.subscribe((event: NavigationStart) => {
if (event.restoredState) {
// This is intentional
}
})
);
}

// preventBack() {
// window.history.forward();
// window.onunload = function() {
// null;
// console.log("Hello")
// };
// }

@HostListener('mouseover')
@HostListener('document:mousemove', ['$event'])
@HostListener('keypress')
@HostListener('click')
@HostListener('document:keypress', ['$event'])
onMouseClick() {
this.autoLogout.setisActive(true);
}

ngOnDestroy(): void {
this.subscriptions.forEach(subscription => subscription.unsubscribe());
}
title = 'pre-registration';
message: object;
subscriptions: Subscription[] = [];

constructor(private autoLogout: AutoLogoutService, private router: Router, private configService: ConfigService) {
}

ngOnInit() {
this.subscriptions.push(this.autoLogout.currentMessageAutoLogout.subscribe(() => {
// This is intentional
}));
this.autoLogout.changeMessage({timerFired: false});
this.routerType();
}

routerType() {
this.subscriptions.push(
this.router.events
.pipe(filter((event: NavigationEvent) => event instanceof NavigationStart))
.subscribe((event: NavigationStart) => {
if (event.restoredState) {
// This is intentional
}
})
);
}

// preventBack() {
// window.history.forward();
// window.onunload = function() {
// null;
// console.log("Hello")
// };
// }

@HostListener('mouseover')
@HostListener('document:mousemove', ['$event'])
@HostListener('keypress')
@HostListener('click')
@HostListener('document:keypress', ['$event'])
onMouseClick() {
this.autoLogout.setisActive(true);
this.updateLastActionTimestamp(); // Added as part of MOSIP-37079
}


@HostListener('window:load', ['$event'])
@HostListener('document:visibilitychange', ['$event'])
@HostListener('window:beforeunload', ['$event'])
onVisibilityChange(event?: Event) {
console.warn(`Event detected: '${event.type}'.`);
this.onVisibilityChangeCheckSessionHandler(event); // Added as part of MOSIP-37079
}

/**
* @description Detects when the page becomes hidden or visible and validates the session.
* Implemented as part of MOSIP-37079 to handle session timeout when the user switches tabs.
*
* @param event
* @private
*/
private onVisibilityChangeCheckSessionHandler(event?: Event) {
const isHiddenState: boolean = (('beforeunload' === event.type) || ('hidden' === document.visibilityState));
if (isHiddenState) {
this.updateHiddenTimestamp();
} else {
this.autoLogout.validateHiddenState();
}
}

/**
* @description Updates the timestamp of the last user action in sessionStorage.
* Implemented as part of MOSIP-37079 to track user activity for session timeout management.
*/
private updateLastActionTimestamp() {
sessionStorage.setItem('lastActionTimestamp', Date.now().toString());
}

/**
* @description Updates the timestamp of hidden page action in sessionStorage.
* Implemented as part of MOSIP-37079 to track user activity for session timeout management.
*/
private updateHiddenTimestamp() {
let lastActionTimestampValue: string = (sessionStorage.getItem('lastActionTimestamp'));
if (!lastActionTimestampValue) {
lastActionTimestampValue = Date.now().toString();
}
sessionStorage.setItem('hiddenTimestamp', lastActionTimestampValue);
}

ngOnDestroy(): void {
this.subscriptions.forEach(subscription => subscription.unsubscribe());
}
}
39 changes: 23 additions & 16 deletions pre-registration-ui/src/app/core/core.module.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { HTTP_INTERCEPTORS } from '@angular/common/http';
import {NgModule} from '@angular/core';
import {CommonModule} from '@angular/common';
import {HTTP_INTERCEPTORS} from '@angular/common/http';

import { AboutUsComponent } from './about-us/about-us.component';
import { FaqComponent } from './faq/faq.component';
import { HeaderComponent } from './header/header.component';
import { FooterComponent } from './footer/footer.component';
import { ContactComponent } from './contact/contact.component';
import { AppRoutingModule } from '../app-routing.module';
import { SharedModule } from '../shared/shared.module';
import { AuthInterceptorService } from '../shared/auth-interceptor.service';
import {AboutUsComponent} from './about-us/about-us.component';
import {FaqComponent} from './faq/faq.component';
import {HeaderComponent} from './header/header.component';
import {FooterComponent} from './footer/footer.component';
import {ContactComponent} from './contact/contact.component';
import {AppRoutingModule} from '../app-routing.module';
import {SharedModule} from '../shared/shared.module';
import {AuthInterceptorService} from '../shared/auth-interceptor.service';
import {CacheInterceptorService} from "../shared/cache-interceptor.service";

@NgModule({
imports: [CommonModule, AppRoutingModule, SharedModule],
declarations: [HeaderComponent, FooterComponent, AboutUsComponent, FaqComponent, ContactComponent],
exports: [HeaderComponent, FooterComponent, SharedModule],
providers: [{ provide: HTTP_INTERCEPTORS, useClass: AuthInterceptorService, multi: true }]
imports: [CommonModule, AppRoutingModule, SharedModule],
declarations: [HeaderComponent, FooterComponent, AboutUsComponent, FaqComponent, ContactComponent],
exports: [HeaderComponent, FooterComponent, SharedModule],
providers: [
{provide: HTTP_INTERCEPTORS, useClass: AuthInterceptorService, multi: true},
// CacheInterceptorService Added as part of MOSIP-37079 to ensure session data is not restored from cache.
{provide: HTTP_INTERCEPTORS, useClass: CacheInterceptorService, multi: true},
],
})
export class CoreModule {}
export class CoreModule {
}

Loading