]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/reset-password/reset-password.component.ts
Support different playback rates (#318)
[github/Chocobozzz/PeerTube.git] / client / src / app / reset-password / reset-password.component.ts
1 import { Component, OnInit } from '@angular/core'
2 import { FormBuilder, FormGroup, Validators } from '@angular/forms'
3 import { ActivatedRoute, Router } from '@angular/router'
4 import { USER_PASSWORD, UserService } from '@app/shared'
5 import { NotificationsService } from 'angular2-notifications'
6 import { AuthService } from '../core'
7 import { FormReactive } from '../shared'
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 form: FormGroup
17 formErrors = {
18 'password': '',
19 'password-confirm': ''
20 }
21 validationMessages = {
22 'password': USER_PASSWORD.MESSAGES,
23 'password-confirm': {
24 'required': 'Confirmation of the password is required.'
25 }
26 }
27
28 private userId: number
29 private verificationString: string
30
31 constructor (
32 private authService: AuthService,
33 private userService: UserService,
34 private notificationsService: NotificationsService,
35 private formBuilder: FormBuilder,
36 private router: Router,
37 private route: ActivatedRoute
38 ) {
39 super()
40 }
41
42 buildForm () {
43 this.form = this.formBuilder.group({
44 password: [ '', USER_PASSWORD.VALIDATORS ],
45 'password-confirm': [ '', Validators.required ]
46 })
47
48 this.form.valueChanges.subscribe(data => this.onValueChanged(data))
49 }
50
51 ngOnInit () {
52 this.buildForm()
53
54 this.userId = this.route.snapshot.queryParams['userId']
55 this.verificationString = this.route.snapshot.queryParams['verificationString']
56
57 if (!this.userId || !this.verificationString) {
58 this.notificationsService.error('Error', 'Unable to find user id or verification string.')
59 this.router.navigate([ '/' ])
60 }
61 }
62
63 resetPassword () {
64 this.userService.resetPassword(this.userId, this.verificationString, this.form.value.password)
65 .subscribe(
66 () => {
67 this.notificationsService.success('Success', 'Your password has been successfully reset!')
68 this.router.navigate([ '/login' ])
69 },
70
71 err => this.notificationsService.error('Error', err.message)
72 )
73 }
74
75 isConfirmedPasswordValid () {
76 const values = this.form.value
77 return values.password === values['password-confirm']
78 }
79 }