mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
98863: Domain validator fix + error message
This commit is contained in:
@@ -1,3 +1,3 @@
|
||||
<ds-register-email-form
|
||||
[MESSAGE_PREFIX]="'forgot-email.form'" [typeRequest]="'forgot'">
|
||||
[MESSAGE_PREFIX]="'forgot-email.form'" [typeRequest]="typeRequest">
|
||||
</ds-register-email-form>
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -18,8 +18,11 @@
|
||||
<span *ngIf="email.errors && email.errors.required">
|
||||
{{ MESSAGE_PREFIX + '.email.error.required' | translate }}
|
||||
</span>
|
||||
<span *ngIf="email.errors && email.errors.pattern">
|
||||
{{ MESSAGE_PREFIX + '.email.error.pattern' | translate }}
|
||||
<span *ngIf="email.errors && ((email.errors.pattern && this.typeRequest === TYPE_REQUEST_REGISTER) || email.errors.email)">
|
||||
{{ 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>
|
||||
</div>
|
||||
</div>
|
||||
|
@@ -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<string> {
|
||||
return this.googleRecaptchaService.captchaVersion();
|
||||
}
|
||||
|
||||
captchaMode(): Observable<string> {
|
||||
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();
|
||||
}
|
||||
|
@@ -1,3 +1,3 @@
|
||||
<ds-register-email-form
|
||||
[MESSAGE_PREFIX]="'register-page.registration'" [typeRequest]="'register'">
|
||||
[MESSAGE_PREFIX]="'register-page.registration'" [typeRequest]="typeRequest">
|
||||
</ds-register-email-form>
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -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.",
|
||||
|
||||
|
Reference in New Issue
Block a user