]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+my-account/my-account-settings/my-account-change-password/my-account-change-password.component.ts
Form validators refractoring
[github/Chocobozzz/PeerTube.git] / client / src / app / +my-account / my-account-settings / my-account-change-password / my-account-change-password.component.ts
1 import { Component, OnInit } from '@angular/core'
2 import { NotificationsService } from 'angular2-notifications'
3 import { FormReactive, USER_PASSWORD, UserService } from '../../../shared'
4 import { I18n } from '@ngx-translate/i18n-polyfill'
5 import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
6
7 @Component({
8 selector: 'my-account-change-password',
9 templateUrl: './my-account-change-password.component.html',
10 styleUrls: [ './my-account-change-password.component.scss' ]
11 })
12 export class MyAccountChangePasswordComponent extends FormReactive implements OnInit {
13 error: string = null
14
15 constructor (
16 protected formValidatorService: FormValidatorService,
17 private notificationsService: NotificationsService,
18 private userService: UserService,
19 private i18n: I18n
20 ) {
21 super()
22 }
23
24 ngOnInit () {
25 this.buildForm({
26 'new-password': USER_PASSWORD,
27 'new-confirmed-password': USER_PASSWORD
28 })
29 }
30
31 changePassword () {
32 const newPassword = this.form.value['new-password']
33 const newConfirmedPassword = this.form.value['new-confirmed-password']
34
35 this.error = null
36
37 if (newPassword !== newConfirmedPassword) {
38 this.error = this.i18n('The new password and the confirmed password do not correspond.')
39 return
40 }
41
42 this.userService.changePassword(newPassword).subscribe(
43 () => this.notificationsService.success(this.i18n('Success'), this.i18n('Password updated.')),
44
45 err => this.error = err.message
46 )
47 }
48 }