feat: add user change password component (#660)

Fixes: #657
This commit is contained in:
Benura Abeywardena
2020-05-16 13:01:27 +05:30
committed by GitHub
parent 0c2af151f3
commit eb56bdc0ad
8 changed files with 172 additions and 2 deletions
@@ -0,0 +1,60 @@
/** Angular Imports */
import { Component, OnInit, Inject } from '@angular/core';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material';
import { FormBuilder, Validators, ValidatorFn, AbstractControl, ValidationErrors } from '@angular/forms';
import { Subscription } from 'rxjs';
/**
* Change Password Dialog component.
*/
@Component({
selector: 'mifosx-change-password-dialog',
templateUrl: './change-password-dialog.component.html',
styleUrls: ['./change-password-dialog.component.scss']
})
export class ChangePasswordDialogComponent implements OnInit {
/** Change Password Form */
changePasswordForm: any;
/**
* @param {MatDialogRef} dialogRef Component reference to dialog.
* @param {any} data Provides any data.
*/
constructor(public dialogRef: MatDialogRef<ChangePasswordDialogComponent>,
@Inject(MAT_DIALOG_DATA) public data: any,
private formBuilder: FormBuilder) { }
ngOnInit() {
this.createChangePasswordForm();
}
/** Change Password form */
createChangePasswordForm() {
this.changePasswordForm = this.formBuilder.group({
'password': ['', [Validators.required, Validators.pattern('^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*[$@$!%*?&])[A-Za-z\d$@$!%*?&].{8,}$'), Validators.maxLength(50), Validators.minLength(8)]],
'repeatPassword': ['', [Validators.required, this.confirmPassword('password')]]
});
}
/**
* Confirm Change Password of Users
* @param controlNameToCompare Form Control Name to be compared.
*/
confirmPassword(controlNameToCompare: string): ValidatorFn {
return (c: AbstractControl): ValidationErrors|null => {
if (c.value == null || c.value.length === 0) {
return null;
}
const controlToCompare = c.root.get(controlNameToCompare);
if (controlToCompare) {
const subscription: Subscription = controlToCompare.valueChanges.subscribe(() => {
c.updateValueAndValidity();
subscription.unsubscribe();
});
}
return controlToCompare && controlToCompare.value !== c.value ? {'notequal': true} : null;
};
}
}