|
|
|
|
@ -16,6 +16,7 @@ import { StorageService } from '../../shared/services/storage.service';
|
|
|
|
|
|
|
|
|
|
export class ChangePasswordComponent implements OnInit{
|
|
|
|
|
isFirstLogin = false;
|
|
|
|
|
firstTimeLoginForm!: FormGroup;
|
|
|
|
|
changePasswordForm!: FormGroup;
|
|
|
|
|
currentLanguage = new FormControl();
|
|
|
|
|
httpService: any;
|
|
|
|
|
@ -40,7 +41,7 @@ constructor(private fb: FormBuilder, private httpURIService: HttpURIService, pri
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
passwordMatchValidator(group: AbstractControl): ValidationErrors | null {
|
|
|
|
|
const newPassword = group.get('enterNewPassword')?.value;
|
|
|
|
|
const newPassword = group.get('newPassword')?.value;
|
|
|
|
|
const confirmPassword = group.get('confirmPassword')?.value;
|
|
|
|
|
return newPassword === confirmPassword ? null : { passwordMismatch: true };
|
|
|
|
|
}
|
|
|
|
|
@ -48,18 +49,19 @@ constructor(private fb: FormBuilder, private httpURIService: HttpURIService, pri
|
|
|
|
|
ngOnInit(): void {
|
|
|
|
|
this.checkIfFirstTimeChangePasswordOrNot();
|
|
|
|
|
|
|
|
|
|
if (!this.isFirstLogin) {
|
|
|
|
|
this.initChangePasswordForm();
|
|
|
|
|
}
|
|
|
|
|
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],
|
|
|
|
|
enterNewPassword: ['',[ Validators.required, Validators.minLength(6)]],
|
|
|
|
|
newPassword: ['', [Validators.required, Validators.minLength(6)]],
|
|
|
|
|
confirmPassword: ['', [Validators.required, Validators.minLength(6)]]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
validators: this.passwordMatchValidator
|
|
|
|
|
}, { validators: this.passwordMatchValidator });
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
checkIfFirstTimeChangePasswordOrNot(): void {
|
|
|
|
|
@ -113,14 +115,18 @@ constructor(private fb: FormBuilder, private httpURIService: HttpURIService, pri
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
getFormPayload() {
|
|
|
|
|
const form = this.isFirstLogin ? this.firstTimeLoginForm : this.changePasswordForm;
|
|
|
|
|
|
|
|
|
|
onSubmit(){
|
|
|
|
|
if(this.changePasswordForm.invalid){return}
|
|
|
|
|
|
|
|
|
|
const payload = {
|
|
|
|
|
oldPassword: this.changePasswordForm.value.oldPassword,
|
|
|
|
|
newPassword: this.changePasswordForm.value.enterNewPassword
|
|
|
|
|
return {
|
|
|
|
|
oldPassword: form.get('oldPassword')?.value || null,
|
|
|
|
|
// confirmPassword: form.get('confirmPassword')?.value || null,
|
|
|
|
|
newPassword: form.get('newPassword')?.value,
|
|
|
|
|
userId: this.storageService.getItem('USER_ID')
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
onSubmit(){
|
|
|
|
|
const payload = this.getFormPayload();
|
|
|
|
|
|
|
|
|
|
this.httpURIService.requestPOST(URIKey.CHANGE_PASSWORD_URI, payload)
|
|
|
|
|
.subscribe();
|
|
|
|
|
|