]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/account/account-change-password/account-change-password.component.ts
Add auto scroll to videos list
[github/Chocobozzz/PeerTube.git] / client / src / app / account / account-change-password / account-change-password.component.ts
1 import { Component, OnInit } from '@angular/core'
2 import { FormBuilder, FormGroup } from '@angular/forms'
3 import { Router } from '@angular/router'
4
5 import { NotificationsService } from 'angular2-notifications'
6
7 import { FormReactive, UserService, USER_PASSWORD } from '../../shared'
8
9 @Component({
10 selector: 'my-account-change-password',
11 templateUrl: './account-change-password.component.html'
12 })
13
14 export class AccountChangePasswordComponent extends FormReactive implements OnInit {
15 error: string = null
16
17 form: FormGroup
18 formErrors = {
19 'new-password': '',
20 'new-confirmed-password': ''
21 }
22 validationMessages = {
23 'new-password': USER_PASSWORD.MESSAGES,
24 'new-confirmed-password': USER_PASSWORD.MESSAGES
25 }
26
27 constructor (
28 private formBuilder: FormBuilder,
29 private notificationsService: NotificationsService,
30 private userService: UserService
31 ) {
32 super()
33 }
34
35 buildForm () {
36 this.form = this.formBuilder.group({
37 'new-password': [ '', USER_PASSWORD.VALIDATORS ],
38 'new-confirmed-password': [ '', USER_PASSWORD.VALIDATORS ]
39 })
40
41 this.form.valueChanges.subscribe(data => this.onValueChanged(data))
42 }
43
44 ngOnInit () {
45 this.buildForm()
46 }
47
48 changePassword () {
49 const newPassword = this.form.value['new-password']
50 const newConfirmedPassword = this.form.value['new-confirmed-password']
51
52 this.error = null
53
54 if (newPassword !== newConfirmedPassword) {
55 this.error = 'The new password and the confirmed password do not correspond.'
56 return
57 }
58
59 this.userService.changePassword(newPassword).subscribe(
60 () => this.notificationsService.success('Success', 'Password updated.'),
61
62 err => this.error = err.message
63 )
64 }
65 }