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',
11 templateUrl: './account.component.html'
14 export class AccountComponent 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 router: Router,
30 private notificationsService: NotificationsService,
31 private userService: UserService
37 this.form = this.formBuilder.group({
38 'new-password': [ '', USER_PASSWORD.VALIDATORS ],
39 'new-confirmed-password': [ '', USER_PASSWORD.VALIDATORS ],
42 this.form.valueChanges.subscribe(data => this.onValueChanged(data));
50 const newPassword = this.form.value['new-password'];
51 const newConfirmedPassword = this.form.value['new-confirmed-password'];
55 if (newPassword !== newConfirmedPassword) {
56 this.error = 'The new password and the confirmed password do not correspond.';
60 this.userService.changePassword(newPassword).subscribe(
61 () => this.notificationsService.success('Success', 'Password updated.'),
63 err => this.error = err