diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2016-08-05 18:04:08 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2016-08-05 18:04:08 +0200 |
commit | 629d8d6f70cf83b55011dff53bfe1c4a95ac3433 (patch) | |
tree | 9d5a145609d9c693ddacfbc42ae75ca3c841aef0 /client/src/app/account | |
parent | 99a64bfed25e45547df3045cf249bc895e6f220b (diff) | |
download | PeerTube-629d8d6f70cf83b55011dff53bfe1c4a95ac3433.tar.gz PeerTube-629d8d6f70cf83b55011dff53bfe1c4a95ac3433.tar.zst PeerTube-629d8d6f70cf83b55011dff53bfe1c4a95ac3433.zip |
Client: implement password change
Diffstat (limited to 'client/src/app/account')
-rw-r--r-- | client/src/app/account/account.component.html | 27 | ||||
-rw-r--r-- | client/src/app/account/account.component.ts | 45 | ||||
-rw-r--r-- | client/src/app/account/account.routes.ts | 5 | ||||
-rw-r--r-- | client/src/app/account/account.service.ts | 19 | ||||
-rw-r--r-- | client/src/app/account/index.ts | 2 |
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 @@ | |||
1 | import { Control, ControlGroup, Validators } from '@angular/common'; | ||
2 | import { Component, OnInit } from '@angular/core'; | ||
3 | import { Router } from '@angular/router'; | ||
4 | |||
5 | import { AccountService } from './account.service'; | ||
6 | |||
7 | @Component({ | ||
8 | selector: 'my-account', | ||
9 | template: require('./account.component.html'), | ||
10 | providers: [ AccountService ] | ||
11 | }) | ||
12 | |||
13 | export 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 @@ | |||
1 | import { AccountComponent } from './account.component'; | ||
2 | |||
3 | export 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 @@ | |||
1 | import { Injectable } from '@angular/core'; | ||
2 | |||
3 | import { AuthHttp, AuthService } from '../shared'; | ||
4 | |||
5 | @Injectable() | ||
6 | export 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 @@ | |||
1 | export * from './account.component'; | ||
2 | export * from './account.routes'; | ||