diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-04-06 21:21:03 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-04-06 21:21:03 +0200 |
commit | af5e743b01f20f24d0c25e786d57f557b21f3a24 (patch) | |
tree | 5186d587135f13f00687f8ed6cd8504cdd35799f /client/src/app/account/account.component.ts | |
parent | 92fb909c9b4a92a00b0d0da7629e6fb003de281b (diff) | |
download | PeerTube-af5e743b01f20f24d0c25e786d57f557b21f3a24.tar.gz PeerTube-af5e743b01f20f24d0c25e786d57f557b21f3a24.tar.zst PeerTube-af5e743b01f20f24d0c25e786d57f557b21f3a24.zip |
Client: add ability for user to change nsfw settings
Diffstat (limited to 'client/src/app/account/account.component.ts')
-rw-r--r-- | client/src/app/account/account.component.ts | 64 |
1 files changed, 13 insertions, 51 deletions
diff --git a/client/src/app/account/account.component.ts b/client/src/app/account/account.component.ts index 14452a73e..57b3d4ccd 100644 --- a/client/src/app/account/account.component.ts +++ b/client/src/app/account/account.component.ts | |||
@@ -4,63 +4,25 @@ import { Router } from '@angular/router'; | |||
4 | 4 | ||
5 | import { NotificationsService } from 'angular2-notifications'; | 5 | import { NotificationsService } from 'angular2-notifications'; |
6 | 6 | ||
7 | import { FormReactive, UserService, USER_PASSWORD } from '../shared'; | 7 | import { AuthService } from '../core'; |
8 | import { | ||
9 | FormReactive, | ||
10 | User, | ||
11 | UserService, | ||
12 | USER_PASSWORD | ||
13 | } from '../shared'; | ||
8 | 14 | ||
9 | @Component({ | 15 | @Component({ |
10 | selector: 'my-account', | 16 | selector: 'my-account', |
11 | templateUrl: './account.component.html' | 17 | templateUrl: './account.component.html', |
18 | styleUrls: [ './account.component.scss' ] | ||
12 | }) | 19 | }) |
20 | export class AccountComponent implements OnInit { | ||
21 | user: User = null; | ||
13 | 22 | ||
14 | export class AccountComponent extends FormReactive implements OnInit { | 23 | constructor(private authService: AuthService) {} |
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 | 24 | ||
45 | ngOnInit() { | 25 | ngOnInit() { |
46 | this.buildForm(); | 26 | this.user = this.authService.getUser(); |
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 | } | 27 | } |
66 | } | 28 | } |