98863: Domain validator fix + error message

This commit is contained in:
Marie Verdonck
2023-01-26 14:24:52 +01:00
parent 0d7a030960
commit 31d86eeb8c
7 changed files with 30 additions and 10 deletions

View File

@@ -1,3 +1,3 @@
<ds-register-email-form <ds-register-email-form
[MESSAGE_PREFIX]="'forgot-email.form'" [typeRequest]="'forgot'"> [MESSAGE_PREFIX]="'forgot-email.form'" [typeRequest]="typeRequest">
</ds-register-email-form> </ds-register-email-form>

View File

@@ -1,4 +1,5 @@
import { Component } from '@angular/core'; import { Component } from '@angular/core';
import { TYPE_REQUEST_FORGOT } from '../../register-email-form/register-email-form.component';
@Component({ @Component({
selector: 'ds-forgot-email', selector: 'ds-forgot-email',
@@ -9,5 +10,5 @@ import { Component } from '@angular/core';
* Component responsible the forgot password email step * Component responsible the forgot password email step
*/ */
export class ForgotEmailComponent { export class ForgotEmailComponent {
typeRequest = TYPE_REQUEST_FORGOT;
} }

View File

@@ -18,8 +18,11 @@
<span *ngIf="email.errors && email.errors.required"> <span *ngIf="email.errors && email.errors.required">
{{ MESSAGE_PREFIX + '.email.error.required' | translate }} {{ MESSAGE_PREFIX + '.email.error.required' | translate }}
</span> </span>
<span *ngIf="email.errors && email.errors.pattern"> <span *ngIf="email.errors && ((email.errors.pattern && this.typeRequest === TYPE_REQUEST_REGISTER) || email.errors.email)">
{{ MESSAGE_PREFIX + '.email.error.pattern' | translate }} {{ MESSAGE_PREFIX + '.email.error.not-email-form' | translate }}
</span>
<span *ngIf="email.errors && email.errors.pattern && this.typeRequest === TYPE_REQUEST_REGISTER">
{{ MESSAGE_PREFIX + '.email.error.not-valid-domain' | translate: { domains: validMailDomains } }}
</span> </span>
</div> </div>
</div> </div>

View File

@@ -10,6 +10,9 @@ import {ConfigurationDataService} from '../core/data/configuration-data.service'
import {getAllCompletedRemoteData} from '../core/shared/operators'; import {getAllCompletedRemoteData} from '../core/shared/operators';
import { ConfigurationProperty } from '../core/shared/configuration-property.model'; import { ConfigurationProperty } from '../core/shared/configuration-property.model';
export const TYPE_REQUEST_FORGOT = 'forgot';
export const TYPE_REQUEST_REGISTER = 'register';
@Component({ @Component({
selector: 'ds-register-email-form', selector: 'ds-register-email-form',
templateUrl: './register-email-form.component.html' templateUrl: './register-email-form.component.html'
@@ -37,6 +40,15 @@ export class RegisterEmailFormComponent implements OnInit {
typeRequest: string = null; typeRequest: string = null;
validMailDomains: string[]; validMailDomains: string[];
TYPE_REQUEST_REGISTER = TYPE_REQUEST_REGISTER;
captchaVersion(): Observable<string> {
return this.googleRecaptchaService.captchaVersion();
}
captchaMode(): Observable<string> {
return this.googleRecaptchaService.captchaMode();
}
constructor( constructor(
private epersonRegistrationService: EpersonRegistrationService, private epersonRegistrationService: EpersonRegistrationService,
@@ -51,6 +63,7 @@ export class RegisterEmailFormComponent implements OnInit {
ngOnInit(): void { ngOnInit(): void {
const validators: ValidatorFn[] = [ const validators: ValidatorFn[] = [
Validators.required, Validators.required,
Validators.email,
Validators.pattern('^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}$') Validators.pattern('^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}$')
]; ];
this.form = this.formBuilder.group({ this.form = this.formBuilder.group({
@@ -65,10 +78,10 @@ export class RegisterEmailFormComponent implements OnInit {
if (remoteData.payload) { if (remoteData.payload) {
for (const remoteValue of remoteData.payload.values) { for (const remoteValue of remoteData.payload.values) {
this.validMailDomains.push(remoteValue); this.validMailDomains.push(remoteValue);
if (this.validMailDomains.length !== 0 && this.MESSAGE_PREFIX === 'register-page.registration') { if (this.validMailDomains.length !== 0 && this.typeRequest === TYPE_REQUEST_REGISTER) {
this.form.get('email').setValidators([ this.form.get('email').setValidators([
...validators, ...validators,
Validators.pattern(this.validMailDomains.map((domain: string) => '(^.*@' + domain.replace(new RegExp('\\.', 'g'), '\\.') + '$)').join('|')), Validators.pattern(this.validMailDomains.map((domain: string) => '(^.*' + domain.replace(new RegExp('\\.', 'g'), '\\.') + '$)').join('|')),
]); ]);
this.form.updateValueAndValidity(); this.form.updateValueAndValidity();
} }

View File

@@ -1,3 +1,3 @@
<ds-register-email-form <ds-register-email-form
[MESSAGE_PREFIX]="'register-page.registration'" [typeRequest]="'register'"> [MESSAGE_PREFIX]="'register-page.registration'" [typeRequest]="typeRequest">
</ds-register-email-form> </ds-register-email-form>

View File

@@ -1,4 +1,5 @@
import { Component } from '@angular/core'; import { Component } from '@angular/core';
import { TYPE_REQUEST_REGISTER } from '../../register-email-form/register-email-form.component';
@Component({ @Component({
selector: 'ds-register-email', selector: 'ds-register-email',
@@ -9,5 +10,5 @@ import { Component } from '@angular/core';
* Component responsible the email registration step when registering as a new user * Component responsible the email registration step when registering as a new user
*/ */
export class RegisterEmailComponent { export class RegisterEmailComponent {
typeRequest = TYPE_REQUEST_REGISTER;
} }

View File

@@ -1406,7 +1406,7 @@
"forgot-email.form.email.error.required": "Please fill in an email address", "forgot-email.form.email.error.required": "Please fill in an email address",
"forgot-email.form.email.error.pattern": "Please fill in a valid email address", "forgot-email.form.email.error.not-email-form": "Please fill in a valid email address",
"forgot-email.form.email.hint": "This address will be verified and used as your login name.", "forgot-email.form.email.hint": "This address will be verified and used as your login name.",
@@ -3013,7 +3013,9 @@
"register-page.registration.email.error.required": "Please fill in an email address", "register-page.registration.email.error.required": "Please fill in an email address",
"register-page.registration.email.error.pattern": "Please fill in a valid email address", "register-page.registration.email.error.not-email-form": "Please fill in a valid email address. ",
"register-page.registration.email.error.not-valid-domain": "Use email with allowed domains: {{ domains }}",
"register-page.registration.email.hint": "This address will be verified and used as your login name.", "register-page.registration.email.hint": "This address will be verified and used as your login name.",