aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/account/account-change-password
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/account/account-change-password')
-rw-r--r--client/src/app/account/account-change-password/account-change-password.component.html24
-rw-r--r--client/src/app/account/account-change-password/account-change-password.component.ts66
-rw-r--r--client/src/app/account/account-change-password/index.ts1
3 files changed, 91 insertions, 0 deletions
diff --git a/client/src/app/account/account-change-password/account-change-password.component.html b/client/src/app/account/account-change-password/account-change-password.component.html
new file mode 100644
index 000000000..92d9f900a
--- /dev/null
+++ b/client/src/app/account/account-change-password/account-change-password.component.html
@@ -0,0 +1,24 @@
1<div *ngIf="error" class="alert alert-danger">{{ error }}</div>
2
3<form role="form" (ngSubmit)="changePassword()" [formGroup]="form">
4 <div class="form-group">
5 <label for="new-password">New password</label>
6 <input
7 type="password" class="form-control" id="new-password"
8 formControlName="new-password"
9 >
10 <div *ngIf="formErrors['new-password']" class="alert alert-danger">
11 {{ formErrors['new-password'] }}
12 </div>
13 </div>
14
15 <div class="form-group">
16 <label for="name">Confirm new password</label>
17 <input
18 type="password" class="form-control" id="new-confirmed-password"
19 formControlName="new-confirmed-password"
20 >
21 </div>
22
23 <input type="submit" value="Change password" class="btn btn-default" [disabled]="!form.valid">
24</form>
diff --git a/client/src/app/account/account-change-password/account-change-password.component.ts b/client/src/app/account/account-change-password/account-change-password.component.ts
new file mode 100644
index 000000000..15dc42d22
--- /dev/null
+++ b/client/src/app/account/account-change-password/account-change-password.component.ts
@@ -0,0 +1,66 @@
1import { Component, OnInit } from '@angular/core';
2import { FormBuilder, FormGroup } from '@angular/forms';
3import { Router } from '@angular/router';
4
5import { NotificationsService } from 'angular2-notifications';
6
7import { FormReactive, UserService, USER_PASSWORD } from '../../shared';
8
9@Component({
10 selector: 'my-account-change-password',
11 templateUrl: './account-change-password.component.html'
12})
13
14export class AccountChangePasswordComponent extends FormReactive implements OnInit {
15 error: string = null;
16
17 form: FormGroup;
18 formErrors = {
19 'new-password': '',
20 'new-confirmed-password': ''
21 };
22 validationMessages = {
23 'new-password': USER_PASSWORD.MESSAGES,
24 'new-confirmed-password': USER_PASSWORD.MESSAGES
25 };
26
27 constructor(
28 private formBuilder: FormBuilder,
29 private router: Router,
30 private notificationsService: NotificationsService,
31 private userService: UserService
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.error = null;
54
55 if (newPassword !== newConfirmedPassword) {
56 this.error = 'The new password and the confirmed password do not correspond.';
57 return;
58 }
59
60 this.userService.changePassword(newPassword).subscribe(
61 () => this.notificationsService.success('Success', 'Password updated.'),
62
63 err => this.error = err
64 );
65 }
66}
diff --git a/client/src/app/account/account-change-password/index.ts b/client/src/app/account/account-change-password/index.ts
new file mode 100644
index 000000000..72a63e48d
--- /dev/null
+++ b/client/src/app/account/account-change-password/index.ts
@@ -0,0 +1 @@
export * from './account-change-password.component';