|
1 | 1 | import { Component, OnInit } from '@angular/core'; |
2 | 2 | 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'; |
4 | 4 | import { ActivatedRoute, Router, RouterLink } from '@angular/router'; |
5 | 5 | import { AuthService } from '../../services/auth.service'; |
6 | 6 | import { MessageService } from 'primeng/api'; |
@@ -33,20 +33,24 @@ export class ResetPassword implements OnInit { |
33 | 33 | private router: Router |
34 | 34 | ) { |
35 | 35 | this.resetForm = this.fb.group({ |
36 | | - password: ['', [Validators.required, Validators.minLength(6)]], |
| 36 | + password: ['', [Validators.required, Validators.minLength(8)]], |
37 | 37 | confirmPassword: ['', Validators.required] |
38 | 38 | }, { validators: this.passwordMatchValidator }); |
39 | 39 | } |
40 | 40 |
|
41 | 41 | 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 | + }); |
47 | 51 | } |
48 | 52 |
|
49 | | - passwordMatchValidator(g: FormGroup) { |
| 53 | + passwordMatchValidator(g: AbstractControl): ValidationErrors | null { |
50 | 54 | return g.get('password')?.value === g.get('confirmPassword')?.value |
51 | 55 | ? null : { mismatch: true }; |
52 | 56 | } |
|
0 commit comments