+ /** Used to set the validation and value and update the validation and value @public */
+ public checkType(userType: string): void {
+ if (userType === 'forgotPassword') {
+ this.getFormControl('password').setValidators([]);
+ this.getFormControl('password').updateValueAndValidity();
+ this.getFormControl('password2').setValidators([]);
+ this.getFormControl('password2').updateValueAndValidity();
+ this.getFormControl('old_password').setValidators([]);
+ this.getFormControl('old_password').updateValueAndValidity();
+ } else if (userType === 'editmail') {
+ this.getFormControl('password').setValidators([]);
+ this.getFormControl('password').updateValueAndValidity();
+ this.getFormControl('password2').setValidators([]);
+ this.getFormControl('password2').updateValueAndValidity();
+ this.getFormControl('old_password').setValidators([]);
+ this.getFormControl('old_password').updateValueAndValidity();
+ this.getFormControl('userName').setValidators([]);
+ this.getFormControl('userName').updateValueAndValidity();
+ }
+ }
+
+ /** Forgot password @public */
+ public forgetPassword(): void {
+ this.isLoadingResults = true;
+ if (isNullOrUndefined(this.userForm.value.otp)) {
+ this.payload = JSON.stringify({
+ username: (this.userForm.value.userName).toLowerCase(),
+ email_id: (this.userForm.value.email_id)
+ });
+ } else {
+ this.getFormControl('userName').enable();
+ this.payload = JSON.stringify({
+ username: (this.userForm.value.userName).toLowerCase(),
+ otp: (this.userForm.value.otp)
+ });
+ }
+ const apiURLHeader: APIURLHEADER = {
+ url: environment.GENERATETOKEN_URL,
+ httpOptions: { headers: this.headers }
+ };
+ this.restService.postResource(apiURLHeader, this.payload).subscribe((result:
+ { email: string, id: string, user_id: string, message: string, otp: string }
+ ): void => {
+ if (result.email === 'sent') {
+ this.getFormControl('userName').disable();
+ this.getFormControl('email_id').disable();
+ this.isOtp = true;
+ this.cd.detectChanges();
+ this.notifierService.notify('success', this.translateService.instant('PAGE.USERS.USERSUCCESSFULLY'));
+ }
+ if (result.message === 'valid_otp') {
+ this.activeModal.close(this.modalData);
+ this.getFormControl('email_id').enable();
+ sessionStorage.setItem('id_token', result.id);
+ sessionStorage.setItem('user_id', result.user_id);
+ sessionStorage.setItem('mail', this.userForm.value.email_id);
+ this.userType = 'change_password';
+ sessionStorage.setItem('usertype', this.userType);
+ this.idToken = sessionStorage.getItem('id_token');
+ this.notifierService.notify('success', this.translateService.instant('PAGE.USERS.OTPSUCCESSFULLY'));
+ if (!isNullOrUndefined(sessionStorage.getItem('id_token')) && !isNullOrUndefined(sessionStorage.getItem('mail'))) {
+ this.authService.forgotPassword.next(true);
+ this.isForgotPassword$ = this.authService.forgotPassword;
+ this.authService.isForgotPassword.subscribe((res: boolean): void => {
+ this.forgotPassword = res;
+ });
+ if (this.forgotPassword === true) {
+ this.router.navigate(['/forgotpassword/changepassword/', encodeURI(this.idToken)]).catch((): void => {
+ // Catch Navigation Error
+ });
+ }
+ }
+ } else if (result.otp === 'invalid') {
+ this.getFormControl('userName').disable();
+ this.notifierService.notify('warning', this.translateService.instant('PAGE.USERS.INVALIDOTP'));
+ }
+ this.isLoadingResults = false;
+ }, (error: ERRORDATA): void => {
+ // eslint-disable-next-line @typescript-eslint/no-magic-numbers
+ if (error.error.status === 401 || error.error.status === 429 || error.error.status === 404) {
+ this.activeModal.close(this.modalData);
+ this.router.navigate(['/login']).catch((): void => {
+ // Catch Navigation Error
+ });
+ }
+ this.restService.handleError(error, 'post');
+ this.isLoadingResults = false;
+ });
+ }
+
+ /** Change password @public */
+ public changePassword(): void {
+ this.isLoadingResults = true;
+ this.userID = sessionStorage.getItem('user_id');
+ const payLoad: LOGINPARAMS = {};
+ payLoad.password = (this.userForm.value.password);
+ payLoad.email_id = (sessionStorage.getItem('mail'));
+ const apiURLHeader: APIURLHEADER = {
+ url: environment.USERS_URL + '/' + this.userID,
+ httpOptions: { headers: this.headers }
+ };
+ this.restService.patchResource(apiURLHeader, payLoad).subscribe((result: {}): void => {
+ this.activeModal.close(this.modalData);
+ this.router.navigate(['/login']).catch((): void => {
+ // Catch Navigation Error
+ });
+ this.authService.logoutResponse();
+ this.notifierService.notify('success', this.translateService.instant('PAGE.USERS.CHANGEDSUCCESSFULLY'));
+ this.isLoadingResults = false;
+ }, (error: ERRORDATA): void => {
+ this.restService.handleError(error, 'put');
+ this.isLoadingResults = false;
+ });
+ }
+