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'
8 selector: 'my-account-change-password',
9 templateUrl: './my-account-change-password.component.html',
10 styleUrls: [ './my-account-change-password.component.scss' ]
12 export class MyAccountChangePasswordComponent extends FormReactive implements OnInit {
18 'new-confirmed-password': ''
20 validationMessages = {
21 'new-password': USER_PASSWORD.MESSAGES,
22 'new-confirmed-password': USER_PASSWORD.MESSAGES
26 private formBuilder: FormBuilder,
27 private notificationsService: NotificationsService,
28 private userService: UserService,
35 this.form = this.formBuilder.group({
36 'new-password': [ '', USER_PASSWORD.VALIDATORS ],
37 'new-confirmed-password': [ '', USER_PASSWORD.VALIDATORS ]
40 this.form.valueChanges.subscribe(data => this.onValueChanged(data))
48 const newPassword = this.form.value['new-password']
49 const newConfirmedPassword = this.form.value['new-confirmed-password']
53 if (newPassword !== newConfirmedPassword) {
54 this.error = this.i18n('The new password and the confirmed password do not correspond.')
58 this.userService.changePassword(newPassword).subscribe(
59 () => this.notificationsService.success(this.i18n('Success'), this.i18n('Password updated.')),
61 err => this.error = err.message