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'
7 selector: 'my-account-change-password',
8 templateUrl: './my-account-change-password.component.html',
9 styleUrls: [ './my-account-change-password.component.scss' ]
11 export class MyAccountChangePasswordComponent extends FormReactive implements OnInit {
17 'new-confirmed-password': ''
19 validationMessages = {
20 'new-password': USER_PASSWORD.MESSAGES,
21 'new-confirmed-password': USER_PASSWORD.MESSAGES
25 private formBuilder: FormBuilder,
26 private notificationsService: NotificationsService,
27 private userService: UserService
33 this.form = this.formBuilder.group({
34 'new-password': [ '', USER_PASSWORD.VALIDATORS ],
35 'new-confirmed-password': [ '', USER_PASSWORD.VALIDATORS ]
38 this.form.valueChanges.subscribe(data => this.onValueChanged(data))
46 const newPassword = this.form.value['new-password']
47 const newConfirmedPassword = this.form.value['new-confirmed-password']
51 if (newPassword !== newConfirmedPassword) {
52 this.error = 'The new password and the confirmed password do not correspond.'
56 this.userService.changePassword(newPassword).subscribe(
57 () => this.notificationsService.success('Success', 'Password updated.'),
59 err => this.error = err.message