Browse Source

feat(account): implement dynamic password validation to register page

#2039
pull/2041/head
mehmet-erim 7 years ago
parent
commit
60ed67d004
  1. 37
      npm/ng-packs/packages/account/src/lib/components/register/register.component.ts

37
npm/ng-packs/packages/account/src/lib/components/register/register.component.ts

@ -1,6 +1,6 @@
import { ConfigState, GetAppConfiguration } from '@abp/ng.core';
import { ConfigState, GetAppConfiguration, ABP } from '@abp/ng.core';
import { ToasterService } from '@abp/ng.theme.shared';
import { Component } from '@angular/core';
import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { Navigate } from '@ngxs/router-plugin';
import { Store } from '@ngxs/store';
@ -10,13 +10,14 @@ import { catchError, finalize, switchMap, take, tap } from 'rxjs/operators';
import snq from 'snq';
import { RegisterRequest } from '../../models';
import { AccountService } from '../../services/account.service';
import { PasswordRules, validatePassword } from '@ngx-validate/core';
const { maxLength, minLength, required, email } = Validators;
@Component({
selector: 'abp-register',
templateUrl: './register.component.html',
})
export class RegisterComponent {
export class RegisterComponent implements OnInit {
form: FormGroup;
inProgress: boolean;
@ -30,10 +31,38 @@ export class RegisterComponent {
) {
this.oauthService.configure(this.store.selectSnapshot(ConfigState.getOne('environment')).oAuthConfig);
this.oauthService.loadDiscoveryDocument();
}
ngOnInit() {
const passwordRules: ABP.Dictionary<string> = this.store.selectSnapshot(
ConfigState.getSettings('Identity.Password'),
);
const passwordRulesArr = [] as PasswordRules;
let requiredLength = 1;
if ((passwordRules['Abp.Identity.Password.RequireDigit'] || '').toLowerCase() === 'true') {
passwordRulesArr.push('number');
}
if ((passwordRules['Abp.Identity.Password.RequireLowercase'] || '').toLowerCase() === 'true') {
passwordRulesArr.push('small');
}
if ((passwordRules['Abp.Identity.Password.RequireUppercase'] || '').toLowerCase() === 'true') {
passwordRulesArr.push('capital');
}
if (+(passwordRules['Abp.Identity.Password.RequiredUniqueChars'] || 0) > 0) {
passwordRulesArr.push('special');
}
if (Number.isInteger(+passwordRules['Abp.Identity.Password.RequiredLength'])) {
requiredLength = +passwordRules['Abp.Identity.Password.RequiredLength'];
}
this.form = this.fb.group({
username: ['', [required, maxLength(255)]],
password: ['', [required, maxLength(32)]],
password: ['', [required, validatePassword(passwordRulesArr), minLength(requiredLength), maxLength(32)]],
email: ['', [required, email]],
});
}

Loading…
Cancel
Save