diff options
Diffstat (limited to 'client/src/app/account/account.component.ts')
-rw-r--r-- | client/src/app/account/account.component.ts | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/client/src/app/account/account.component.ts b/client/src/app/account/account.component.ts new file mode 100644 index 000000000..851eaf198 --- /dev/null +++ b/client/src/app/account/account.component.ts | |||
@@ -0,0 +1,67 @@ | |||
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'; | ||
5 | |||
6 | import { AccountService } from './account.service'; | ||
7 | import { FormReactive, USER_PASSWORD } from '../shared'; | ||
8 | |||
9 | @Component({ | ||
10 | selector: 'my-account', | ||
11 | templateUrl: './account.component.html' | ||
12 | }) | ||
13 | |||
14 | export class AccountComponent extends FormReactive implements OnInit { | ||
15 | information: string = null; | ||
16 | error: string = null; | ||
17 | |||
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 | |||
28 | constructor( | ||
29 | private accountService: AccountService, | ||
30 | private formBuilder: FormBuilder, | ||
31 | private router: Router | ||
32 | ) { | ||
33 | super(); | ||
34 | } | ||
35 | |||
36 | buildForm() { | ||
37 | this.form = this.formBuilder.group({ | ||
38 | 'new-password': [ '', USER_PASSWORD.VALIDATORS ], | ||
39 | 'new-confirmed-password': [ '', USER_PASSWORD.VALIDATORS ], | ||
40 | }); | ||
41 | |||
42 | this.form.valueChanges.subscribe(data => this.onValueChanged(data)); | ||
43 | } | ||
44 | |||
45 | ngOnInit() { | ||
46 | this.buildForm(); | ||
47 | } | ||
48 | |||
49 | changePassword() { | ||
50 | const newPassword = this.form.value['new-password']; | ||
51 | const newConfirmedPassword = this.form.value['new-confirmed-password']; | ||
52 | |||
53 | this.information = null; | ||
54 | this.error = null; | ||
55 | |||
56 | if (newPassword !== newConfirmedPassword) { | ||
57 | this.error = 'The new password and the confirmed password do not correspond.'; | ||
58 | return; | ||
59 | } | ||
60 | |||
61 | this.accountService.changePassword(newPassword).subscribe( | ||
62 | ok => this.information = 'Password updated.', | ||
63 | |||
64 | err => this.error = err | ||
65 | ); | ||
66 | } | ||
67 | } | ||