Feature 10914: Enforce Password change on First login
* Added NG-UI support to Enforce Password change on First login
* A popup will be opened on First login with current password, new password and confirm password fields
* Once new password is entered, Click apply button
* The popup is closed & redirected to Login page.
* Sign in using the new password.
Change-Id: I9ee6bf923e897b40d06a1781cdd7d044b171c825
Signed-off-by: SANDHYA.JS <sandhya.j@tataelxsi.co.in>
diff --git a/src/services/AuthGuardService.ts b/src/services/AuthGuardService.ts
index 0c8d1e4..2effeca 100644
--- a/src/services/AuthGuardService.ts
+++ b/src/services/AuthGuardService.ts
@@ -22,8 +22,8 @@
import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot } from '@angular/router';
import { AuthenticationService } from 'AuthenticationService';
-import { Observable } from 'rxjs';
-import { map, take } from 'rxjs/operators';
+import { combineLatest, Observable } from 'rxjs';
+import { map } from 'rxjs/operators';
/**
* An Injectable is a class adorned with the @Injectable decorator function.
@@ -45,17 +45,19 @@
* Returns Observable<boolean> if authorized @public
*/
public canActivate(next: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> {
- return this.authService.isLoggedIn
- .pipe(
- take(1),
- map((isLoggedIn: boolean) => {
- if (!isLoggedIn) {
- this.router.navigate(['/login']).catch(() => {
- //TODO: Handle error notification
- });
- }
+ return combineLatest(
+ this.authService.isLoggedIn,
+ this.authService.isChangePassword
+ ).pipe(
+ map(([isLoggedIn, changePassword]: [boolean, boolean]): boolean => {
+ if (changePassword || isLoggedIn) {
return true;
- })
- );
+ } else {
+ this.router.navigate(['/login']).catch();
+ this.authService.destoryToken();
+ return false;
+ }
+ })
+ );
}
}