aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/account/account.component.ts
blob: a22738d3f509a6ce011db8a7140ea923ff22c266 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import {  } from '@angular/common';
import { Component, OnInit } from '@angular/core';
import { FormControl, FormGroup, Validators } from '@angular/forms';
import { Router } from '@angular/router';

import { AccountService } from './account.service';

@Component({
  selector: 'my-account',
  template: require('./account.component.html')
})

export class AccountComponent implements OnInit {
  newPassword = '';
  newConfirmedPassword = '';
  changePasswordForm: FormGroup;
  information: string = null;
  error: string = null;

  constructor(
    private accountService: AccountService,
    private router: Router
  ) {}

  ngOnInit() {
    this.changePasswordForm = new FormGroup({
      'new-password': new FormControl('', [ <any>Validators.required, <any>Validators.minLength(6) ]),
      'new-confirmed-password': new FormControl('', [ <any>Validators.required, <any>Validators.minLength(6) ]),
    });
  }

  changePassword() {
    this.information = null;
    this.error = null;

    if (this.newPassword !== this.newConfirmedPassword) {
      this.error = 'The new password and the confirmed password do not correspond.';
      return;
    }

    this.accountService.changePassword(this.newPassword).subscribe(
      ok => this.information = 'Password updated.',

      err => this.error = err
    );
  }
}