]>
Commit | Line | Data |
---|---|---|
ab32b0fc | 1 | import { } from '@angular/common'; |
629d8d6f | 2 | import { Component, OnInit } from '@angular/core'; |
4b2f33f3 | 3 | import { FormBuilder, FormGroup } from '@angular/forms'; |
629d8d6f C |
4 | import { Router } from '@angular/router'; |
5 | ||
6 | import { AccountService } from './account.service'; | |
4b2f33f3 | 7 | import { FormReactive, USER_PASSWORD } from '../shared'; |
629d8d6f C |
8 | |
9 | @Component({ | |
10 | selector: 'my-account', | |
ec8d8440 | 11 | templateUrl: './account.component.html' |
629d8d6f C |
12 | }) |
13 | ||
4b2f33f3 | 14 | export class AccountComponent extends FormReactive implements OnInit { |
629d8d6f C |
15 | information: string = null; |
16 | error: string = null; | |
17 | ||
4b2f33f3 C |
18 | form: FormGroup; |
19 | formErrors = { | |
20 | 'new-password': '', | |
21 | 'new-confirmed-password': '' | |
22 | }; | |
23 | validationMessages = { | |
24 | 'new-password': USER_PASSWORD.MESSAGES, | |
25 | 'new-confirmed-password': USER_PASSWORD.MESSAGES | |
26 | }; | |
27 | ||
629d8d6f C |
28 | constructor( |
29 | private accountService: AccountService, | |
4b2f33f3 | 30 | private formBuilder: FormBuilder, |
629d8d6f | 31 | private router: Router |
4b2f33f3 C |
32 | ) { |
33 | super(); | |
34 | } | |
629d8d6f | 35 | |
4b2f33f3 C |
36 | buildForm() { |
37 | this.form = this.formBuilder.group({ | |
38 | 'new-password': [ '', USER_PASSWORD.VALIDATORS ], | |
39 | 'new-confirmed-password': [ '', USER_PASSWORD.VALIDATORS ], | |
629d8d6f | 40 | }); |
4b2f33f3 C |
41 | |
42 | this.form.valueChanges.subscribe(data => this.onValueChanged(data)); | |
43 | } | |
44 | ||
45 | ngOnInit() { | |
46 | this.buildForm(); | |
629d8d6f C |
47 | } |
48 | ||
0f6da32b | 49 | changePassword() { |
4b2f33f3 C |
50 | const newPassword = this.form.value['new-password']; |
51 | const newConfirmedPassword = this.form.value['new-confirmed-password']; | |
52 | ||
629d8d6f C |
53 | this.information = null; |
54 | this.error = null; | |
55 | ||
4b2f33f3 | 56 | if (newPassword !== newConfirmedPassword) { |
629d8d6f C |
57 | this.error = 'The new password and the confirmed password do not correspond.'; |
58 | return; | |
59 | } | |
60 | ||
4b2f33f3 | 61 | this.accountService.changePassword(newPassword).subscribe( |
629d8d6f C |
62 | ok => this.information = 'Password updated.', |
63 | ||
64 | err => this.error = err | |
65 | ); | |
66 | } | |
67 | } |