|
|
|
|
@ -43,34 +43,73 @@ constructor(private fb: FormBuilder, private httpURIService: HttpURIService, pri
|
|
|
|
|
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 {
|
|
|
|
|
const newPassword = group.get('newPassword')?.value;
|
|
|
|
|
const confirmPassword = group.get('confirmPassword')?.value;
|
|
|
|
|
return newPassword === confirmPassword ? null : { passwordMismatch: true };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
oldAndNewPasswordNotSame(group: AbstractControl): ValidationErrors | null {
|
|
|
|
|
const oldPassword = group.get('oldPassword')?.value;
|
|
|
|
|
const newPassword = group.get('newPassword')?.value;
|
|
|
|
|
|
|
|
|
|
initForm(): void {
|
|
|
|
|
if (this.firstLogin) {
|
|
|
|
|
this.changePasswordForm = undefined!;
|
|
|
|
|
this.firstTimeLoginForm = this.fb.group({
|
|
|
|
|
newPassword: ['', [Validators.required, Validators.minLength(6)]],
|
|
|
|
|
confirmPassword: ['', [Validators.required, Validators.minLength(6)]]
|
|
|
|
|
}, { validators: this.passwordMatchValidator });
|
|
|
|
|
} else {
|
|
|
|
|
this.firstTimeLoginForm = undefined!;
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ngOnInit(): void {
|
|
|
|
|
this.checkIfFirstTimeChangePasswordOrNot();
|
|
|
|
|
this.initForm();
|
|
|
|
|
}
|
|
|
|
|
return oldPassword === newPassword
|
|
|
|
|
? { oldAndNewPasswordSame: true }
|
|
|
|
|
: null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
checkIfFirstTimeChangePasswordOrNot(): void {
|
|
|
|
|
try {
|
|
|
|
|
@ -85,17 +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 }
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getFormPayload() {
|
|
|
|
|
const form = this.firstLogin ? this.firstTimeLoginForm : this.changePasswordForm;
|
|
|
|
|
|
|
|
|
|
|