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">
|
<div class="error-msg">
|
||||||
@if(!mail.valid && mail.touched &&
|
@if(!mail.valid && mail.touched &&
|
||||||
!checkIfUserEmailIsValid(pwResetData.mail.toLowerCase())) {
|
!isEmailValid(pwResetData.mail.toLowerCase())) {
|
||||||
<p>{{ "register.errorMail0" | translate }}</p>
|
<p>{{ "register.errorMail0" | translate }}</p>
|
||||||
} @else { @if (mail.touched &&
|
} @else { @if (mail.touched &&
|
||||||
!checkIfUserEmailIsValid(pwResetData.mail.toLowerCase())) {
|
!isEmailValid(pwResetData.mail.toLowerCase())) {
|
||||||
<p>{{ "register.errorMail1" | translate }}</p>
|
<p>{{ "register.errorMail1" | translate }}</p>
|
||||||
} }
|
} }
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -58,7 +58,7 @@
|
||||||
mail.invalid ||
|
mail.invalid ||
|
||||||
!pwResetData.mail ||
|
!pwResetData.mail ||
|
||||||
isButtonDisabled() ||
|
isButtonDisabled() ||
|
||||||
!checkIfUserEmailIsValid(pwResetData.mail)
|
!isEmailValid(pwResetData.mail)
|
||||||
"
|
"
|
||||||
></app-form-btn>
|
></app-form-btn>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,9 @@ import { FormBtnComponent } from '../../../shared/components/buttons/form-btn/fo
|
||||||
import { FooterComponent } from '../footer/footer.component';
|
import { FooterComponent } from '../footer/footer.component';
|
||||||
import { HeaderComponent } from '../header/header.component';
|
import { HeaderComponent } from '../header/header.component';
|
||||||
import { TranslateModule } from '@ngx-translate/core';
|
import { TranslateModule } from '@ngx-translate/core';
|
||||||
import { LoginService } from '../../../services/login.service';
|
|
||||||
import { BtnBackComponent } from '../../../shared/components/buttons/btn-back/btn-back.component';
|
import { BtnBackComponent } from '../../../shared/components/buttons/btn-back/btn-back.component';
|
||||||
import { ButtonStateService } from '../../../services/button-state.service';
|
import { ButtonStateService } from '../../../services/button-state.service';
|
||||||
|
import { AuthService } from '../../../services/auth.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-forgot-pw',
|
selector: 'app-forgot-pw',
|
||||||
|
|
@ -30,14 +30,14 @@ export class ForgotPwComponent {
|
||||||
};
|
};
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
public loginService: LoginService,
|
private buttonStateService: ButtonStateService,
|
||||||
private buttonStateService: ButtonStateService
|
private authService: AuthService
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
onSubmit(ngForm: NgForm) {
|
onSubmit(ngForm: NgForm) {
|
||||||
this.buttonStateService.enableButton();
|
this.buttonStateService.enableButton();
|
||||||
if (ngForm.submitted && ngForm.form.valid) {
|
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;
|
return this.buttonStateService.isButtonDisabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
checkIfUserEmailIsValid(emailValue: string) {
|
isEmailValid(emailValue: string) {
|
||||||
const emailRegex = /^[\w.%+-]+@[\w.-]+\.[a-zA-Z]{2,}$/;
|
const emailRegex = /^[\w.%+-]+@[\w.-]+\.[a-zA-Z]{2,}$/;
|
||||||
if (emailRegex.test(emailValue)) {
|
if (emailRegex.test(emailValue)) {
|
||||||
return true;
|
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> {
|
checkAuthUser(): Observable<boolean> {
|
||||||
return this.apiService.request('GET', `/auth/`).pipe(
|
return this.apiService.request('GET', `/auth/`).pipe(
|
||||||
map(() => true),
|
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 {
|
showSessionExpiredMessage(): void {
|
||||||
this.createInfoToast(
|
this.createInfoToast(
|
||||||
'Your session has expired, please log in again.',
|
'Your session has expired, please log in again.',
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue