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