From a9816553feb848341a8c3214861d5479c3688578 Mon Sep 17 00:00:00 2001 From: "SANDHYA.JS" Date: Tue, 12 Apr 2022 09:07:08 +0530 Subject: [PATCH] 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 --- src/app/AppModule.ts | 13 +- src/app/approutes.module.ts | 6 + src/app/login/LoginComponent.ts | 42 ++++- src/app/users/UsersModule.ts | 9 +- .../users/add-user/AddEditUserComponent.html | 146 +++++++++++------- .../users/add-user/AddEditUserComponent.scss | 45 +++++- .../users/add-user/AddEditUserComponent.ts | 49 +++++- .../ChangePasswordComponent.html | 18 +++ .../ChangePasswordComponent.scss | 25 +++ .../ChangePasswordComponent.ts | 76 +++++++++ .../change-password/ChangePasswordModule.ts | 42 +++++ src/assets/i18n/de.json | 4 +- src/assets/i18n/en.json | 4 +- src/assets/i18n/es.json | 4 +- src/assets/i18n/pt.json | 4 +- src/models/CommonModel.ts | 1 + src/models/VNFDModel.ts | 2 + src/services/AuthGuardService.ts | 28 ++-- src/services/AuthenticationService.ts | 86 +++++++---- tsconfig.json | 4 +- 20 files changed, 483 insertions(+), 125 deletions(-) create mode 100644 src/app/utilities/change-password/ChangePasswordComponent.html create mode 100644 src/app/utilities/change-password/ChangePasswordComponent.scss create mode 100644 src/app/utilities/change-password/ChangePasswordComponent.ts create mode 100644 src/app/utilities/change-password/ChangePasswordModule.ts diff --git a/src/app/AppModule.ts b/src/app/AppModule.ts index f36b8bf..451e0f1 100644 --- a/src/app/AppModule.ts +++ b/src/app/AppModule.ts @@ -50,6 +50,8 @@ import { NgIdleKeepaliveModule } from '@ng-idle/keepalive'; import { AuthenticationService } from 'AuthenticationService'; import { AuthGuardService } from 'AuthGuardService'; import { BreadcrumbComponent } from 'BreadCrumb'; +import { ChangePasswordComponent } from 'ChangePasswordComponent'; +import { ChangePasswordModule } from 'ChangePasswordModule'; import { ComposePackages } from 'ComposePackages'; import { ConfirmationTopologyComponent } from 'ConfirmationTopology'; import { DeleteComponent } from 'DeleteComponent'; @@ -124,7 +126,8 @@ const customNotifierOptions: NotifierOptions = { SDNControllerActionComponent, SwitchProjectComponent, GoToTopDirective, - ScalingComponent + ScalingComponent, + ChangePasswordComponent ], imports: [ NotifierModule.withConfig(customNotifierOptions), @@ -149,7 +152,8 @@ const customNotifierOptions: NotifierOptions = { RouterModule.forRoot(appRoutes, { useHash: false, relativeLinkResolution: 'legacy' }), NgIdleKeepaliveModule.forRoot(), LoaderModule, - SharedModule + SharedModule, + ChangePasswordModule ], providers: [ { @@ -196,7 +200,8 @@ const customNotifierOptions: NotifierOptions = { PDUInstancesActionComponent, SDNControllerActionComponent, SwitchProjectComponent, - ScalingComponent + ScalingComponent, + ChangePasswordComponent ] }) @@ -225,7 +230,7 @@ export function appInitializerFactory(translate: TranslateService, injector: Inj translate.setDefaultLang('en'); const languageCode: string = localStorage.getItem('languageCode'); if (languageCode !== null && languageCode !== undefined && languageCode !== '') { - await translate.use(languageCode).toPromise().catch(() => { + await translate.use(languageCode).toPromise().catch((): void => { translate.setDefaultLang('en'); }); } else { diff --git a/src/app/approutes.module.ts b/src/app/approutes.module.ts index 6145aae..e75416e 100644 --- a/src/app/approutes.module.ts +++ b/src/app/approutes.module.ts @@ -20,6 +20,7 @@ */ import { Routes } from '@angular/router'; import { AuthGuardService } from 'AuthGuardService'; +import { ChangePasswordComponent } from 'ChangePasswordComponent'; import { LayoutComponent } from 'LayoutComponent'; import { LoginComponent } from 'LoginComponent'; import { PageNotFoundComponent } from 'PageNotFound'; @@ -114,6 +115,11 @@ export const appRoutes: Routes = [ } ] }, + { + path: 'changepassword', + component: ChangePasswordComponent, + canActivate: [AuthGuardService] + }, { path: '**', component: PageNotFoundComponent diff --git a/src/app/login/LoginComponent.ts b/src/app/login/LoginComponent.ts index 2f4f67e..8c6f5a3 100644 --- a/src/app/login/LoginComponent.ts +++ b/src/app/login/LoginComponent.ts @@ -55,6 +55,9 @@ export class LoginComponent implements OnInit { /** Observable Hold the value of subscription @public */ public isLoggedIn$: Observable; + /** Observable Hold the value of subscription @public */ + public isChangePassword$: Observable; + /** contains access token information @public */ public accessToken: string; @@ -70,6 +73,12 @@ export class LoginComponent implements OnInit { /** Contains all methods related to shared @public */ public sharedService: SharedService; + /** contains the loggedIn observable value @public */ + public loggedIn: boolean; + + /** contains the passwordIn observable value @public */ + public changePassword: boolean; + /** Utilizes auth service for any auth operations @private */ private authService: AuthenticationService; @@ -94,11 +103,24 @@ export class LoginComponent implements OnInit { */ public ngOnInit(): void { this.isLoggedIn$ = this.authService.isLoggedIn; - if (this.isLoggedIn$) { - this.router.navigate(['/']).catch(() => { + this.isLoggedIn$.subscribe((res: boolean): void => { + this.loggedIn = res; + }); + if (this.loggedIn === true) { + this.router.navigate(['/']).catch((): void => { // Catch Navigation Error }); } + this.isChangePassword$ = this.authService.isChangePassword; + this.isChangePassword$.subscribe((res: boolean): void => { + this.changePassword = res; + }); + if (this.changePassword === true) { + this.router.navigate(['changepassword']).catch((): void => { + // Catch Navigation Error + }); + } + this.loginForm = this.formBuilder.group({ userName: ['', [Validators.required]], password: ['', [Validators.required]] @@ -117,13 +139,19 @@ export class LoginComponent implements OnInit { this.isLoadingResults = true; this.sharedService.cleanForm(this.loginForm); this.authService.login(this.loginForm.value.userName, this.loginForm.value.password).subscribe( - (data: {}) => { + (data: {}): void => { this.isLoadingResults = false; - this.router.navigate([this.returnUrl]).catch(() => { - // Catch Navigation Error - }); + if (this.changePassword === true && this.loggedIn === false) { + this.router.navigate(['/changepassword']).catch((): void => { + // Catch Navigation Error + }); + } else { + this.router.navigate([this.returnUrl]).catch((): void => { + // Catch Navigation Error + }); + } localStorage.removeItem('returnUrl'); - }, (err: HttpErrorResponse) => { + }, (err: HttpErrorResponse): void => { this.isLoadingResults = false; this.restService.handleError(err, 'post'); }); diff --git a/src/app/users/UsersModule.ts b/src/app/users/UsersModule.ts index 2014c48..8b5f316 100644 --- a/src/app/users/UsersModule.ts +++ b/src/app/users/UsersModule.ts @@ -28,7 +28,7 @@ import { RouterModule, Routes } from '@angular/router'; import { NgbModule } from '@ng-bootstrap/ng-bootstrap'; import { NgSelectModule } from '@ng-select/ng-select'; import { TranslateModule } from '@ngx-translate/core'; -import { AddEditUserComponent } from 'AddEditUserComponent'; +import { ChangePasswordModule } from 'ChangePasswordModule'; import { DataService } from 'DataService'; import { LoaderModule } from 'LoaderModule'; import { Ng2SmartTableModule } from 'ng2-smart-table'; @@ -60,10 +60,11 @@ const routes: Routes = [ */ @NgModule({ imports: [ReactiveFormsModule, FormsModule, CommonModule, HttpClientModule, Ng2SmartTableModule, TranslateModule, - FlexLayoutModule, NgSelectModule, NgbModule, RouterModule.forChild(routes), PagePerRowModule, LoaderModule, PageReloadModule], - declarations: [UsersComponent, UserDetailsComponent, AddEditUserComponent, ProjectRoleComponent], + FlexLayoutModule, NgSelectModule, NgbModule, RouterModule.forChild(routes), PagePerRowModule, LoaderModule, + PageReloadModule, ChangePasswordModule], + declarations: [UsersComponent, UserDetailsComponent, ProjectRoleComponent], providers: [DataService], - entryComponents: [AddEditUserComponent, ProjectRoleComponent] + entryComponents: [ProjectRoleComponent] }) /** Exporting a class @exports UsersModule */ export class UsersModule { diff --git a/src/app/users/add-user/AddEditUserComponent.html b/src/app/users/add-user/AddEditUserComponent.html index 8c496cc..d3a0b08 100644 --- a/src/app/users/add-user/AddEditUserComponent.html +++ b/src/app/users/add-user/AddEditUserComponent.html @@ -15,75 +15,105 @@ limitations under the License. Author: KUMARAN M (kumaran.m@tataelxsi.co.in), RAJESH S (rajesh.s@tataelxsi.co.in), BARATH KUMAR R (barath.r@tataelxsi.co.in) --> -
- -