|
|
|
|
@ -5,6 +5,7 @@ import { TranslateModule } from '@ngx-translate/core';
|
|
|
|
|
import { PasswordHideShowComponent } from '../../shared/components/password-hide-show/password-hide-show.component';
|
|
|
|
|
import { HttpURIService } from '../../app.http.uri.service';
|
|
|
|
|
import { URIKey } from '../../utils/uri-enums';
|
|
|
|
|
import { StorageService } from '../../shared/services/storage.service';
|
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'app-change-password',
|
|
|
|
|
@ -26,7 +27,7 @@ passwordType2: string = 'password';
|
|
|
|
|
@ViewChild('psh') passwordHideShow?: PasswordHideShowComponent;
|
|
|
|
|
@ViewChild('psh1') passwordHideShow1 ?: PasswordHideShowComponent;
|
|
|
|
|
@ViewChild('psh2') passwordHideShow2 ?: PasswordHideShowComponent;
|
|
|
|
|
constructor(private fb: FormBuilder, private httpURIService: HttpURIService){}
|
|
|
|
|
constructor(private fb: FormBuilder, private httpURIService: HttpURIService, private storageService: StorageService){}
|
|
|
|
|
|
|
|
|
|
togglePasswordType() {
|
|
|
|
|
this.passwordType = this.passwordHideShow?.showPassword ? 'password' : 'text';
|
|
|
|
|
@ -45,6 +46,11 @@ constructor(private fb: FormBuilder, private httpURIService: HttpURIService){}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ngOnInit(): void {
|
|
|
|
|
this.checkIfFirstTimeChangePasswordOrNot();
|
|
|
|
|
|
|
|
|
|
if (!this.isFirstLogin) {
|
|
|
|
|
this.initChangePasswordForm();
|
|
|
|
|
}
|
|
|
|
|
this.changePasswordForm = this.fb.group({
|
|
|
|
|
oldPassword: ['', Validators.required],
|
|
|
|
|
enterNewPassword: ['',[ Validators.required, Validators.minLength(6)]],
|
|
|
|
|
@ -55,6 +61,39 @@ constructor(private fb: FormBuilder, private httpURIService: HttpURIService){}
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
checkIfFirstTimeChangePasswordOrNot(): void {
|
|
|
|
|
const fromMenu = history.state?.['fromMenu'];
|
|
|
|
|
|
|
|
|
|
if (fromMenu) {
|
|
|
|
|
this.isFirstLogin = false;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const currentUser: any = JSON.parse(
|
|
|
|
|
this.storageService.getItem('user') || '{}'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
this.isFirstLogin = !!currentUser?.user?.isFirstLogin;
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error('Error parsing user data:', error);
|
|
|
|
|
this.isFirstLogin = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
initChangePasswordForm(): void {
|
|
|
|
|
this.changePasswordForm = this.fb.group(
|
|
|
|
|
{
|
|
|
|
|
oldPassword: ['', Validators.required],
|
|
|
|
|
enterNewPassword: ['', [Validators.required, Validators.minLength(6)]],
|
|
|
|
|
confirmPassword: ['', [Validators.required, Validators.minLength(6)]],
|
|
|
|
|
},
|
|
|
|
|
{ validators: this.passwordMatchValidator }
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
get newPasswordError$() {
|
|
|
|
|
const control = this.changePasswordForm.get('newPassword');
|
|
|
|
|
if (!control || !control.touched) return null;
|
|
|
|
|
|