|
|
|
@ -18,7 +18,7 @@ import { SuccessMessages } from '../../utils/enums';
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
export class ChangePasswordComponent implements OnInit{
|
|
|
|
export class ChangePasswordComponent implements OnInit{
|
|
|
|
isFirstLogin = false;
|
|
|
|
firstLogin = true;
|
|
|
|
firstTimeLoginForm!: FormGroup;
|
|
|
|
firstTimeLoginForm!: FormGroup;
|
|
|
|
changePasswordForm!: FormGroup;
|
|
|
|
changePasswordForm!: FormGroup;
|
|
|
|
currentLanguage = new FormControl();
|
|
|
|
currentLanguage = new FormControl();
|
|
|
|
@ -49,23 +49,28 @@ constructor(private fb: FormBuilder, private httpURIService: HttpURIService, pri
|
|
|
|
return newPassword === confirmPassword ? null : { passwordMismatch: true };
|
|
|
|
return newPassword === confirmPassword ? null : { passwordMismatch: true };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ngOnInit(): void {
|
|
|
|
initForm(): void {
|
|
|
|
this.checkIfFirstTimeChangePasswordOrNot();
|
|
|
|
if (this.firstLogin) {
|
|
|
|
|
|
|
|
this.changePasswordForm = undefined!;
|
|
|
|
if (this.isFirstLogin) {
|
|
|
|
|
|
|
|
this.firstTimeLoginForm = this.fb.group({
|
|
|
|
this.firstTimeLoginForm = this.fb.group({
|
|
|
|
newPassword: ['', [Validators.required, Validators.minLength(6)]],
|
|
|
|
newPassword: ['', [Validators.required, Validators.minLength(6)]],
|
|
|
|
confirmPassword: ['', [Validators.required, Validators.minLength(6)]]
|
|
|
|
confirmPassword: ['', [Validators.required, Validators.minLength(6)]]
|
|
|
|
}, { validators: this.passwordMatchValidator });
|
|
|
|
}, { validators: this.passwordMatchValidator });
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
|
|
|
|
this.firstTimeLoginForm = undefined!;
|
|
|
|
this.changePasswordForm = this.fb.group({
|
|
|
|
this.changePasswordForm = this.fb.group({
|
|
|
|
oldPassword: ['', Validators.required],
|
|
|
|
oldPassword: ['', Validators.required],
|
|
|
|
newPassword: ['', [Validators.required, Validators.minLength(6)]],
|
|
|
|
newPassword: ['', [Validators.required, Validators.minLength(6)]],
|
|
|
|
confirmPassword: ['', [Validators.required, Validators.minLength(6)]]
|
|
|
|
confirmPassword: ['', [Validators.required, Validators.minLength(6)]]
|
|
|
|
}, { validators: this.passwordMatchValidator });
|
|
|
|
}, { validators: this.passwordMatchValidator });
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ngOnInit(): void {
|
|
|
|
|
|
|
|
this.checkIfFirstTimeChangePasswordOrNot();
|
|
|
|
|
|
|
|
this.initForm();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
checkIfFirstTimeChangePasswordOrNot(): void {
|
|
|
|
checkIfFirstTimeChangePasswordOrNot(): void {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
@ -73,10 +78,10 @@ constructor(private fb: FormBuilder, private httpURIService: HttpURIService, pri
|
|
|
|
this.storageService.getItem('user') || '{}'
|
|
|
|
this.storageService.getItem('user') || '{}'
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
this.isFirstLogin = !!currentUser?.user?.isFirstLogin;
|
|
|
|
this.firstLogin = !!currentUser?.user?.firstLogin;
|
|
|
|
} catch (error) {
|
|
|
|
} catch (error) {
|
|
|
|
console.error('Error parsing user data:', error);
|
|
|
|
console.error('Error parsing user data:', error);
|
|
|
|
this.isFirstLogin = false;
|
|
|
|
this.firstLogin = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -91,28 +96,8 @@ constructor(private fb: FormBuilder, private httpURIService: HttpURIService, pri
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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.firstLogin ? this.firstTimeLoginForm : this.changePasswordForm;
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
oldPassword: form.get('oldPassword')?.value || null,
|
|
|
|
oldPassword: form.get('oldPassword')?.value || null,
|
|
|
|
@ -129,6 +114,18 @@ constructor(private fb: FormBuilder, private httpURIService: HttpURIService, pri
|
|
|
|
next: (response) => {
|
|
|
|
next: (response) => {
|
|
|
|
if (!(response instanceof HttpErrorResponse)) {
|
|
|
|
if (!(response instanceof HttpErrorResponse)) {
|
|
|
|
this.i18nService.success(SuccessMessages.CHANGE_PASSWORD_SUCCESS, []);
|
|
|
|
this.i18nService.success(SuccessMessages.CHANGE_PASSWORD_SUCCESS, []);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (this.firstLogin) {
|
|
|
|
|
|
|
|
const currentUser = JSON.parse(this.storageService.getItem('user') || '{}');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (currentUser?.user) {
|
|
|
|
|
|
|
|
currentUser.user.firstLogin = false;
|
|
|
|
|
|
|
|
this.storageService.setItem('user', JSON.stringify(currentUser));
|
|
|
|
|
|
|
|
this.firstLogin = false;
|
|
|
|
|
|
|
|
console.log(this.firstLogin)
|
|
|
|
|
|
|
|
this.initForm();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|