diff --git a/apps/maarch_entreprise/js/angular/app/password-modification.component.ts b/apps/maarch_entreprise/js/angular/app/password-modification.component.ts index ab564a04ea676297584f3c9f22bfcc4ce972de3c..6372627a547b693096a9dcb035f26e6cdf590a5a 100644 --- a/apps/maarch_entreprise/js/angular/app/password-modification.component.ts +++ b/apps/maarch_entreprise/js/angular/app/password-modification.component.ts @@ -97,14 +97,18 @@ export class PasswordModificationComponent implements OnInit { this.coreUrl = angularGlobals.coreUrl; this.http.get(this.coreUrl + 'rest/passwordRules') .subscribe((data: any) => { + let valArr : ValidatorFn[] = []; let ruleTextArr: String[] = []; + + valArr.push(Validators.required); + data.rules.forEach((rule: any) => { if (rule.label == 'minLength') { this.passwordRules.minLength.enabled = rule.enabled; 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) { ruleTextArr.push(rule.value + ' ' + this.lang['password' + rule.label]); } @@ -113,6 +117,7 @@ export class PasswordModificationComponent implements OnInit { } else if (rule.label == 'complexityUpper') { this.passwordRules.complexityUpper.enabled = rule.enabled; this.passwordRules.complexityUpper.value = rule.value; + valArr.push(this.regexValidator(new RegExp('[A-Z]'), { 'complexityUpper': '' })); if (rule.enabled) { ruleTextArr.push(this.lang['password' + rule.label]); } @@ -121,6 +126,7 @@ export class PasswordModificationComponent implements OnInit { } else if (rule.label == 'complexityNumber') { this.passwordRules.complexityNumber.enabled = rule.enabled; this.passwordRules.complexityNumber.value = rule.value; + valArr.push(this.regexValidator(new RegExp('[0-9]'), { 'complexityNumber': '' })); if (rule.enabled) { ruleTextArr.push(this.lang['password' + rule.label]); } @@ -129,6 +135,7 @@ export class PasswordModificationComponent implements OnInit { } else if (rule.label == 'complexitySpecial') { this.passwordRules.complexitySpecial.enabled = rule.enabled; this.passwordRules.complexitySpecial.value = rule.value; + valArr.push(this.regexValidator(new RegExp('[^A-Za-z0-9]'), { 'complexitySpecial': '' })); if (rule.enabled) { ruleTextArr.push(this.lang['password' + rule.label]); } @@ -145,17 +152,16 @@ export class PasswordModificationComponent implements OnInit { ruleTextArr.push(this.lang['passwordhistoryLastUseDesc'] + ' ' + rule.value + ' ' + this.lang['passwordhistoryLastUseDesc2']); } } - }); this.ruleText = ruleTextArr.join(', '); + this.firstFormGroup.controls["newPasswordCtrl"].setValidators(valArr); }, (err) => { this.notify.error(err.error.errors); }); this.firstFormGroup = this._formBuilder.group({ 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: [ '', @@ -182,6 +188,7 @@ export class PasswordModificationComponent implements OnInit { } getErrorMessage() { + console.log(this.firstFormGroup.controls['newPasswordCtrl'].errors); if (this.firstFormGroup.controls['newPasswordCtrl'].hasError('required')) { return this.lang.requiredField + ' !'; diff --git a/apps/maarch_entreprise/js/angular/app/profile.component.ts b/apps/maarch_entreprise/js/angular/app/profile.component.ts index 2297d5e7cc770b30c9735b8d98e6d2d17a3dbd9b..14584f812e764b8f42f900a9b57015ccbb5dd6f9 100755 --- a/apps/maarch_entreprise/js/angular/app/profile.component.ts +++ b/apps/maarch_entreprise/js/angular/app/profile.component.ts @@ -745,12 +745,13 @@ export class ProfileComponent extends AutoCompletePlugin implements OnInit { changePasswd() { this.http.get(this.coreUrl + 'rest/passwordRules') .subscribe((data: any) => { + let valArr : ValidatorFn[] = []; let ruleTextArr: String[] = []; data.rules.forEach((rule: any) => { if (rule.label == 'minLength') { this.passwordRules.minLength.enabled = rule.enabled; 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) { ruleTextArr.push(rule.value + ' ' + this.lang['password' + rule.label]); } @@ -759,6 +760,7 @@ export class ProfileComponent extends AutoCompletePlugin implements OnInit { } else if (rule.label == 'complexityUpper') { this.passwordRules.complexityUpper.enabled = rule.enabled; this.passwordRules.complexityUpper.value = rule.value; + valArr.push(this.regexValidator(new RegExp('[A-Z]'), { 'complexityUpper': '' })); if (rule.enabled) { ruleTextArr.push(this.lang['password' + rule.label]); } @@ -767,6 +769,7 @@ export class ProfileComponent extends AutoCompletePlugin implements OnInit { } else if (rule.label == 'complexityNumber') { this.passwordRules.complexityNumber.enabled = rule.enabled; this.passwordRules.complexityNumber.value = rule.value; + valArr.push(this.regexValidator(new RegExp('[0-9]'), { 'complexityNumber': '' })); if (rule.enabled) { ruleTextArr.push(this.lang['password' + rule.label]); } @@ -775,6 +778,7 @@ export class ProfileComponent extends AutoCompletePlugin implements OnInit { } else if (rule.label == 'complexitySpecial') { this.passwordRules.complexitySpecial.enabled = rule.enabled; this.passwordRules.complexitySpecial.value = rule.value; + valArr.push(this.regexValidator(new RegExp('[^A-Za-z0-9]'), { 'complexitySpecial': '' })); if (rule.enabled) { ruleTextArr.push(this.lang['password' + rule.label]); } @@ -794,14 +798,14 @@ export class ProfileComponent extends AutoCompletePlugin implements OnInit { }); this.ruleText = ruleTextArr.join(', '); + this.firstFormGroup.controls["newPasswordCtrl"].setValidators(valArr); }, (err) => { this.notify.error(err.error.errors); }); this.firstFormGroup = this._formBuilder.group({ 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: [ '',