+
+ /** Fetching the data from server to load it in toaster @public */
+ public generateData(): void {
+ const userID: string = sessionStorage.getItem('user_id');
+ if (userID !== '') {
+ this.isLoadingResults = true;
+ this.restService.getResource(environment.USERS_URL + '/' + userID).subscribe((userDetails: UserDetail): void => {
+ this.userDetails = userDetails;
+ if (!isNullOrUndefined(userDetails)) {
+ const account: string = this.sharedService.convertEpochTime(!isNullOrUndefined(userDetails._admin) ?
+ userDetails._admin.account_expire_time : null);
+ const password: string = this.sharedService.convertEpochTime(!isNullOrUndefined(userDetails._admin) ?
+ userDetails._admin.password_expire_time : null);
+ const accountExpire: number = this.sharedService.converEpochToDays(account);
+ const passwordExpire: number = this.sharedService.converEpochToDays(password);
+ if (accountExpire >= 0 && accountExpire <= this.expireDays) {
+ this.accountNoOfDays = String(accountExpire);
+ }
+ if (passwordExpire >= 0 && passwordExpire <= this.expireDays) {
+ this.passwordNoOfDays = String(passwordExpire);
+ }
+ this.lastLoginMessage = this.translateService.instant('PAGE.LOGIN.LASTACCESS');
+ this.failedAttemptsMessage = this.translateService.instant('PAGE.LOGIN.FAILED');
+ 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 = 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();
+ }
+ this.passwordExpiryToaster();
+ this.accountExpiryToaster();
+ }
+ this.isLoadingResults = false;
+ }, (error: ERRORDATA): void => {
+ this.isLoadingResults = false;
+ this.restService.handleError(error, 'get');
+ });
+ }
+ }
+
+ /** 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') ||
+ (this.accountNoOfDays === '0' && this.passwordNoOfDays === '0')) {
+ this.passwordExpireMessage = this.translateService.instant('PAGE.LOGIN.PASSWORDEXPIRETODAY');
+ this.accountExpireMessage = this.translateService.instant('PAGE.LOGIN.ACCOUNTEXPIRETODAY');
+ if (this.accountNoOfDays === '1') {
+ this.passwordExpireMessage = this.translateService.instant('PAGE.LOGIN.PASSWORDEXPIRETOMORROW');
+ this.accountExpireMessage = this.translateService.instant('PAGE.LOGIN.ACCOUNTEXPIRETOMORROW');
+ }
+ this.passwordMessage = '';
+ this.accountMessage = '';
+ this.accountNoOfDays = '';
+ this.passwordNoOfDays = '';
+ this.sharedService.showToaster(this.lastLogin, this.failedAttempts, this.passwordNoOfDays, this.accountNoOfDays,
+ this.passwordExpireMessage, this.accountExpireMessage, this.passwordMessage, this.accountMessage);
+ } else if (!isNullOrUndefined(this.passwordNoOfDays)) {
+ if ((this.passwordNoOfDays === '0') || this.passwordNoOfDays === '1' ||
+ (this.passwordNoOfDays === '0' && (isNullOrUndefined(this.accountNoOfDays) || !isNullOrUndefined(this.accountNoOfDays))) ||
+ (this.passwordNoOfDays === '1' && (isNullOrUndefined(this.accountNoOfDays) || !isNullOrUndefined(this.accountNoOfDays)))
+ ) {
+ 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 = '';
+ }
+ if (isNullOrUndefined(this.accountNoOfDays)) {
+ this.sharedService.passwordToaster(this.lastLogin, this.failedAttempts, this.passwordNoOfDays,
+ this.passwordExpireMessage, this.passwordMessage);
+ } else {
+ 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)) {
+ if ((this.accountNoOfDays === '0') || (this.accountNoOfDays === '1') || ((this.accountNoOfDays === '0') &&
+ (isNullOrUndefined(this.passwordNoOfDays) || !isNullOrUndefined(this.passwordNoOfDays))) ||
+ ((this.accountNoOfDays === '1') && (isNullOrUndefined(this.passwordNoOfDays) || !isNullOrUndefined(this.passwordNoOfDays)))
+ && this.passwordNoOfDays !== '0' && this.passwordNoOfDays !== '1') {
+ 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 = '';
+ }
+ if (isNullOrUndefined(this.passwordNoOfDays)) {
+ this.sharedService.accountToaster(this.lastLogin, this.failedAttempts,
+ this.accountNoOfDays, this.accountExpireMessage, this.accountMessage);
+ } else {
+ 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)) {
+ this.toaster.info(this.lastLoginMessage + ':' + ' ' + this.lastLogin +
+ '</br>' + this.failedAttemptsMessage + ':' + ' ' + this.failedAttempts +
+ '</br>' + this.passwordExpireMessage + ' ' + this.passwordNoOfDays + ' ' + this.daysMessage +
+ '</br>' + this.accountExpireMessage + ' ' + this.accountNoOfDays + ' ' + this.daysMessage,
+ this.translateService.instant('PAGE.LOGIN.LOGINHISTORY'), this.toasterSettings);
+ } else if (!isNullOrUndefined(this.accountNoOfDays) || !isNullOrUndefined(this.passwordNoOfDays)) {
+ if (!isNullOrUndefined(this.passwordNoOfDays)) {
+ this.toaster.info(this.lastLoginMessage + ':' + ' ' + this.lastLogin +
+ '</br>' + this.failedAttemptsMessage + ':' + ' ' + this.failedAttempts +
+ '</br>' + this.passwordExpireMessage + ' ' + this.passwordNoOfDays + ' ' + this.daysMessage,
+ this.translateService.instant('PAGE.LOGIN.LOGINHISTORY'), this.toasterSettings);
+ } else if (!isNullOrUndefined(this.accountNoOfDays)) {
+ this.toaster.info(
+ this.lastLoginMessage + ':' + ' ' + this.lastLogin +
+ '</br>' + this.failedAttemptsMessage + ':' + ' ' + this.failedAttempts +
+ '</br>' + this.accountExpireMessage + ' ' + this.accountNoOfDays + ' ' + this.daysMessage,
+ this.translateService.instant('PAGE.LOGIN.LOGINHISTORY'), this.toasterSettings);
+ }
+ } else {
+ this.toaster.info(this.lastLoginMessage + ':' + ' ' + this.lastLogin +
+ '</br>' + this.failedAttemptsMessage + ':' + ' ' + this.failedAttempts,
+ this.translateService.instant('PAGE.LOGIN.LOGINHISTORY'), this.toasterSettings);
+ }
+ }