diff options
author | Chocobozzz <me@florianbigard.com> | 2018-09-26 16:28:15 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-09-26 16:28:27 +0200 |
commit | a890d1e0d30851741392e6e7f14acffe685d28e0 (patch) | |
tree | 40f6d0c4643f795670943e176d60b2e85a0fb6e0 /client/src | |
parent | be1206bb934c223893a652be5f1f6c911c9c66be (diff) | |
download | PeerTube-a890d1e0d30851741392e6e7f14acffe685d28e0.tar.gz PeerTube-a890d1e0d30851741392e6e7f14acffe685d28e0.tar.zst PeerTube-a890d1e0d30851741392e6e7f14acffe685d28e0.zip |
Check current password on server side
Diffstat (limited to 'client/src')
3 files changed, 21 insertions, 25 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 00b6d20fa..ae797d1bc 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,14 +1,14 @@ | |||
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)="checkPassword()" [formGroup]="form"> | 3 | <form role="form" (ngSubmit)="changePassword()" [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" | 7 | type="password" id="current-password" i18n-placeholder placeholder="Current password" |
8 | formControlName="old-password" [ngClass]="{ 'input-error': formErrors['old-password'] }" | 8 | formControlName="current-password" [ngClass]="{ 'input-error': formErrors['current-password'] }" |
9 | > | 9 | > |
10 | <div *ngIf="formErrors['old-password']" class="form-error"> | 10 | <div *ngIf="formErrors['current-password']" class="form-error"> |
11 | {{ formErrors['old-password'] }} | 11 | {{ formErrors['current-password'] }} |
12 | </div> | 12 | </div> |
13 | 13 | ||
14 | <input | 14 | <input |
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 da0021df9..e5343b33d 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 | |||
@@ -30,7 +30,7 @@ export class MyAccountChangePasswordComponent extends FormReactive implements On | |||
30 | 30 | ||
31 | ngOnInit () { | 31 | ngOnInit () { |
32 | this.buildForm({ | 32 | this.buildForm({ |
33 | 'old-password': this.userValidatorsService.USER_PASSWORD, | 33 | 'current-password': this.userValidatorsService.USER_PASSWORD, |
34 | 'new-password': this.userValidatorsService.USER_PASSWORD, | 34 | 'new-password': this.userValidatorsService.USER_PASSWORD, |
35 | 'new-confirmed-password': this.userValidatorsService.USER_CONFIRM_PASSWORD | 35 | 'new-confirmed-password': this.userValidatorsService.USER_CONFIRM_PASSWORD |
36 | }) | 36 | }) |
@@ -44,31 +44,26 @@ export class MyAccountChangePasswordComponent extends FormReactive implements On | |||
44 | .subscribe(() => confirmPasswordControl.setErrors({ matchPassword: true })) | 44 | .subscribe(() => confirmPasswordControl.setErrors({ matchPassword: true })) |
45 | } | 45 | } |
46 | 46 | ||
47 | checkPassword () { | 47 | changePassword () { |
48 | this.error = null | 48 | const currentPassword = this.form.value[ 'current-password' ] |
49 | const oldPassword = this.form.value[ 'old-password' ] | 49 | const newPassword = this.form.value[ 'new-password' ] |
50 | 50 | ||
51 | // compare old password | 51 | this.userService.changePassword(currentPassword, newPassword).subscribe( |
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 () { | ||
64 | this.userService.changePassword(this.form.value[ 'new-password' ]).subscribe( | ||
65 | () => { | 52 | () => { |
66 | this.notificationsService.success(this.i18n('Success'), this.i18n('Password updated.')) | 53 | this.notificationsService.success(this.i18n('Success'), this.i18n('Password updated.')) |
67 | 54 | ||
68 | this.form.reset() | 55 | this.form.reset() |
56 | this.error = null | ||
69 | }, | 57 | }, |
70 | 58 | ||
71 | err => this.error = err.message | 59 | err => { |
60 | if (err.status === 401) { | ||
61 | this.error = this.i18n('You current password is invalid.') | ||
62 | return | ||
63 | } | ||
64 | |||
65 | this.error = err.message | ||
66 | } | ||
72 | ) | 67 | ) |
73 | } | 68 | } |
74 | } | 69 | } |
diff --git a/client/src/app/shared/users/user.service.ts b/client/src/app/shared/users/user.service.ts index fad5b0980..bd5cd45d4 100644 --- a/client/src/app/shared/users/user.service.ts +++ b/client/src/app/shared/users/user.service.ts | |||
@@ -17,9 +17,10 @@ export class UserService { | |||
17 | ) { | 17 | ) { |
18 | } | 18 | } |
19 | 19 | ||
20 | changePassword (newPassword: string) { | 20 | changePassword (currentPassword: string, newPassword: string) { |
21 | const url = UserService.BASE_USERS_URL + 'me' | 21 | const url = UserService.BASE_USERS_URL + 'me' |
22 | const body: UserUpdateMe = { | 22 | const body: UserUpdateMe = { |
23 | currentPassword, | ||
23 | password: newPassword | 24 | password: newPassword |
24 | } | 25 | } |
25 | 26 | ||