]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+reset-password/reset-password.component.ts
Bumped to version v5.2.1
[github/Chocobozzz/PeerTube.git] / client / src / app / +reset-password / reset-password.component.ts
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, FormReactiveService } 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 formReactiveService: FormReactiveService,
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 next: () => {
47 this.notifier.success($localize`Your password has been successfully reset!`)
48
49 this.router.navigate([ '/login' ])
50 },
51
52 error: err => this.notifier.error(err.message)
53 })
54 }
55
56 isConfirmedPasswordValid () {
57 const values = this.form.value
58 return values.password === values['password-confirm']
59 }
60 }