aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/account
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/account')
-rw-r--r--client/src/app/account/account.component.html27
-rw-r--r--client/src/app/account/account.component.ts45
-rw-r--r--client/src/app/account/account.routes.ts5
-rw-r--r--client/src/app/account/account.service.ts19
-rw-r--r--client/src/app/account/index.ts2
5 files changed, 98 insertions, 0 deletions
diff --git a/client/src/app/account/account.component.html b/client/src/app/account/account.component.html
new file mode 100644
index 000000000..ad8f690bd
--- /dev/null
+++ b/client/src/app/account/account.component.html
@@ -0,0 +1,27 @@
1<h3>Account</h3>
2
3<div *ngIf="information" class="alert alert-success">{{ information }}</div>
4<div *ngIf="error" class="alert alert-danger">{{ error }}</div>
5
6<form role="form" (ngSubmit)="changePassword(newPassword.value, newConfirmedPassword.value)" [ngFormModel]="changePasswordForm">
7 <div class="form-group">
8 <label for="new-password">New password</label>
9 <input
10 type="password" class="form-control" name="new-password" id="new-password"
11 ngControl="newPassword" #newPassword="ngForm"
12 >
13 <div [hidden]="newPassword.valid || newPassword.pristine" class="alert alert-warning">
14 The password should have more than 5 characters
15 </div>
16 </div>
17
18 <div class="form-group">
19 <label for="name">Confirm new password</label>
20 <input
21 type="password" class="form-control" name="new-confirmed-password" id="new-confirmed-password"
22 ngControl="newConfirmedPassword" #newConfirmedPassword="ngForm"
23 >
24 </div>
25
26 <input type="submit" value="Change password" class="btn btn-default" [disabled]="!changePasswordForm.valid">
27</form>
diff --git a/client/src/app/account/account.component.ts b/client/src/app/account/account.component.ts
new file mode 100644
index 000000000..5c42103f8
--- /dev/null
+++ b/client/src/app/account/account.component.ts
@@ -0,0 +1,45 @@
1import { Control, ControlGroup, Validators } from '@angular/common';
2import { Component, OnInit } from '@angular/core';
3import { Router } from '@angular/router';
4
5import { AccountService } from './account.service';
6
7@Component({
8 selector: 'my-account',
9 template: require('./account.component.html'),
10 providers: [ AccountService ]
11})
12
13export class AccountComponent implements OnInit {
14 changePasswordForm: ControlGroup;
15 information: string = null;
16 error: string = null;
17
18 constructor(
19 private accountService: AccountService,
20 private router: Router
21 ) {}
22
23 ngOnInit() {
24 this.changePasswordForm = new ControlGroup({
25 newPassword: new Control('', Validators.compose([ Validators.required, Validators.minLength(6) ])),
26 newConfirmedPassword: new Control('', Validators.compose([ Validators.required, Validators.minLength(6) ])),
27 });
28 }
29
30 changePassword(newPassword: string, newConfirmedPassword: string) {
31 this.information = null;
32 this.error = null;
33
34 if (newPassword !== newConfirmedPassword) {
35 this.error = 'The new password and the confirmed password do not correspond.';
36 return;
37 }
38
39 this.accountService.changePassword(newPassword).subscribe(
40 ok => this.information = 'Password updated.',
41
42 err => this.error = err
43 );
44 }
45}
diff --git a/client/src/app/account/account.routes.ts b/client/src/app/account/account.routes.ts
new file mode 100644
index 000000000..e348c6ebe
--- /dev/null
+++ b/client/src/app/account/account.routes.ts
@@ -0,0 +1,5 @@
1import { AccountComponent } from './account.component';
2
3export const AccountRoutes = [
4 { path: 'account', component: AccountComponent }
5];
diff --git a/client/src/app/account/account.service.ts b/client/src/app/account/account.service.ts
new file mode 100644
index 000000000..19b4e0624
--- /dev/null
+++ b/client/src/app/account/account.service.ts
@@ -0,0 +1,19 @@
1import { Injectable } from '@angular/core';
2
3import { AuthHttp, AuthService } from '../shared';
4
5@Injectable()
6export class AccountService {
7 private static BASE_USERS_URL = '/api/v1/users/';
8
9 constructor(private authHttp: AuthHttp, private authService: AuthService) { }
10
11 changePassword(newPassword: string) {
12 const url = AccountService.BASE_USERS_URL + this.authService.getUser().id;
13 const body = {
14 password: newPassword
15 };
16
17 return this.authHttp.put(url, body);
18 }
19}
diff --git a/client/src/app/account/index.ts b/client/src/app/account/index.ts
new file mode 100644
index 000000000..7445003fd
--- /dev/null
+++ b/client/src/app/account/index.ts
@@ -0,0 +1,2 @@
1export * from './account.component';
2export * from './account.routes';