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/account.component.ts | |
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/account.component.ts')
-rw-r--r-- | client/src/app/account/account.component.ts | 45 |
1 files changed, 45 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..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 | } | ||