]> 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
Add i18n attributes
[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 { FormBuilder, FormGroup } from '@angular/forms'
3 import { NotificationsService } from 'angular2-notifications'
4 import { FormReactive, USER_PASSWORD, UserService } from '../../../shared'
5 import { I18n } from '@ngx-translate/i18n-polyfill'
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 form: FormGroup
16 formErrors = {
17 'new-password': '',
18 'new-confirmed-password': ''
19 }
20 validationMessages = {
21 'new-password': USER_PASSWORD.MESSAGES,
22 'new-confirmed-password': USER_PASSWORD.MESSAGES
23 }
24
25 constructor (
26 private formBuilder: FormBuilder,
27 private notificationsService: NotificationsService,
28 private userService: UserService,
29 private i18n: I18n
30 ) {
31 super()
32 }
33
34 buildForm () {
35 this.form = this.formBuilder.group({
36 'new-password': [ '', USER_PASSWORD.VALIDATORS ],
37 'new-confirmed-password': [ '', USER_PASSWORD.VALIDATORS ]
38 })
39
40 this.form.valueChanges.subscribe(data => this.onValueChanged(data))
41 }
42
43 ngOnInit () {
44 this.buildForm()
45 }
46
47 changePassword () {
48 const newPassword = this.form.value['new-password']
49 const newConfirmedPassword = this.form.value['new-confirmed-password']
50
51 this.error = null
52
53 if (newPassword !== newConfirmedPassword) {
54 this.error = this.i18n('The new password and the confirmed password do not correspond.')
55 return
56 }
57
58 this.userService.changePassword(newPassword).subscribe(
59 () => this.notificationsService.success(this.i18n('Success'), this.i18n('Password updated.')),
60
61 err => this.error = err.message
62 )
63 }
64 }