aboutsummaryrefslogtreecommitdiffhomepage
path: root/client
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-09-05 14:59:15 +0200
committerChocobozzz <me@florianbigard.com>2018-09-05 15:00:25 +0200
commitb0ee41df7d6de2f77d30e7bb47c245c0b33019d4 (patch)
treeeafdc2bc0a8facd7a3b779d3998eb696f0177473 /client
parent4c8e4e04d1b3f0f207e9155df393ceeb23dc2172 (diff)
downloadPeerTube-b0ee41df7d6de2f77d30e7bb47c245c0b33019d4.tar.gz
PeerTube-b0ee41df7d6de2f77d30e7bb47c245c0b33019d4.tar.zst
PeerTube-b0ee41df7d6de2f77d30e7bb47c245c0b33019d4.zip
Clean up change password validation
Diffstat (limited to 'client')
-rw-r--r--client/src/app/+my-account/my-account-settings/my-account-change-password/my-account-change-password.component.html8
-rw-r--r--client/src/app/+my-account/my-account-settings/my-account-change-password/my-account-change-password.component.ts35
-rw-r--r--client/src/app/+my-account/my-account.component.ts5
-rw-r--r--client/src/app/shared/forms/form-validators/user-validators.service.ts8
4 files changed, 27 insertions, 29 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 913b570cb..ab6df52be 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
@@ -6,7 +6,6 @@
6 <input 6 <input
7 type="password" id="new-password" i18n-placeholder placeholder="New password" 7 type="password" id="new-password" i18n-placeholder placeholder="New password"
8 formControlName="new-password" [ngClass]="{ 'input-error': formErrors['new-password'] }" 8 formControlName="new-password" [ngClass]="{ 'input-error': formErrors['new-password'] }"
9 (change)="validateNewPassword()" (blur)="printAnError()"
10 > 9 >
11 <div *ngIf="formErrors['new-password']" class="form-error"> 10 <div *ngIf="formErrors['new-password']" class="form-error">
12 {{ formErrors['new-password'] }} 11 {{ formErrors['new-password'] }}
@@ -14,8 +13,11 @@
14 13
15 <input 14 <input
16 type="password" id="new-confirmed-password" i18n-placeholder placeholder="Confirm new password" 15 type="password" id="new-confirmed-password" i18n-placeholder placeholder="Confirm new password"
17 formControlName="new-confirmed-password" (change)="validateNewPassword()" (blur)="printAnError()" 16 formControlName="new-confirmed-password"
18 > 17 >
18 <div *ngIf="formErrors['new-confirmed-password']" class="form-error">
19 {{ formErrors['new-confirmed-password'] }}
20 </div>
19 21
20 <input type="submit" i18n-value value="Change password" [disabled]="!form.valid || unsendable"> 22 <input type="submit" i18n-value value="Change password" [disabled]="!form.valid">
21</form> 23</form>
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 0707d8f9a..57a706b0f 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
@@ -4,6 +4,7 @@ import { FormReactive, UserService } from '../../../shared'
4import { I18n } from '@ngx-translate/i18n-polyfill' 4import { 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'
7 8
8@Component({ 9@Component({
9 selector: 'my-account-change-password', 10 selector: 'my-account-change-password',
@@ -12,7 +13,6 @@ import { UserValidatorsService } from '@app/shared/forms/form-validators/user-va
12}) 13})
13export class MyAccountChangePasswordComponent extends FormReactive implements OnInit { 14export class MyAccountChangePasswordComponent extends FormReactive implements OnInit {
14 error: string = null 15 error: string = null
15 unsendable = true // default to true to not have to not the if in change password
16 16
17 constructor ( 17 constructor (
18 protected formValidatorService: FormValidatorService, 18 protected formValidatorService: FormValidatorService,
@@ -27,36 +27,23 @@ export class MyAccountChangePasswordComponent extends FormReactive implements On
27 ngOnInit () { 27 ngOnInit () {
28 this.buildForm({ 28 this.buildForm({
29 'new-password': this.userValidatorsService.USER_PASSWORD, 29 'new-password': this.userValidatorsService.USER_PASSWORD,
30 'new-confirmed-password': this.userValidatorsService.USER_PASSWORD 30 'new-confirmed-password': this.userValidatorsService.USER_CONFIRM_PASSWORD
31 }) 31 })
32 }
33 32
34 validateNewPassword () { 33 const confirmPasswordControl = this.form.get('new-confirmed-password')
35 if (this.form.value['new-password'] && this.form.value['new-confirmed-password']) {
36 if (this.form.value['new-password'] === this.form.value['new-confirmed-password']) {
37 this.error = null
38 this.unsendable = false
39 return
40 }
41 }
42 this.unsendable = true
43 }
44 34
45 printAnError () { 35 confirmPasswordControl.valueChanges
46 console.log(this.unsendable) 36 .pipe(filter(v => v !== this.form.value[ 'new-password' ]))
47 this.validateNewPassword() 37 .subscribe(() => confirmPasswordControl.setErrors({ matchPassword: true }))
48 if (this.unsendable) {
49 this.error = this.i18n('The new password and the confirmed password do not correspond.')
50 }
51 } 38 }
52 39
53 changePassword () { 40 changePassword () {
54 if (this.unsendable) { 41 this.userService.changePassword(this.form.value[ 'new-password' ]).subscribe(
55 return 42 () => {
56 } 43 this.notificationsService.success(this.i18n('Success'), this.i18n('Password updated.'))
57 44
58 this.userService.changePassword(this.form.value['new-password']).subscribe( 45 this.form.reset()
59 () => this.notificationsService.success(this.i18n('Success'), this.i18n('Password updated.')), 46 },
60 47
61 err => this.error = err.message 48 err => this.error = err.message
62 ) 49 )
diff --git a/client/src/app/+my-account/my-account.component.ts b/client/src/app/+my-account/my-account.component.ts
index 548f6a1c0..7100638c8 100644
--- a/client/src/app/+my-account/my-account.component.ts
+++ b/client/src/app/+my-account/my-account.component.ts
@@ -20,7 +20,6 @@ export class MyAccountComponent implements OnInit {
20 ) {} 20 ) {}
21 21
22 ngOnInit () { 22 ngOnInit () {
23 console.log(this.router.url)
24 this.updateLibraryLabel(this.router.url) 23 this.updateLibraryLabel(this.router.url)
25 24
26 this.router.events 25 this.router.events
@@ -29,7 +28,9 @@ export class MyAccountComponent implements OnInit {
29 } 28 }
30 29
31 isVideoImportEnabled () { 30 isVideoImportEnabled () {
32 return this.serverService.getConfig().import.videos.http.enabled 31 const importConfig = this.serverService.getConfig().import.videos
32
33 return importConfig.http.enabled || importConfig.torrent.enabled
33 } 34 }
34 35
35 private updateLibraryLabel (url: string) { 36 private updateLibraryLabel (url: string) {
diff --git a/client/src/app/shared/forms/form-validators/user-validators.service.ts b/client/src/app/shared/forms/form-validators/user-validators.service.ts
index 424553d74..1fd1cdf68 100644
--- a/client/src/app/shared/forms/form-validators/user-validators.service.ts
+++ b/client/src/app/shared/forms/form-validators/user-validators.service.ts
@@ -8,6 +8,7 @@ export class UserValidatorsService {
8 readonly USER_USERNAME: BuildFormValidator 8 readonly USER_USERNAME: BuildFormValidator
9 readonly USER_EMAIL: BuildFormValidator 9 readonly USER_EMAIL: BuildFormValidator
10 readonly USER_PASSWORD: BuildFormValidator 10 readonly USER_PASSWORD: BuildFormValidator
11 readonly USER_CONFIRM_PASSWORD: BuildFormValidator
11 readonly USER_VIDEO_QUOTA: BuildFormValidator 12 readonly USER_VIDEO_QUOTA: BuildFormValidator
12 readonly USER_VIDEO_QUOTA_DAILY: BuildFormValidator 13 readonly USER_VIDEO_QUOTA_DAILY: BuildFormValidator
13 readonly USER_ROLE: BuildFormValidator 14 readonly USER_ROLE: BuildFormValidator
@@ -55,6 +56,13 @@ export class UserValidatorsService {
55 } 56 }
56 } 57 }
57 58
59 this.USER_CONFIRM_PASSWORD = {
60 VALIDATORS: [],
61 MESSAGES: {
62 'matchPassword': this.i18n('The new password and the confirmed password do not correspond.')
63 }
64 }
65
58 this.USER_VIDEO_QUOTA = { 66 this.USER_VIDEO_QUOTA = {
59 VALIDATORS: [ Validators.required, Validators.min(-1) ], 67 VALIDATORS: [ Validators.required, Validators.min(-1) ],
60 MESSAGES: { 68 MESSAGES: {