1 import { Component, OnInit } from '@angular/core'
2 import { FormBuilder, FormGroup } from '@angular/forms'
3 import { Router } from '@angular/router'
5 import { NotificationsService } from 'angular2-notifications'
7 import { FormReactive, UserService, USER_PASSWORD } from '../../shared'
10 selector: 'my-account-change-password',
11 templateUrl: './account-change-password.component.html'
14 export class AccountChangePasswordComponent extends FormReactive implements OnInit {
20 'new-confirmed-password': ''
22 validationMessages = {
23 'new-password': USER_PASSWORD.MESSAGES,
24 'new-confirmed-password': USER_PASSWORD.MESSAGES
28 private formBuilder: FormBuilder,
29 private notificationsService: NotificationsService,
30 private userService: UserService
36 this.form = this.formBuilder.group({
37 'new-password': [ '', USER_PASSWORD.VALIDATORS ],
38 'new-confirmed-password': [ '', USER_PASSWORD.VALIDATORS ]
41 this.form.valueChanges.subscribe(data => this.onValueChanged(data))
49 const newPassword = this.form.value['new-password']
50 const newConfirmedPassword = this.form.value['new-confirmed-password']
54 if (newPassword !== newConfirmedPassword) {
55 this.error = 'The new password and the confirmed password do not correspond.'
59 this.userService.changePassword(newPassword).subscribe(
60 () => this.notificationsService.success('Success', 'Password updated.'),
62 err => this.error = err