]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+reset-password/reset-password.component.ts
Migrate to $localize
[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
C
3import { Notifier, UserService } from '@app/core'
4import { FormReactive, FormValidatorService, ResetPasswordValidatorsService, UserValidatorsService } from '@app/shared/shared-forms'
ecb4e35f
C
5
6@Component({
7 selector: 'my-login',
8 templateUrl: './reset-password.component.html',
9 styleUrls: [ './reset-password.component.scss' ]
10})
11
12export class ResetPasswordComponent extends FormReactive implements OnInit {
ecb4e35f
C
13 private userId: number
14 private verificationString: string
15
16 constructor (
d18d6478 17 protected formValidatorService: FormValidatorService,
e309822b
C
18 private resetPasswordValidatorsService: ResetPasswordValidatorsService,
19 private userValidatorsService: UserValidatorsService,
ecb4e35f 20 private userService: UserService,
f8b2c1b4 21 private notifier: Notifier,
ecb4e35f 22 private router: Router,
66357162
C
23 private route: ActivatedRoute
24 ) {
ecb4e35f
C
25 super()
26 }
27
ecb4e35f 28 ngOnInit () {
d18d6478 29 this.buildForm({
e309822b
C
30 password: this.userValidatorsService.USER_PASSWORD,
31 'password-confirm': this.resetPasswordValidatorsService.RESET_PASSWORD_CONFIRM
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)
45 .subscribe(
46 () => {
66357162 47 this.notifier.success($localize`Your password has been successfully reset!`)
ecb4e35f
C
48 this.router.navigate([ '/login' ])
49 },
50
f8b2c1b4 51 err => this.notifier.error(err.message)
ecb4e35f
C
52 )
53 }
54
55 isConfirmedPasswordValid () {
56 const values = this.form.value
57 return values.password === values['password-confirm']
58 }
59}