diff options
author | Chocobozzz <me@florianbigard.com> | 2018-01-30 13:27:07 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-01-30 13:27:07 +0100 |
commit | ecb4e35f4e6c7304cb274593c13cb47fd5078b75 (patch) | |
tree | 1e238002340bc521afde59d52f406e41298a7aac /client/src/app/reset-password/reset-password.component.ts | |
parent | 80d1057bfcd3582af0dacf5ccd5a7a93ef95410b (diff) | |
download | PeerTube-ecb4e35f4e6c7304cb274593c13cb47fd5078b75.tar.gz PeerTube-ecb4e35f4e6c7304cb274593c13cb47fd5078b75.tar.zst PeerTube-ecb4e35f4e6c7304cb274593c13cb47fd5078b75.zip |
Add ability to reset our password
Diffstat (limited to 'client/src/app/reset-password/reset-password.component.ts')
-rw-r--r-- | client/src/app/reset-password/reset-password.component.ts | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/client/src/app/reset-password/reset-password.component.ts b/client/src/app/reset-password/reset-password.component.ts new file mode 100644 index 000000000..408374779 --- /dev/null +++ b/client/src/app/reset-password/reset-password.component.ts | |||
@@ -0,0 +1,79 @@ | |||
1 | import { Component, OnInit } from '@angular/core' | ||
2 | import { FormBuilder, FormGroup, Validators } from '@angular/forms' | ||
3 | import { ActivatedRoute, Router } from '@angular/router' | ||
4 | import { USER_PASSWORD, UserService } from '@app/shared' | ||
5 | import { NotificationsService } from 'angular2-notifications' | ||
6 | import { AuthService } from '../core' | ||
7 | import { FormReactive } from '../shared' | ||
8 | |||
9 | @Component({ | ||
10 | selector: 'my-login', | ||
11 | templateUrl: './reset-password.component.html', | ||
12 | styleUrls: [ './reset-password.component.scss' ] | ||
13 | }) | ||
14 | |||
15 | export class ResetPasswordComponent extends FormReactive implements OnInit { | ||
16 | form: FormGroup | ||
17 | formErrors = { | ||
18 | 'password': '', | ||
19 | 'password-confirm': '' | ||
20 | } | ||
21 | validationMessages = { | ||
22 | 'password': USER_PASSWORD.MESSAGES, | ||
23 | 'password-confirm': { | ||
24 | 'required': 'Confirmation of the password is required.' | ||
25 | } | ||
26 | } | ||
27 | |||
28 | private userId: number | ||
29 | private verificationString: string | ||
30 | |||
31 | constructor ( | ||
32 | private authService: AuthService, | ||
33 | private userService: UserService, | ||
34 | private notificationsService: NotificationsService, | ||
35 | private formBuilder: FormBuilder, | ||
36 | private router: Router, | ||
37 | private route: ActivatedRoute | ||
38 | ) { | ||
39 | super() | ||
40 | } | ||
41 | |||
42 | buildForm () { | ||
43 | this.form = this.formBuilder.group({ | ||
44 | password: [ '', USER_PASSWORD.VALIDATORS ], | ||
45 | 'password-confirm': [ '', Validators.required ] | ||
46 | }) | ||
47 | |||
48 | this.form.valueChanges.subscribe(data => this.onValueChanged(data)) | ||
49 | } | ||
50 | |||
51 | ngOnInit () { | ||
52 | this.buildForm() | ||
53 | |||
54 | this.userId = this.route.snapshot.queryParams['userId'] | ||
55 | this.verificationString = this.route.snapshot.queryParams['verificationString'] | ||
56 | |||
57 | if (!this.userId || !this.verificationString) { | ||
58 | this.notificationsService.error('Error', 'Unable to find user id or verification string.') | ||
59 | this.router.navigate([ '/' ]) | ||
60 | } | ||
61 | } | ||
62 | |||
63 | resetPassword () { | ||
64 | this.userService.resetPassword(this.userId, this.verificationString, this.form.value.password) | ||
65 | .subscribe( | ||
66 | () => { | ||
67 | this.notificationsService.success('Success', 'Your password has been successfully reset!') | ||
68 | this.router.navigate([ '/login' ]) | ||
69 | }, | ||
70 | |||
71 | err => this.notificationsService.error('Error', err.message) | ||
72 | ) | ||
73 | } | ||
74 | |||
75 | isConfirmedPasswordValid () { | ||
76 | const values = this.form.value | ||
77 | return values.password === values['password-confirm'] | ||
78 | } | ||
79 | } | ||