Skip to content
Snippets Groups Projects
Verified Commit 21e39a41 authored by Alex ORLUC's avatar Alex ORLUC
Browse files

FIX formgroup validators

parent bfa2ccbe
No related branches found
No related tags found
No related merge requests found
...@@ -97,14 +97,18 @@ export class PasswordModificationComponent implements OnInit { ...@@ -97,14 +97,18 @@ export class PasswordModificationComponent implements OnInit {
this.coreUrl = angularGlobals.coreUrl; this.coreUrl = angularGlobals.coreUrl;
this.http.get(this.coreUrl + 'rest/passwordRules') this.http.get(this.coreUrl + 'rest/passwordRules')
.subscribe((data: any) => { .subscribe((data: any) => {
let valArr : ValidatorFn[] = [];
let ruleTextArr: String[] = []; let ruleTextArr: String[] = [];
valArr.push(Validators.required);
data.rules.forEach((rule: any) => { data.rules.forEach((rule: any) => {
if (rule.label == 'minLength') { if (rule.label == 'minLength') {
this.passwordRules.minLength.enabled = rule.enabled; this.passwordRules.minLength.enabled = rule.enabled;
this.passwordRules.minLength.value = rule.value; this.passwordRules.minLength.value = rule.value;
this.firstFormGroup.controls["newPasswordCtrl"].setValidators([Validators.minLength(this.passwordRules.minLength.value)]) valArr.push(Validators.minLength(this.passwordRules.minLength.value));
if (rule.enabled) { if (rule.enabled) {
ruleTextArr.push(rule.value + ' ' + this.lang['password' + rule.label]); ruleTextArr.push(rule.value + ' ' + this.lang['password' + rule.label]);
} }
...@@ -113,6 +117,7 @@ export class PasswordModificationComponent implements OnInit { ...@@ -113,6 +117,7 @@ export class PasswordModificationComponent implements OnInit {
} else if (rule.label == 'complexityUpper') { } else if (rule.label == 'complexityUpper') {
this.passwordRules.complexityUpper.enabled = rule.enabled; this.passwordRules.complexityUpper.enabled = rule.enabled;
this.passwordRules.complexityUpper.value = rule.value; this.passwordRules.complexityUpper.value = rule.value;
valArr.push(this.regexValidator(new RegExp('[A-Z]'), { 'complexityUpper': '' }));
if (rule.enabled) { if (rule.enabled) {
ruleTextArr.push(this.lang['password' + rule.label]); ruleTextArr.push(this.lang['password' + rule.label]);
} }
...@@ -121,6 +126,7 @@ export class PasswordModificationComponent implements OnInit { ...@@ -121,6 +126,7 @@ export class PasswordModificationComponent implements OnInit {
} else if (rule.label == 'complexityNumber') { } else if (rule.label == 'complexityNumber') {
this.passwordRules.complexityNumber.enabled = rule.enabled; this.passwordRules.complexityNumber.enabled = rule.enabled;
this.passwordRules.complexityNumber.value = rule.value; this.passwordRules.complexityNumber.value = rule.value;
valArr.push(this.regexValidator(new RegExp('[0-9]'), { 'complexityNumber': '' }));
if (rule.enabled) { if (rule.enabled) {
ruleTextArr.push(this.lang['password' + rule.label]); ruleTextArr.push(this.lang['password' + rule.label]);
} }
...@@ -129,6 +135,7 @@ export class PasswordModificationComponent implements OnInit { ...@@ -129,6 +135,7 @@ export class PasswordModificationComponent implements OnInit {
} else if (rule.label == 'complexitySpecial') { } else if (rule.label == 'complexitySpecial') {
this.passwordRules.complexitySpecial.enabled = rule.enabled; this.passwordRules.complexitySpecial.enabled = rule.enabled;
this.passwordRules.complexitySpecial.value = rule.value; this.passwordRules.complexitySpecial.value = rule.value;
valArr.push(this.regexValidator(new RegExp('[^A-Za-z0-9]'), { 'complexitySpecial': '' }));
if (rule.enabled) { if (rule.enabled) {
ruleTextArr.push(this.lang['password' + rule.label]); ruleTextArr.push(this.lang['password' + rule.label]);
} }
...@@ -145,17 +152,16 @@ export class PasswordModificationComponent implements OnInit { ...@@ -145,17 +152,16 @@ export class PasswordModificationComponent implements OnInit {
ruleTextArr.push(this.lang['passwordhistoryLastUseDesc'] + ' ' + rule.value + ' ' + this.lang['passwordhistoryLastUseDesc2']); ruleTextArr.push(this.lang['passwordhistoryLastUseDesc'] + ' ' + rule.value + ' ' + this.lang['passwordhistoryLastUseDesc2']);
} }
} }
}); });
this.ruleText = ruleTextArr.join(', '); this.ruleText = ruleTextArr.join(', ');
this.firstFormGroup.controls["newPasswordCtrl"].setValidators(valArr);
}, (err) => { }, (err) => {
this.notify.error(err.error.errors); this.notify.error(err.error.errors);
}); });
this.firstFormGroup = this._formBuilder.group({ this.firstFormGroup = this._formBuilder.group({
newPasswordCtrl: [ newPasswordCtrl: [
'', ''
Validators.compose([Validators.minLength(1), this.regexValidator(new RegExp('[A-Z]'), { 'complexityUpper': '' }), this.regexValidator(new RegExp('[0-9]'), { 'complexityNumber': '' }), this.regexValidator(new RegExp('[^A-Za-z0-9]'), { 'complexitySpecial': '' })])
], ],
retypePasswordCtrl: [ retypePasswordCtrl: [
'', '',
...@@ -182,6 +188,7 @@ export class PasswordModificationComponent implements OnInit { ...@@ -182,6 +188,7 @@ export class PasswordModificationComponent implements OnInit {
} }
getErrorMessage() { getErrorMessage() {
console.log(this.firstFormGroup.controls['newPasswordCtrl'].errors);
if (this.firstFormGroup.controls['newPasswordCtrl'].hasError('required')) { if (this.firstFormGroup.controls['newPasswordCtrl'].hasError('required')) {
return this.lang.requiredField + ' !'; return this.lang.requiredField + ' !';
......
...@@ -745,12 +745,13 @@ export class ProfileComponent extends AutoCompletePlugin implements OnInit { ...@@ -745,12 +745,13 @@ export class ProfileComponent extends AutoCompletePlugin implements OnInit {
changePasswd() { changePasswd() {
this.http.get(this.coreUrl + 'rest/passwordRules') this.http.get(this.coreUrl + 'rest/passwordRules')
.subscribe((data: any) => { .subscribe((data: any) => {
let valArr : ValidatorFn[] = [];
let ruleTextArr: String[] = []; let ruleTextArr: String[] = [];
data.rules.forEach((rule: any) => { data.rules.forEach((rule: any) => {
if (rule.label == 'minLength') { if (rule.label == 'minLength') {
this.passwordRules.minLength.enabled = rule.enabled; this.passwordRules.minLength.enabled = rule.enabled;
this.passwordRules.minLength.value = rule.value; this.passwordRules.minLength.value = rule.value;
this.firstFormGroup.controls["newPasswordCtrl"].setValidators([Validators.minLength(this.passwordRules.minLength.value)]) valArr.push(Validators.minLength(this.passwordRules.minLength.value));
if (rule.enabled) { if (rule.enabled) {
ruleTextArr.push(rule.value + ' ' + this.lang['password' + rule.label]); ruleTextArr.push(rule.value + ' ' + this.lang['password' + rule.label]);
} }
...@@ -759,6 +760,7 @@ export class ProfileComponent extends AutoCompletePlugin implements OnInit { ...@@ -759,6 +760,7 @@ export class ProfileComponent extends AutoCompletePlugin implements OnInit {
} else if (rule.label == 'complexityUpper') { } else if (rule.label == 'complexityUpper') {
this.passwordRules.complexityUpper.enabled = rule.enabled; this.passwordRules.complexityUpper.enabled = rule.enabled;
this.passwordRules.complexityUpper.value = rule.value; this.passwordRules.complexityUpper.value = rule.value;
valArr.push(this.regexValidator(new RegExp('[A-Z]'), { 'complexityUpper': '' }));
if (rule.enabled) { if (rule.enabled) {
ruleTextArr.push(this.lang['password' + rule.label]); ruleTextArr.push(this.lang['password' + rule.label]);
} }
...@@ -767,6 +769,7 @@ export class ProfileComponent extends AutoCompletePlugin implements OnInit { ...@@ -767,6 +769,7 @@ export class ProfileComponent extends AutoCompletePlugin implements OnInit {
} else if (rule.label == 'complexityNumber') { } else if (rule.label == 'complexityNumber') {
this.passwordRules.complexityNumber.enabled = rule.enabled; this.passwordRules.complexityNumber.enabled = rule.enabled;
this.passwordRules.complexityNumber.value = rule.value; this.passwordRules.complexityNumber.value = rule.value;
valArr.push(this.regexValidator(new RegExp('[0-9]'), { 'complexityNumber': '' }));
if (rule.enabled) { if (rule.enabled) {
ruleTextArr.push(this.lang['password' + rule.label]); ruleTextArr.push(this.lang['password' + rule.label]);
} }
...@@ -775,6 +778,7 @@ export class ProfileComponent extends AutoCompletePlugin implements OnInit { ...@@ -775,6 +778,7 @@ export class ProfileComponent extends AutoCompletePlugin implements OnInit {
} else if (rule.label == 'complexitySpecial') { } else if (rule.label == 'complexitySpecial') {
this.passwordRules.complexitySpecial.enabled = rule.enabled; this.passwordRules.complexitySpecial.enabled = rule.enabled;
this.passwordRules.complexitySpecial.value = rule.value; this.passwordRules.complexitySpecial.value = rule.value;
valArr.push(this.regexValidator(new RegExp('[^A-Za-z0-9]'), { 'complexitySpecial': '' }));
if (rule.enabled) { if (rule.enabled) {
ruleTextArr.push(this.lang['password' + rule.label]); ruleTextArr.push(this.lang['password' + rule.label]);
} }
...@@ -794,14 +798,14 @@ export class ProfileComponent extends AutoCompletePlugin implements OnInit { ...@@ -794,14 +798,14 @@ export class ProfileComponent extends AutoCompletePlugin implements OnInit {
}); });
this.ruleText = ruleTextArr.join(', '); this.ruleText = ruleTextArr.join(', ');
this.firstFormGroup.controls["newPasswordCtrl"].setValidators(valArr);
}, (err) => { }, (err) => {
this.notify.error(err.error.errors); this.notify.error(err.error.errors);
}); });
this.firstFormGroup = this._formBuilder.group({ this.firstFormGroup = this._formBuilder.group({
newPasswordCtrl: [ newPasswordCtrl: [
'', ''
Validators.compose([Validators.minLength(1), this.regexValidator(new RegExp('[A-Z]'), { 'complexityUpper': '' }), this.regexValidator(new RegExp('[0-9]'), { 'complexityNumber': '' }), this.regexValidator(new RegExp('[^A-Za-z0-9]'), { 'complexitySpecial': '' })])
], ],
retypePasswordCtrl: [ retypePasswordCtrl: [
'', '',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment