]>
Commit | Line | Data |
---|---|---|
1 | import { Component, OnInit } from '@angular/core' | |
2 | import { ActivatedRoute, Router } from '@angular/router' | |
3 | import { Notifier, UserService } from '@app/core' | |
4 | import { RESET_PASSWORD_CONFIRM_VALIDATOR } from '@app/shared/form-validators/reset-password-validators' | |
5 | import { USER_PASSWORD_VALIDATOR } from '@app/shared/form-validators/user-validators' | |
6 | import { FormReactive, FormValidatorService } from '@app/shared/shared-forms' | |
7 | ||
8 | @Component({ | |
9 | selector: 'my-login', | |
10 | templateUrl: './reset-password.component.html', | |
11 | styleUrls: [ './reset-password.component.scss' ] | |
12 | }) | |
13 | ||
14 | export class ResetPasswordComponent extends FormReactive implements OnInit { | |
15 | private userId: number | |
16 | private verificationString: string | |
17 | ||
18 | constructor ( | |
19 | protected formValidatorService: FormValidatorService, | |
20 | private userService: UserService, | |
21 | private notifier: Notifier, | |
22 | private router: Router, | |
23 | private route: ActivatedRoute | |
24 | ) { | |
25 | super() | |
26 | } | |
27 | ||
28 | ngOnInit () { | |
29 | this.buildForm({ | |
30 | password: USER_PASSWORD_VALIDATOR, | |
31 | 'password-confirm': RESET_PASSWORD_CONFIRM_VALIDATOR | |
32 | }) | |
33 | ||
34 | this.userId = this.route.snapshot.queryParams['userId'] | |
35 | this.verificationString = this.route.snapshot.queryParams['verificationString'] | |
36 | ||
37 | if (!this.userId || !this.verificationString) { | |
38 | this.notifier.error($localize`Unable to find user id or verification string.`) | |
39 | this.router.navigate([ '/' ]) | |
40 | } | |
41 | } | |
42 | ||
43 | resetPassword () { | |
44 | this.userService.resetPassword(this.userId, this.verificationString, this.form.value.password) | |
45 | .subscribe( | |
46 | () => { | |
47 | this.notifier.success($localize`Your password has been successfully reset!`) | |
48 | this.router.navigate([ '/login' ]) | |
49 | }, | |
50 | ||
51 | err => this.notifier.error(err.message) | |
52 | ) | |
53 | } | |
54 | ||
55 | isConfirmedPasswordValid () { | |
56 | const values = this.form.value | |
57 | return values.password === values['password-confirm'] | |
58 | } | |
59 | } |