From b0ee41df7d6de2f77d30e7bb47c245c0b33019d4 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 5 Sep 2018 14:59:15 +0200 Subject: [PATCH] Clean up change password validation --- .../my-account-change-password.component.html | 8 +++-- .../my-account-change-password.component.ts | 35 ++++++------------- .../app/+my-account/my-account.component.ts | 5 +-- .../user-validators.service.ts | 8 +++++ 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 @@
{{ formErrors['new-password'] }} @@ -14,8 +13,11 @@ +
+ {{ formErrors['new-confirmed-password'] }} +
- + 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' import { I18n } from '@ngx-translate/i18n-polyfill' import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service' import { UserValidatorsService } from '@app/shared/forms/form-validators/user-validators.service' +import { filter } from 'rxjs/operators' @Component({ selector: 'my-account-change-password', @@ -12,7 +13,6 @@ import { UserValidatorsService } from '@app/shared/forms/form-validators/user-va }) export class MyAccountChangePasswordComponent extends FormReactive implements OnInit { error: string = null - unsendable = true // default to true to not have to not the if in change password constructor ( protected formValidatorService: FormValidatorService, @@ -27,36 +27,23 @@ export class MyAccountChangePasswordComponent extends FormReactive implements On ngOnInit () { this.buildForm({ 'new-password': this.userValidatorsService.USER_PASSWORD, - 'new-confirmed-password': this.userValidatorsService.USER_PASSWORD + 'new-confirmed-password': this.userValidatorsService.USER_CONFIRM_PASSWORD }) - } - validateNewPassword () { - if (this.form.value['new-password'] && this.form.value['new-confirmed-password']) { - if (this.form.value['new-password'] === this.form.value['new-confirmed-password']) { - this.error = null - this.unsendable = false - return - } - } - this.unsendable = true - } + const confirmPasswordControl = this.form.get('new-confirmed-password') - printAnError () { - console.log(this.unsendable) - this.validateNewPassword() - if (this.unsendable) { - this.error = this.i18n('The new password and the confirmed password do not correspond.') - } + confirmPasswordControl.valueChanges + .pipe(filter(v => v !== this.form.value[ 'new-password' ])) + .subscribe(() => confirmPasswordControl.setErrors({ matchPassword: true })) } changePassword () { - if (this.unsendable) { - return - } + this.userService.changePassword(this.form.value[ 'new-password' ]).subscribe( + () => { + this.notificationsService.success(this.i18n('Success'), this.i18n('Password updated.')) - this.userService.changePassword(this.form.value['new-password']).subscribe( - () => this.notificationsService.success(this.i18n('Success'), this.i18n('Password updated.')), + this.form.reset() + }, err => this.error = err.message ) 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 { ) {} ngOnInit () { - console.log(this.router.url) this.updateLibraryLabel(this.router.url) this.router.events @@ -29,7 +28,9 @@ export class MyAccountComponent implements OnInit { } isVideoImportEnabled () { - return this.serverService.getConfig().import.videos.http.enabled + const importConfig = this.serverService.getConfig().import.videos + + return importConfig.http.enabled || importConfig.torrent.enabled } 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 { readonly USER_USERNAME: BuildFormValidator readonly USER_EMAIL: BuildFormValidator readonly USER_PASSWORD: BuildFormValidator + readonly USER_CONFIRM_PASSWORD: BuildFormValidator readonly USER_VIDEO_QUOTA: BuildFormValidator readonly USER_VIDEO_QUOTA_DAILY: BuildFormValidator readonly USER_ROLE: BuildFormValidator @@ -55,6 +56,13 @@ export class UserValidatorsService { } } + this.USER_CONFIRM_PASSWORD = { + VALIDATORS: [], + MESSAGES: { + 'matchPassword': this.i18n('The new password and the confirmed password do not correspond.') + } + } + this.USER_VIDEO_QUOTA = { VALIDATORS: [ Validators.required, Validators.min(-1) ], MESSAGES: { -- 2.25.1