]>
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 { FormReactive, FormValidatorService, ResetPasswordValidatorsService, UserValidatorsService } from '@app/shared/shared-forms' | |
5 | ||
6 | @Component({ | |
7 | selector: 'my-login', | |
8 | templateUrl: './reset-password.component.html', | |
9 | styleUrls: [ './reset-password.component.scss' ] | |
10 | }) | |
11 | ||
12 | export class ResetPasswordComponent extends FormReactive implements OnInit { | |
13 | private userId: number | |
14 | private verificationString: string | |
15 | ||
16 | constructor ( | |
17 | protected formValidatorService: FormValidatorService, | |
18 | private resetPasswordValidatorsService: ResetPasswordValidatorsService, | |
19 | private userValidatorsService: UserValidatorsService, | |
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: this.userValidatorsService.USER_PASSWORD, | |
31 | 'password-confirm': this.resetPasswordValidatorsService.RESET_PASSWORD_CONFIRM | |
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 | } |