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