]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/reset-password/reset-password.component.ts
Translated using Weblate (Catalan)
[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'
f8b2c1b4
C
3import { UserService, UserValidatorsService, FormReactive } from '@app/shared'
4import { Notifier } from '@app/core'
b1d40cff 5import { I18n } from '@ngx-translate/i18n-polyfill'
d18d6478 6import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
e309822b 7import { ResetPasswordValidatorsService } from '@app/shared/forms/form-validators/reset-password-validators.service'
ecb4e35f
C
8
9@Component({
10 selector: 'my-login',
11 templateUrl: './reset-password.component.html',
12 styleUrls: [ './reset-password.component.scss' ]
13})
14
15export class ResetPasswordComponent extends FormReactive implements OnInit {
ecb4e35f
C
16 private userId: number
17 private verificationString: string
18
19 constructor (
d18d6478 20 protected formValidatorService: FormValidatorService,
e309822b
C
21 private resetPasswordValidatorsService: ResetPasswordValidatorsService,
22 private userValidatorsService: UserValidatorsService,
ecb4e35f 23 private userService: UserService,
f8b2c1b4 24 private notifier: Notifier,
ecb4e35f 25 private router: Router,
b1d40cff
C
26 private route: ActivatedRoute,
27 private i18n: I18n
ecb4e35f
C
28 ) {
29 super()
30 }
31
ecb4e35f 32 ngOnInit () {
d18d6478 33 this.buildForm({
e309822b
C
34 password: this.userValidatorsService.USER_PASSWORD,
35 'password-confirm': this.resetPasswordValidatorsService.RESET_PASSWORD_CONFIRM
d18d6478 36 })
ecb4e35f
C
37
38 this.userId = this.route.snapshot.queryParams['userId']
39 this.verificationString = this.route.snapshot.queryParams['verificationString']
40
41 if (!this.userId || !this.verificationString) {
f8b2c1b4 42 this.notifier.error(this.i18n('Unable to find user id or verification string.'))
ecb4e35f
C
43 this.router.navigate([ '/' ])
44 }
45 }
46
47 resetPassword () {
48 this.userService.resetPassword(this.userId, this.verificationString, this.form.value.password)
49 .subscribe(
50 () => {
f8b2c1b4 51 this.notifier.success(this.i18n('Your password has been successfully reset!'))
ecb4e35f
C
52 this.router.navigate([ '/login' ])
53 },
54
f8b2c1b4 55 err => this.notifier.error(err.message)
ecb4e35f
C
56 )
57 }
58
59 isConfirmedPasswordValid () {
60 const values = this.form.value
61 return values.password === values['password-confirm']
62 }
63}