@@ -0,0 +1,50 @@
|
||||
<h1 mat-dialog-title>Change Password</h1>
|
||||
|
||||
<div mat-dialog-content>
|
||||
|
||||
<form [formGroup]="changePasswordForm">
|
||||
|
||||
<div fxLayout="column">
|
||||
|
||||
<mat-form-field>
|
||||
<mat-label>Password</mat-label>
|
||||
<input matInput formControlName="password" type="password">
|
||||
<mat-error *ngIf="changePasswordForm.controls.password.hasError('required')">
|
||||
Password <strong>is required</strong>
|
||||
</mat-error>
|
||||
<mat-error *ngIf="changePasswordForm.controls.password.hasError('minlength')">
|
||||
Password should be at least <strong>8 characters long</strong>
|
||||
</mat-error>
|
||||
<mat-error *ngIf="changePasswordForm.controls.password.hasError('maxlength')">
|
||||
Password should not be more than <strong>50 characters long</strong>
|
||||
</mat-error>
|
||||
<mat-error *ngIf="changePasswordForm.controls.password.hasError('pattern')">
|
||||
Password should include a <strong>numeral</strong> and at <strong>least one uppercase</strong> ,<strong>lowercase and special character</strong>
|
||||
</mat-error>
|
||||
</mat-form-field>
|
||||
|
||||
</div>
|
||||
|
||||
<div fxLayout="column">
|
||||
|
||||
<mat-form-field>
|
||||
<mat-label>Repeat Password</mat-label>
|
||||
<input matInput formControlName="repeatPassword" type="password">
|
||||
<mat-error *ngIf="changePasswordForm.controls.repeatPassword.hasError('required')">
|
||||
Password <strong>required</strong>
|
||||
</mat-error>
|
||||
<mat-error *ngIf="changePasswordForm.controls.repeatPassword.hasError('notequal')">
|
||||
Password <strong>does not match</strong>
|
||||
</mat-error>
|
||||
</mat-form-field>
|
||||
|
||||
</div>
|
||||
|
||||
</form>
|
||||
|
||||
</div>
|
||||
|
||||
<mat-dialog-actions align="center">
|
||||
<button mat-raised-button mat-dialog-close>Cancel</button>
|
||||
<button mat-raised-button color="warn" [disabled]="!changePasswordForm.valid" [mat-dialog-close]="{password:changePasswordForm.get('password').value,repeatPassword:changePasswordForm.get('repeatPassword').value}">Confirm</button>
|
||||
</mat-dialog-actions>
|
||||
@@ -0,0 +1,25 @@
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { ChangePasswordDialogComponent } from './change-password-dialog.component';
|
||||
|
||||
describe('ChangePasswordDialogComponent', () => {
|
||||
let component: ChangePasswordDialogComponent;
|
||||
let fixture: ComponentFixture<ChangePasswordDialogComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [ ChangePasswordDialogComponent ]
|
||||
})
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(ChangePasswordDialogComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -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;
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import { FileUploadComponent } from './file-upload/file-upload.component';
|
||||
import { FooterComponent } from './footer/footer.component';
|
||||
import { LanguageSelectorComponent } from './language-selector/language-selector.component';
|
||||
import { ThemePickerComponent } from './theme-picker/theme-picker.component';
|
||||
import { ChangePasswordDialogComponent } from './change-password-dialog/change-password-dialog.component';
|
||||
|
||||
/** Custom Modules */
|
||||
import { IconsModule } from './icons.module';
|
||||
@@ -36,6 +37,7 @@ import { MaterialModule } from './material.module';
|
||||
FooterComponent,
|
||||
LanguageSelectorComponent,
|
||||
ThemePickerComponent,
|
||||
ChangePasswordDialogComponent
|
||||
],
|
||||
exports: [
|
||||
FileUploadComponent,
|
||||
@@ -50,7 +52,8 @@ import { MaterialModule } from './material.module';
|
||||
],
|
||||
entryComponents: [
|
||||
FormDialogComponent,
|
||||
DeleteDialogComponent
|
||||
DeleteDialogComponent,
|
||||
ChangePasswordDialogComponent
|
||||
]
|
||||
})
|
||||
export class SharedModule { }
|
||||
|
||||
Reference in New Issue
Block a user