Browse Source

feat(identity): implement dynamic password validation to users page

#2039
pull/2041/head
mehmet-erim 7 years ago
parent
commit
7d026e5e91
  1. 44
      npm/ng-packs/packages/identity/src/lib/components/users/users.component.ts

44
npm/ng-packs/packages/identity/src/lib/components/users/users.component.ts

@ -1,4 +1,4 @@
import { ABP } from '@abp/ng.core';
import { ABP, ConfigState } from '@abp/ng.core';
import { ConfirmationService, Toaster } from '@abp/ng.theme.shared';
import { Component, TemplateRef, TrackByFunction, ViewChild, OnInit } from '@angular/core';
import { AbstractControl, FormArray, FormBuilder, FormGroup, Validators, FormControl } from '@angular/forms';
@ -17,6 +17,7 @@ import {
} from '../../actions/identity.actions';
import { Identity } from '../../models/identity';
import { IdentityState } from '../../states/identity.state';
import { PasswordRules, validatePassword } from '@ngx-validate/core';
@Component({
selector: 'abp-users',
templateUrl: './users.component.html',
@ -55,6 +56,10 @@ export class UsersComponent implements OnInit {
sortKey = '';
passwordRulesArr = [] as PasswordRules;
requiredPasswordLength = 1;
trackByFn: TrackByFunction<AbstractControl> = (index, item) => Object.keys(item)[0] || index;
get roleGroups(): FormGroup[] {
@ -65,6 +70,30 @@ export class UsersComponent implements OnInit {
ngOnInit() {
this.get();
const passwordRules: ABP.Dictionary<string> = this.store.selectSnapshot(
ConfigState.getSettings('Identity.Password'),
);
if ((passwordRules['Abp.Identity.Password.RequireDigit'] || '').toLowerCase() === 'true') {
this.passwordRulesArr.push('number');
}
if ((passwordRules['Abp.Identity.Password.RequireLowercase'] || '').toLowerCase() === 'true') {
this.passwordRulesArr.push('small');
}
if ((passwordRules['Abp.Identity.Password.RequireUppercase'] || '').toLowerCase() === 'true') {
this.passwordRulesArr.push('capital');
}
if (+(passwordRules['Abp.Identity.Password.RequiredUniqueChars'] || 0) > 0) {
this.passwordRulesArr.push('special');
}
if (Number.isInteger(+passwordRules['Abp.Identity.Password.RequiredLength'])) {
this.requiredPasswordLength = +passwordRules['Abp.Identity.Password.RequiredLength'];
}
}
onSearch(value) {
@ -92,10 +121,17 @@ export class UsersComponent implements OnInit {
),
});
const passwordValidators = [
validatePassword(this.passwordRulesArr),
Validators.minLength(this.requiredPasswordLength),
Validators.maxLength(32),
];
this.form.addControl('password', new FormControl('', [...passwordValidators]));
if (!this.selected.userName) {
this.form.addControl('password', new FormControl('', [Validators.required, Validators.maxLength(32)]));
} else {
this.form.addControl('password', new FormControl('', [Validators.maxLength(32)]));
this.form.get('password').setValidators([...passwordValidators, Validators.required]);
this.form.get('password').updateValueAndValidity();
}
});
}

Loading…
Cancel
Save