aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/+my-account
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/+my-account')
-rw-r--r--client/src/app/+my-account/my-account-settings/my-account-change-password/my-account-change-password.component.html10
-rw-r--r--client/src/app/+my-account/my-account-settings/my-account-change-password/my-account-change-password.component.scss3
-rw-r--r--client/src/app/+my-account/my-account-settings/my-account-change-password/my-account-change-password.component.ts25
3 files changed, 35 insertions, 3 deletions
diff --git a/client/src/app/+my-account/my-account-settings/my-account-change-password/my-account-change-password.component.html b/client/src/app/+my-account/my-account-settings/my-account-change-password/my-account-change-password.component.html
index ab6df52be..00b6d20fa 100644
--- a/client/src/app/+my-account/my-account-settings/my-account-change-password/my-account-change-password.component.html
+++ b/client/src/app/+my-account/my-account-settings/my-account-change-password/my-account-change-password.component.html
@@ -1,9 +1,17 @@
1<div *ngIf="error" class="alert alert-danger">{{ error }}</div> 1<div *ngIf="error" class="alert alert-danger">{{ error }}</div>
2 2
3<form role="form" (ngSubmit)="changePassword()" [formGroup]="form"> 3<form role="form" (ngSubmit)="checkPassword()" [formGroup]="form">
4 4
5 <label i18n for="new-password">Change password</label> 5 <label i18n for="new-password">Change password</label>
6 <input 6 <input
7 type="password" id="old-password" i18n-placeholder placeholder="Old password"
8 formControlName="old-password" [ngClass]="{ 'input-error': formErrors['old-password'] }"
9 >
10 <div *ngIf="formErrors['old-password']" class="form-error">
11 {{ formErrors['old-password'] }}
12 </div>
13
14 <input
7 type="password" id="new-password" i18n-placeholder placeholder="New password" 15 type="password" id="new-password" i18n-placeholder placeholder="New password"
8 formControlName="new-password" [ngClass]="{ 'input-error': formErrors['new-password'] }" 16 formControlName="new-password" [ngClass]="{ 'input-error': formErrors['new-password'] }"
9 > 17 >
diff --git a/client/src/app/+my-account/my-account-settings/my-account-change-password/my-account-change-password.component.scss b/client/src/app/+my-account/my-account-settings/my-account-change-password/my-account-change-password.component.scss
index f8279ffd3..e641482f0 100644
--- a/client/src/app/+my-account/my-account-settings/my-account-change-password/my-account-change-password.component.scss
+++ b/client/src/app/+my-account/my-account-settings/my-account-change-password/my-account-change-password.component.scss
@@ -5,7 +5,8 @@ input[type=password] {
5 @include peertube-input-text(340px); 5 @include peertube-input-text(340px);
6 display: block; 6 display: block;
7 7
8 &#new-confirmed-password { 8 &#new-password,
9 &#new-confirmed-password {
9 margin-top: 15px; 10 margin-top: 15px;
10 } 11 }
11} 12}
diff --git a/client/src/app/+my-account/my-account-settings/my-account-change-password/my-account-change-password.component.ts b/client/src/app/+my-account/my-account-settings/my-account-change-password/my-account-change-password.component.ts
index 57a706b0f..c4837460a 100644
--- a/client/src/app/+my-account/my-account-settings/my-account-change-password/my-account-change-password.component.ts
+++ b/client/src/app/+my-account/my-account-settings/my-account-change-password/my-account-change-password.component.ts
@@ -5,6 +5,8 @@ import { I18n } from '@ngx-translate/i18n-polyfill'
5import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service' 5import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
6import { UserValidatorsService } from '@app/shared/forms/form-validators/user-validators.service' 6import { UserValidatorsService } from '@app/shared/forms/form-validators/user-validators.service'
7import { filter } from 'rxjs/operators' 7import { filter } from 'rxjs/operators'
8import { AuthService } from '@app/core';
9import { User } from '../../../../../../shared';
8 10
9@Component({ 11@Component({
10 selector: 'my-account-change-password', 12 selector: 'my-account-change-password',
@@ -13,11 +15,13 @@ import { filter } from 'rxjs/operators'
13}) 15})
14export class MyAccountChangePasswordComponent extends FormReactive implements OnInit { 16export class MyAccountChangePasswordComponent extends FormReactive implements OnInit {
15 error: string = null 17 error: string = null
18 user: User = null
16 19
17 constructor ( 20 constructor (
18 protected formValidatorService: FormValidatorService, 21 protected formValidatorService: FormValidatorService,
19 private userValidatorsService: UserValidatorsService, 22 private userValidatorsService: UserValidatorsService,
20 private notificationsService: NotificationsService, 23 private notificationsService: NotificationsService,
24 private authService: AuthService,
21 private userService: UserService, 25 private userService: UserService,
22 private i18n: I18n 26 private i18n: I18n
23 ) { 27 ) {
@@ -26,10 +30,13 @@ export class MyAccountChangePasswordComponent extends FormReactive implements On
26 30
27 ngOnInit () { 31 ngOnInit () {
28 this.buildForm({ 32 this.buildForm({
33 'old-password': this.userValidatorsService.USER_PASSWORD,
29 'new-password': this.userValidatorsService.USER_PASSWORD, 34 'new-password': this.userValidatorsService.USER_PASSWORD,
30 'new-confirmed-password': this.userValidatorsService.USER_CONFIRM_PASSWORD 35 'new-confirmed-password': this.userValidatorsService.USER_CONFIRM_PASSWORD
31 }) 36 })
32 37
38 this.user = this.authService.getUser()
39
33 const confirmPasswordControl = this.form.get('new-confirmed-password') 40 const confirmPasswordControl = this.form.get('new-confirmed-password')
34 41
35 confirmPasswordControl.valueChanges 42 confirmPasswordControl.valueChanges
@@ -37,7 +44,23 @@ export class MyAccountChangePasswordComponent extends FormReactive implements On
37 .subscribe(() => confirmPasswordControl.setErrors({ matchPassword: true })) 44 .subscribe(() => confirmPasswordControl.setErrors({ matchPassword: true }))
38 } 45 }
39 46
40 changePassword () { 47 checkPassword () {
48 this.error = null
49 const oldPassword = this.form.value[ 'old-password' ];
50
51 // compare old password
52 this.authService.login(this.user.account.name, oldPassword)
53 .subscribe(
54 () => this.changePassword(),
55 err => {
56 if (err.message.indexOf('credentials are invalid') !== -1) this.error = this.i18n('Incorrect old password.')
57 else this.error = err.message
58 }
59 )
60
61 }
62
63 private changePassword(){
41 this.userService.changePassword(this.form.value[ 'new-password' ]).subscribe( 64 this.userService.changePassword(this.form.value[ 'new-password' ]).subscribe(
42 () => { 65 () => {
43 this.notificationsService.success(this.i18n('Success'), this.i18n('Password updated.')) 66 this.notificationsService.success(this.i18n('Success'), this.i18n('Password updated.'))