1 import { } from '@angular/common';
2 import { Component, OnInit } from '@angular/core';
3 import { FormBuilder, FormGroup } from '@angular/forms';
4 import { Router } from '@angular/router';
6 import { AccountService } from './account.service';
7 import { FormReactive, USER_PASSWORD } from '../shared';
10 selector: 'my-account',
11 template: require('./account.component.html')
14 export class AccountComponent extends FormReactive implements OnInit {
15 information: string = null;
21 'new-confirmed-password': ''
23 validationMessages = {
24 'new-password': USER_PASSWORD.MESSAGES,
25 'new-confirmed-password': USER_PASSWORD.MESSAGES
29 private accountService: AccountService,
30 private formBuilder: FormBuilder,
31 private router: Router
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'];
53 this.information = null;
56 if (newPassword !== newConfirmedPassword) {
57 this.error = 'The new password and the confirmed password do not correspond.';
61 this.accountService.changePassword(newPassword).subscribe(
62 ok => this.information = 'Password updated.',
64 err => this.error = err