Fix Bug 2336: Manual Healing option in Ui
[osm/NG-UI.git] / src / app / login / LoginComponent.ts
index db842d8..45573e2 100644 (file)
@@ -126,6 +126,9 @@ export class LoginComponent implements OnInit {
     /** contains the passwordIn observable value @public */
     public changePassword: boolean;
 
+    /** To show the visiblity of password @public */
+    public visiblePassword: boolean;
+
     /** Utilizes auth service for any auth operations @private */
     private authService: AuthenticationService;
 
@@ -195,7 +198,7 @@ export class LoginComponent implements OnInit {
             userName: ['', [Validators.required]],
             password: ['', [Validators.required]]
         });
-        this.returnUrl = isNullOrUndefined(localStorage.getItem('returnUrl')) ? '/' : localStorage.getItem('returnUrl');
+        this.returnUrl = isNullOrUndefined(sessionStorage.getItem('returnUrl')) ? '/' : sessionStorage.getItem('returnUrl');
     }
 
     /**
@@ -227,15 +230,15 @@ export class LoginComponent implements OnInit {
                     this.router.navigate([this.returnUrl]).catch((): void => {
                         // Catch Navigation Error
                     });
-                    this.isAdminShow = localStorage.getItem('admin_show') === 'true' ? true : false;
-                    this.isUserShow = localStorage.getItem('user_show') === 'true' ? true : false;
+                    this.isAdminShow = sessionStorage.getItem('admin_show') === 'true' ? true : false;
+                    this.isUserShow = sessionStorage.getItem('user_show') === 'true' ? true : false;
                     setTimeout((): void => {
                         if (this.isAdminShow === true || this.isUserShow === true) {
                             this.generateData();
                         }
                     }, this.epochTime1000);
                 }
-                localStorage.removeItem('returnUrl');
+                sessionStorage.removeItem('returnUrl');
             }, (err: HttpErrorResponse): void => {
                 this.isLoadingResults = false;
                 this.restService.handleError(err, 'post');
@@ -244,7 +247,7 @@ export class LoginComponent implements OnInit {
 
     /** Fetching the data from server to load it in toaster @public */
     public generateData(): void {
-        const userID: string = localStorage.getItem('user_id');
+        const userID: string = sessionStorage.getItem('user_id');
         if (userID !== '') {
             this.isLoadingResults = true;
             this.restService.getResource(environment.USERS_URL + '/' + userID).subscribe((userDetails: UserDetail): void => {
@@ -267,8 +270,8 @@ export class LoginComponent implements OnInit {
                     this.accountExpireMessage = this.translateService.instant('PAGE.LOGIN.ACCOUNTEXPIRE');
                     this.passwordExpireMessage = this.translateService.instant('PAGE.LOGIN.PASSWORDEXPIRE');
                     this.daysMessage = this.translateService.instant('PAGE.LOGIN.DAYS');
-                    this.lastLogin = localStorage.getItem('last_login');
-                    this.failedAttempts = localStorage.getItem('failed_count');
+                    this.lastLogin = sessionStorage.getItem('last_login');
+                    this.failedAttempts = sessionStorage.getItem('failed_count');
                     if (this.accountNoOfDays !== '0' && this.passwordNoOfDays !== '0' &&
                         this.accountNoOfDays !== '1' && this.passwordNoOfDays !== '1') {
                         this.showToaster();
@@ -284,6 +287,11 @@ export class LoginComponent implements OnInit {
         }
     }
 
+    /** To Show or Hide the Password @public */
+    public onShowPassword(): void {
+        this.visiblePassword = !this.visiblePassword;
+    }
+
     /** To display password expiry Toaster with required data @public */
     public passwordExpiryToaster(): void {
         if ((this.accountNoOfDays === '1' && this.passwordNoOfDays === '1') ||
@@ -318,24 +326,28 @@ export class LoginComponent implements OnInit {
                     this.sharedService.passwordToaster(this.lastLogin, this.failedAttempts, this.passwordNoOfDays,
                         this.passwordExpireMessage, this.passwordMessage);
                 } else {
-                    if (this.accountNoOfDays === '1') {
-                        this.accountExpireMessage = this.translateService.instant('PAGE.LOGIN.ACCOUNTEXPIRETOMORROW');
-                        this.accountMessage = '';
-                        this.accountNoOfDays = '';
-                    } else if (this.accountNoOfDays === '0') {
-                        this.accountExpireMessage = this.translateService.instant('PAGE.LOGIN.ACCOUNTEXPIRETODAY');
-                        this.accountMessage = '';
-                        this.accountNoOfDays = '';
-                    } else {
-                        this.accountExpireMessage = this.accountExpireMessage = this.translateService.instant('PAGE.LOGIN.ACCOUNTEXPIRE');
-                        this.accountMessage = this.translateService.instant('PAGE.LOGIN.DAYS');
-                    }
-                    this.sharedService.showToaster(this.lastLogin, this.failedAttempts, this.passwordNoOfDays, this.accountNoOfDays,
-                        this.passwordExpireMessage, this.accountExpireMessage, this.passwordMessage, this.accountMessage);
+                    this.accountDaysCheck();
                 }
             }
         }
     }
+    /** To check account no.of days with 0 & 1 @public */
+    public accountDaysCheck(): void {
+        if (this.accountNoOfDays === '1') {
+            this.accountExpireMessage = this.translateService.instant('PAGE.LOGIN.ACCOUNTEXPIRETOMORROW');
+            this.accountMessage = '';
+            this.accountNoOfDays = '';
+        } else if (this.accountNoOfDays === '0') {
+            this.accountExpireMessage = this.translateService.instant('PAGE.LOGIN.ACCOUNTEXPIRETODAY');
+            this.accountMessage = '';
+            this.accountNoOfDays = '';
+        } else {
+            this.accountExpireMessage = this.accountExpireMessage = this.translateService.instant('PAGE.LOGIN.ACCOUNTEXPIRE');
+            this.accountMessage = this.translateService.instant('PAGE.LOGIN.DAYS');
+        }
+        this.sharedService.showToaster(this.lastLogin, this.failedAttempts, this.passwordNoOfDays, this.accountNoOfDays,
+            this.passwordExpireMessage, this.accountExpireMessage, this.passwordMessage, this.accountMessage);
+    }
     /** To display account expiry Toaster with required data @public */
     public accountExpiryToaster(): void {
         if (!isNullOrUndefined(this.accountNoOfDays)) {
@@ -356,24 +368,28 @@ export class LoginComponent implements OnInit {
                     this.sharedService.accountToaster(this.lastLogin, this.failedAttempts,
                         this.accountNoOfDays, this.accountExpireMessage, this.accountMessage);
                 } else {
-                    if (this.passwordNoOfDays === '1') {
-                        this.passwordExpireMessage = this.translateService.instant('PAGE.LOGIN.PASSWORDEXPIRETOMORROW');
-                        this.passwordMessage = '';
-                        this.passwordNoOfDays = '';
-                    } else if (this.passwordNoOfDays === '0') {
-                        this.passwordExpireMessage = this.translateService.instant('PAGE.LOGIN.PASSWORDEXPIRETODAY');
-                        this.passwordMessage = '';
-                        this.passwordNoOfDays = '';
-                    } else {
-                        this.passwordExpireMessage = this.translateService.instant('PAGE.LOGIN.PASSWORDEXPIRE');
-                        this.passwordMessage = this.translateService.instant('PAGE.LOGIN.DAYS');
-                    }
-                    this.sharedService.showToaster(this.lastLogin, this.failedAttempts, this.passwordNoOfDays, this.accountNoOfDays,
-                        this.passwordExpireMessage, this.accountExpireMessage, this.passwordMessage, this.accountMessage);
+                    this.passwordDaysCheck();
                 }
             }
         }
     }
+    /** To check password no.of days with 0 & 1 @public */
+    public passwordDaysCheck(): void {
+        if (this.passwordNoOfDays === '1') {
+            this.passwordExpireMessage = this.translateService.instant('PAGE.LOGIN.PASSWORDEXPIRETOMORROW');
+            this.passwordMessage = '';
+            this.passwordNoOfDays = '';
+        } else if (this.passwordNoOfDays === '0') {
+            this.passwordExpireMessage = this.translateService.instant('PAGE.LOGIN.PASSWORDEXPIRETODAY');
+            this.passwordMessage = '';
+            this.passwordNoOfDays = '';
+        } else {
+            this.passwordExpireMessage = this.translateService.instant('PAGE.LOGIN.PASSWORDEXPIRE');
+            this.passwordMessage = this.translateService.instant('PAGE.LOGIN.DAYS');
+        }
+        this.sharedService.showToaster(this.lastLogin, this.failedAttempts, this.passwordNoOfDays, this.accountNoOfDays,
+            this.passwordExpireMessage, this.accountExpireMessage, this.passwordMessage, this.accountMessage);
+    }
     /** To display password & account expiry Toaster with required data @public */
     public showToaster(): void {
         if (!isNullOrUndefined(this.accountNoOfDays) && !isNullOrUndefined(this.passwordNoOfDays)) {