feat: migrate ForgotPwComponent to Django Rest
This commit is contained in:
parent
4b7912324d
commit
68a413dc97
4 changed files with 26 additions and 8 deletions
|
|
@ -38,10 +38,10 @@
|
|||
}
|
||||
<div class="error-msg">
|
||||
@if(!mail.valid && mail.touched &&
|
||||
!checkIfUserEmailIsValid(pwResetData.mail.toLowerCase())) {
|
||||
!isEmailValid(pwResetData.mail.toLowerCase())) {
|
||||
<p>{{ "register.errorMail0" | translate }}</p>
|
||||
} @else { @if (mail.touched &&
|
||||
!checkIfUserEmailIsValid(pwResetData.mail.toLowerCase())) {
|
||||
!isEmailValid(pwResetData.mail.toLowerCase())) {
|
||||
<p>{{ "register.errorMail1" | translate }}</p>
|
||||
} }
|
||||
</div>
|
||||
|
|
@ -58,7 +58,7 @@
|
|||
mail.invalid ||
|
||||
!pwResetData.mail ||
|
||||
isButtonDisabled() ||
|
||||
!checkIfUserEmailIsValid(pwResetData.mail)
|
||||
!isEmailValid(pwResetData.mail)
|
||||
"
|
||||
></app-form-btn>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -5,9 +5,9 @@ import { FormBtnComponent } from '../../../shared/components/buttons/form-btn/fo
|
|||
import { FooterComponent } from '../footer/footer.component';
|
||||
import { HeaderComponent } from '../header/header.component';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { LoginService } from '../../../services/login.service';
|
||||
import { BtnBackComponent } from '../../../shared/components/buttons/btn-back/btn-back.component';
|
||||
import { ButtonStateService } from '../../../services/button-state.service';
|
||||
import { AuthService } from '../../../services/auth.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-forgot-pw',
|
||||
|
|
@ -30,14 +30,14 @@ export class ForgotPwComponent {
|
|||
};
|
||||
|
||||
constructor(
|
||||
public loginService: LoginService,
|
||||
private buttonStateService: ButtonStateService
|
||||
private buttonStateService: ButtonStateService,
|
||||
private authService: AuthService
|
||||
) {}
|
||||
|
||||
onSubmit(ngForm: NgForm) {
|
||||
this.buttonStateService.enableButton();
|
||||
if (ngForm.submitted && ngForm.form.valid) {
|
||||
this.loginService.passwordReset(this.pwResetData.mail.toLowerCase());
|
||||
this.authService.resetPassword(this.pwResetData.mail.toLowerCase());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -45,7 +45,7 @@ export class ForgotPwComponent {
|
|||
return this.buttonStateService.isButtonDisabled;
|
||||
}
|
||||
|
||||
checkIfUserEmailIsValid(emailValue: string) {
|
||||
isEmailValid(emailValue: string) {
|
||||
const emailRegex = /^[\w.%+-]+@[\w.-]+\.[a-zA-Z]{2,}$/;
|
||||
if (emailRegex.test(emailValue)) {
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -73,6 +73,17 @@ export class AuthService {
|
|||
}
|
||||
}
|
||||
|
||||
async resetPassword(email: string): Promise<void> {
|
||||
try {
|
||||
await lastValueFrom(
|
||||
this.apiService.request('POST', `/auth/reset/`, { email })
|
||||
);
|
||||
this.toastNotificationService.resetPasswordSuccessToast();
|
||||
} catch (error) {
|
||||
console.error('Password reset failed:', error);
|
||||
}
|
||||
}
|
||||
|
||||
checkAuthUser(): Observable<boolean> {
|
||||
return this.apiService.request('GET', `/auth/`).pipe(
|
||||
map(() => true),
|
||||
|
|
|
|||
|
|
@ -29,6 +29,13 @@ export class ToastNotificationService {
|
|||
);
|
||||
}
|
||||
|
||||
resetPasswordSuccessToast(): void {
|
||||
this.createSuccessToast(
|
||||
'If the e-mail address is valid, you will receive an e-mail with a link to reset the password.',
|
||||
'Password Reset Successful'
|
||||
);
|
||||
}
|
||||
|
||||
showSessionExpiredMessage(): void {
|
||||
this.createInfoToast(
|
||||
'Your session has expired, please log in again.',
|
||||
|
|
|
|||
Loading…
Reference in a new issue