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