|
|
|
@ -43,30 +43,74 @@ constructor(private fb: FormBuilder, private httpURIService: HttpURIService, pri
|
|
|
|
this.passwordType2 = this.passwordHideShow2?.showPassword ? 'password' : 'text';
|
|
|
|
this.passwordType2 = this.passwordHideShow2?.showPassword ? 'password' : 'text';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ngOnInit(): void {
|
|
|
|
|
|
|
|
this.checkIfFirstTimeChangePasswordOrNot();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (this.isFirstLogin) {
|
|
|
|
|
|
|
|
this.firstTimeLoginForm = this.fb.group({
|
|
|
|
|
|
|
|
oldPassword: ['', Validators.required],
|
|
|
|
|
|
|
|
newPassword: ['', [
|
|
|
|
|
|
|
|
Validators.required,
|
|
|
|
|
|
|
|
Validators.minLength(8),
|
|
|
|
|
|
|
|
Validators.maxLength(20),
|
|
|
|
|
|
|
|
Validators.pattern(/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]+$/)
|
|
|
|
|
|
|
|
]],
|
|
|
|
|
|
|
|
confirmPassword: ['', [
|
|
|
|
|
|
|
|
Validators.required,
|
|
|
|
|
|
|
|
Validators.minLength(8),
|
|
|
|
|
|
|
|
Validators.maxLength(20),
|
|
|
|
|
|
|
|
Validators.pattern(/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]+$/)
|
|
|
|
|
|
|
|
]]
|
|
|
|
|
|
|
|
}, { validators: this.passwordMatchValidator });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
this.changePasswordForm = this.fb.group({
|
|
|
|
|
|
|
|
oldPassword: ['', Validators.required],
|
|
|
|
|
|
|
|
newPassword: ['', [
|
|
|
|
|
|
|
|
Validators.required,
|
|
|
|
|
|
|
|
Validators.minLength(8),
|
|
|
|
|
|
|
|
Validators.maxLength(20),
|
|
|
|
|
|
|
|
Validators.pattern(/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]+$/)
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
],
|
|
|
|
|
|
|
|
confirmPassword: ['', [
|
|
|
|
|
|
|
|
Validators.required,
|
|
|
|
|
|
|
|
Validators.minLength(8),
|
|
|
|
|
|
|
|
Validators.maxLength(20),
|
|
|
|
|
|
|
|
Validators.pattern(/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]+$/)
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
}, { validators: [
|
|
|
|
|
|
|
|
this.passwordMatchValidator,
|
|
|
|
|
|
|
|
this.oldAndNewPasswordNotSame,
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
passwordMatchValidator(group: AbstractControl): ValidationErrors | null {
|
|
|
|
passwordMatchValidator(group: AbstractControl): ValidationErrors | null {
|
|
|
|
const newPassword = group.get('newPassword')?.value;
|
|
|
|
const newPassword = group.get('newPassword')?.value;
|
|
|
|
const confirmPassword = group.get('confirmPassword')?.value;
|
|
|
|
const confirmPassword = group.get('confirmPassword')?.value;
|
|
|
|
return newPassword === confirmPassword ? null : { passwordMismatch: true };
|
|
|
|
return newPassword === confirmPassword ? null : { passwordMismatch: true };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ngOnInit(): void {
|
|
|
|
oldAndNewPasswordNotSame(group: AbstractControl): ValidationErrors | null {
|
|
|
|
this.checkIfFirstTimeChangePasswordOrNot();
|
|
|
|
const oldPassword = group.get('oldPassword')?.value;
|
|
|
|
|
|
|
|
const newPassword = group.get('newPassword')?.value;
|
|
|
|
if (this.isFirstLogin) {
|
|
|
|
|
|
|
|
this.firstTimeLoginForm = this.fb.group({
|
|
|
|
|
|
|
|
newPassword: ['', [Validators.required, Validators.minLength(6)]],
|
|
|
|
|
|
|
|
confirmPassword: ['', [Validators.required, Validators.minLength(6)]]
|
|
|
|
|
|
|
|
}, { validators: this.passwordMatchValidator });
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
this.changePasswordForm = this.fb.group({
|
|
|
|
|
|
|
|
oldPassword: ['', Validators.required],
|
|
|
|
|
|
|
|
newPassword: ['', [Validators.required, Validators.minLength(6)]],
|
|
|
|
|
|
|
|
confirmPassword: ['', [Validators.required, Validators.minLength(6)]]
|
|
|
|
|
|
|
|
}, { validators: this.passwordMatchValidator });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!oldPassword || !newPassword) {
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return oldPassword === newPassword
|
|
|
|
|
|
|
|
? { oldAndNewPasswordSame: true }
|
|
|
|
|
|
|
|
: null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
checkIfFirstTimeChangePasswordOrNot(): void {
|
|
|
|
checkIfFirstTimeChangePasswordOrNot(): void {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const currentUser: any = JSON.parse(
|
|
|
|
const currentUser: any = JSON.parse(
|
|
|
|
@ -80,37 +124,6 @@ constructor(private fb: FormBuilder, private httpURIService: HttpURIService, pri
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (control.hasError('required')) return 'fieldRequired';
|
|
|
|
|
|
|
|
if (control.hasError('minlength')) return 'passwordTooShort';
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
get confirmPasswordError$() {
|
|
|
|
|
|
|
|
const control = this.changePasswordForm.get('confirmPassword');
|
|
|
|
|
|
|
|
if (!control || !control.touched) return null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (control.hasError('required')) return 'fieldRequired';
|
|
|
|
|
|
|
|
if (control.hasError('minlength')) return 'passwordTooShort';
|
|
|
|
|
|
|
|
if (this.changePasswordForm.hasError('passwordMismatch')) return 'passwordsDoNotMatch';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
getFormPayload() {
|
|
|
|
getFormPayload() {
|
|
|
|
const form = this.isFirstLogin ? this.firstTimeLoginForm : this.changePasswordForm;
|
|
|
|
const form = this.isFirstLogin ? this.firstTimeLoginForm : this.changePasswordForm;
|
|
|
|
|
|
|
|
|
|
|
|
|