From 31d86eeb8cac289085d61477ce31f753e9111f91 Mon Sep 17 00:00:00 2001 From: Marie Verdonck Date: Thu, 26 Jan 2023 14:24:52 +0100 Subject: [PATCH] 98863: Domain validator fix + error message --- .../forgot-email.component.html | 2 +- .../forgot-email.component.ts | 3 ++- .../register-email-form.component.html | 7 +++++-- .../register-email-form.component.ts | 17 +++++++++++++++-- .../register-email.component.html | 2 +- .../register-email/register-email.component.ts | 3 ++- src/assets/i18n/en.json5 | 6 ++++-- 7 files changed, 30 insertions(+), 10 deletions(-) diff --git a/src/app/forgot-password/forgot-password-email/forgot-email.component.html b/src/app/forgot-password/forgot-password-email/forgot-email.component.html index 8be86f17ae..995108cdbc 100644 --- a/src/app/forgot-password/forgot-password-email/forgot-email.component.html +++ b/src/app/forgot-password/forgot-password-email/forgot-email.component.html @@ -1,3 +1,3 @@ + [MESSAGE_PREFIX]="'forgot-email.form'" [typeRequest]="typeRequest"> diff --git a/src/app/forgot-password/forgot-password-email/forgot-email.component.ts b/src/app/forgot-password/forgot-password-email/forgot-email.component.ts index af482bdb67..66a61ed7ee 100644 --- a/src/app/forgot-password/forgot-password-email/forgot-email.component.ts +++ b/src/app/forgot-password/forgot-password-email/forgot-email.component.ts @@ -1,4 +1,5 @@ import { Component } from '@angular/core'; +import { TYPE_REQUEST_FORGOT } from '../../register-email-form/register-email-form.component'; @Component({ selector: 'ds-forgot-email', @@ -9,5 +10,5 @@ import { Component } from '@angular/core'; * Component responsible the forgot password email step */ export class ForgotEmailComponent { - + typeRequest = TYPE_REQUEST_FORGOT; } diff --git a/src/app/register-email-form/register-email-form.component.html b/src/app/register-email-form/register-email-form.component.html index a1eb0cef98..8cc0d293cf 100644 --- a/src/app/register-email-form/register-email-form.component.html +++ b/src/app/register-email-form/register-email-form.component.html @@ -18,8 +18,11 @@ {{ MESSAGE_PREFIX + '.email.error.required' | translate }} - - {{ MESSAGE_PREFIX + '.email.error.pattern' | translate }} + + {{ MESSAGE_PREFIX + '.email.error.not-email-form' | translate }} + + + {{ MESSAGE_PREFIX + '.email.error.not-valid-domain' | translate: { domains: validMailDomains } }} diff --git a/src/app/register-email-form/register-email-form.component.ts b/src/app/register-email-form/register-email-form.component.ts index 9269a0cb2d..83053bd345 100644 --- a/src/app/register-email-form/register-email-form.component.ts +++ b/src/app/register-email-form/register-email-form.component.ts @@ -10,6 +10,9 @@ import {ConfigurationDataService} from '../core/data/configuration-data.service' import {getAllCompletedRemoteData} from '../core/shared/operators'; import { ConfigurationProperty } from '../core/shared/configuration-property.model'; +export const TYPE_REQUEST_FORGOT = 'forgot'; +export const TYPE_REQUEST_REGISTER = 'register'; + @Component({ selector: 'ds-register-email-form', templateUrl: './register-email-form.component.html' @@ -37,6 +40,15 @@ export class RegisterEmailFormComponent implements OnInit { typeRequest: string = null; validMailDomains: string[]; + TYPE_REQUEST_REGISTER = TYPE_REQUEST_REGISTER; + + captchaVersion(): Observable { + return this.googleRecaptchaService.captchaVersion(); + } + + captchaMode(): Observable { + return this.googleRecaptchaService.captchaMode(); + } constructor( private epersonRegistrationService: EpersonRegistrationService, @@ -51,6 +63,7 @@ export class RegisterEmailFormComponent implements OnInit { ngOnInit(): void { const validators: ValidatorFn[] = [ Validators.required, + Validators.email, Validators.pattern('^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}$') ]; this.form = this.formBuilder.group({ @@ -65,10 +78,10 @@ export class RegisterEmailFormComponent implements OnInit { if (remoteData.payload) { for (const remoteValue of remoteData.payload.values) { 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([ ...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(); } diff --git a/src/app/register-page/register-email/register-email.component.html b/src/app/register-page/register-email/register-email.component.html index 80b6885272..1829bb2914 100644 --- a/src/app/register-page/register-email/register-email.component.html +++ b/src/app/register-page/register-email/register-email.component.html @@ -1,3 +1,3 @@ + [MESSAGE_PREFIX]="'register-page.registration'" [typeRequest]="typeRequest"> diff --git a/src/app/register-page/register-email/register-email.component.ts b/src/app/register-page/register-email/register-email.component.ts index 7b7b0f631b..228e8c56a0 100644 --- a/src/app/register-page/register-email/register-email.component.ts +++ b/src/app/register-page/register-email/register-email.component.ts @@ -1,4 +1,5 @@ import { Component } from '@angular/core'; +import { TYPE_REQUEST_REGISTER } from '../../register-email-form/register-email-form.component'; @Component({ 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 */ export class RegisterEmailComponent { - + typeRequest = TYPE_REQUEST_REGISTER; } diff --git a/src/assets/i18n/en.json5 b/src/assets/i18n/en.json5 index 511d923f7d..7a011ecff5 100644 --- a/src/assets/i18n/en.json5 +++ b/src/assets/i18n/en.json5 @@ -1406,7 +1406,7 @@ "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.", @@ -3013,7 +3013,9 @@ "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.",