Skip to content

Commit a71f303

Browse files
committed
feat: Add new password reset page with form validation and success/error handling.
1 parent 39f3f58 commit a71f303

3 files changed

Lines changed: 17 additions & 10 deletions

File tree

src/app/pages/reset-password/reset-password.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
@if (resetForm.get('password')?.invalid && (resetForm.get('password')?.dirty ||
1818
resetForm.get('password')?.touched)) {
1919
<small class="p-error block">
20-
Password is required (min 6 chars).
20+
Password is required (min 8 chars).
2121
</small>
2222
}
2323
</div>

src/app/pages/reset-password/reset-password.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Component, OnInit } from '@angular/core';
22
import { CommonModule } from '@angular/common';
3-
import { FormBuilder, FormGroup, Validators, ReactiveFormsModule } from '@angular/forms';
3+
import { FormBuilder, FormGroup, Validators, ReactiveFormsModule, AbstractControl, ValidationErrors } from '@angular/forms';
44
import { ActivatedRoute, Router, RouterLink } from '@angular/router';
55
import { AuthService } from '../../services/auth.service';
66
import { MessageService } from 'primeng/api';
@@ -33,20 +33,24 @@ export class ResetPassword implements OnInit {
3333
private router: Router
3434
) {
3535
this.resetForm = this.fb.group({
36-
password: ['', [Validators.required, Validators.minLength(6)]],
36+
password: ['', [Validators.required, Validators.minLength(8)]],
3737
confirmPassword: ['', Validators.required]
3838
}, { validators: this.passwordMatchValidator });
3939
}
4040

4141
ngOnInit() {
42-
this.token = this.route.snapshot.queryParamMap.get('token') || '';
43-
if (!this.token) {
44-
this.messageService.add({ severity: 'error', summary: 'Error', detail: 'Invalid or missing token.' });
45-
setTimeout(() => this.router.navigate(['/login']), 2000);
46-
}
42+
this.route.queryParamMap.subscribe(params => {
43+
this.token = params.get('token') || '';
44+
if (!this.token) {
45+
setTimeout(() => {
46+
this.messageService.add({ severity: 'error', summary: 'Error', detail: 'Invalid or missing token.' });
47+
this.router.navigate(['/login']);
48+
}, 500);
49+
}
50+
});
4751
}
4852

49-
passwordMatchValidator(g: FormGroup) {
53+
passwordMatchValidator(g: AbstractControl): ValidationErrors | null {
5054
return g.get('password')?.value === g.get('confirmPassword')?.value
5155
? null : { mismatch: true };
5256
}

src/app/services/auth.service.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Observable, BehaviorSubject, of } from 'rxjs';
44
import { tap, map, catchError, switchMap } from 'rxjs/operators';
55
import { LoginRequest, AuthResponse, RegisterRequest } from '../models/auth.models';
66
import { CsrfService } from './csrf.service';
7+
import { SKIP_ERROR_TOAST } from '../data/http-context.tokens';
78

89
import { environment } from '../../environments/environment';
910

@@ -142,7 +143,9 @@ export class AuthService {
142143
if (this.authenticated) {
143144
return of(true);
144145
}
145-
return this.http.get<any>(`${this.apiUrl}/me`);
146+
return this.http.get<any>(`${this.apiUrl}/me`, {
147+
context: new HttpContext().set(SKIP_ERROR_TOAST, true)
148+
});
146149
}),
147150
tap(user => {
148151
if (user !== true && user) {

0 commit comments

Comments
 (0)