diff options
author | Chocobozzz <me@florianbigard.com> | 2020-06-23 14:49:20 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2020-06-23 16:00:49 +0200 |
commit | 1942f11d5ee6926ad93dc1b79fae18325ba5de18 (patch) | |
tree | 3f2a3cd9466a56c419d197ac832a3e9cbc86bec4 /client/src/app/+reset-password/reset-password.component.ts | |
parent | 67ed6552b831df66713bac9e672738796128d33f (diff) | |
download | PeerTube-1942f11d5ee6926ad93dc1b79fae18325ba5de18.tar.gz PeerTube-1942f11d5ee6926ad93dc1b79fae18325ba5de18.tar.zst PeerTube-1942f11d5ee6926ad93dc1b79fae18325ba5de18.zip |
Lazy load all routes
Diffstat (limited to 'client/src/app/+reset-password/reset-password.component.ts')
-rw-r--r-- | client/src/app/+reset-password/reset-password.component.ts | 61 |
1 files changed, 61 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..8d50e9839 --- /dev/null +++ b/client/src/app/+reset-password/reset-password.component.ts | |||
@@ -0,0 +1,61 @@ | |||
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 | import { I18n } from '@ngx-translate/i18n-polyfill' | ||
6 | |||
7 | @Component({ | ||
8 | selector: 'my-login', | ||
9 | templateUrl: './reset-password.component.html', | ||
10 | styleUrls: [ './reset-password.component.scss' ] | ||
11 | }) | ||
12 | |||
13 | export class ResetPasswordComponent extends FormReactive implements OnInit { | ||
14 | private userId: number | ||
15 | private verificationString: string | ||
16 | |||
17 | constructor ( | ||
18 | protected formValidatorService: FormValidatorService, | ||
19 | private resetPasswordValidatorsService: ResetPasswordValidatorsService, | ||
20 | private userValidatorsService: UserValidatorsService, | ||
21 | private userService: UserService, | ||
22 | private notifier: Notifier, | ||
23 | private router: Router, | ||
24 | private route: ActivatedRoute, | ||
25 | private i18n: I18n | ||
26 | ) { | ||
27 | super() | ||
28 | } | ||
29 | |||
30 | ngOnInit () { | ||
31 | this.buildForm({ | ||
32 | password: this.userValidatorsService.USER_PASSWORD, | ||
33 | 'password-confirm': this.resetPasswordValidatorsService.RESET_PASSWORD_CONFIRM | ||
34 | }) | ||
35 | |||
36 | this.userId = this.route.snapshot.queryParams['userId'] | ||
37 | this.verificationString = this.route.snapshot.queryParams['verificationString'] | ||
38 | |||
39 | if (!this.userId || !this.verificationString) { | ||
40 | this.notifier.error(this.i18n('Unable to find user id or verification string.')) | ||
41 | this.router.navigate([ '/' ]) | ||
42 | } | ||
43 | } | ||
44 | |||
45 | resetPassword () { | ||
46 | this.userService.resetPassword(this.userId, this.verificationString, this.form.value.password) | ||
47 | .subscribe( | ||
48 | () => { | ||
49 | this.notifier.success(this.i18n('Your password has been successfully reset!')) | ||
50 | this.router.navigate([ '/login' ]) | ||
51 | }, | ||
52 | |||
53 | err => this.notifier.error(err.message) | ||
54 | ) | ||
55 | } | ||
56 | |||
57 | isConfirmedPasswordValid () { | ||
58 | const values = this.form.value | ||
59 | return values.password === values['password-confirm'] | ||
60 | } | ||
61 | } | ||