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 { AccountService } from './account.service';
8 import { FormReactive, USER_PASSWORD } from '../shared';
11 selector: 'my-account',
12 templateUrl: './account.component.html'
15 export class AccountComponent extends FormReactive implements OnInit {
21 'new-confirmed-password': ''
23 validationMessages = {
24 'new-password': USER_PASSWORD.MESSAGES,
25 'new-confirmed-password': USER_PASSWORD.MESSAGES
29 private formBuilder: FormBuilder,
30 private router: Router,
31 private notificationsService: NotificationsService,
32 private accountService: AccountService
38 this.form = this.formBuilder.group({
39 'new-password': [ '', USER_PASSWORD.VALIDATORS ],
40 'new-confirmed-password': [ '', USER_PASSWORD.VALIDATORS ],
43 this.form.valueChanges.subscribe(data => this.onValueChanged(data));
51 const newPassword = this.form.value['new-password'];
52 const newConfirmedPassword = this.form.value['new-confirmed-password'];
56 if (newPassword !== newConfirmedPassword) {
57 this.error = 'The new password and the confirmed password do not correspond.';
61 this.accountService.changePassword(newPassword).subscribe(
62 () => this.notificationsService.success('Success', 'Password updated.'),
64 err => this.error = err