<input
type="password" id="new-password" i18n-placeholder placeholder="New password"
formControlName="new-password" [ngClass]="{ 'input-error': formErrors['new-password'] }"
- (change)="validateNewPassword()" (blur)="printAnError()"
>
<div *ngIf="formErrors['new-password']" class="form-error">
{{ formErrors['new-password'] }}
<input
type="password" id="new-confirmed-password" i18n-placeholder placeholder="Confirm new password"
- formControlName="new-confirmed-password" (change)="validateNewPassword()" (blur)="printAnError()"
+ formControlName="new-confirmed-password"
>
+ <div *ngIf="formErrors['new-confirmed-password']" class="form-error">
+ {{ formErrors['new-confirmed-password'] }}
+ </div>
- <input type="submit" i18n-value value="Change password" [disabled]="!form.valid || unsendable">
+ <input type="submit" i18n-value value="Change password" [disabled]="!form.valid">
</form>
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',
})
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,
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
)
) {}
ngOnInit () {
- console.log(this.router.url)
this.updateLibraryLabel(this.router.url)
this.router.events
}
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) {
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
}
}
+ 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: {