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