mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 18:14:17 +00:00
98863: Prevent retrieval of the domains on TYPE_REQUEST_FORGOT form & fixed error message when no emails are set
This commit is contained in:
@@ -20,9 +20,9 @@
|
|||||||
</span>
|
</span>
|
||||||
<span *ngIf="email.errors && ((email.errors.pattern && this.typeRequest === TYPE_REQUEST_REGISTER) || email.errors.email)">
|
<span *ngIf="email.errors && ((email.errors.pattern && this.typeRequest === TYPE_REQUEST_REGISTER) || email.errors.email)">
|
||||||
{{ MESSAGE_PREFIX + '.email.error.not-email-form' | translate }}
|
{{ MESSAGE_PREFIX + '.email.error.not-email-form' | translate }}
|
||||||
</span>
|
<ng-container *ngIf="validMailDomains.length > 0">
|
||||||
<span *ngIf="email.errors && email.errors.pattern && this.typeRequest === TYPE_REQUEST_REGISTER">
|
{{ MESSAGE_PREFIX + '.email.error.not-valid-domain' | translate: { domains: validMailDomains.join(', ') } }}
|
||||||
{{ MESSAGE_PREFIX + '.email.error.not-valid-domain' | translate: { domains: validMailDomains } }}
|
</ng-container>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@@ -12,8 +12,12 @@ import { EpersonRegistrationService } from '../core/data/eperson-registration.se
|
|||||||
import { By } from '@angular/platform-browser';
|
import { By } from '@angular/platform-browser';
|
||||||
import { RouterStub } from '../shared/testing/router.stub';
|
import { RouterStub } from '../shared/testing/router.stub';
|
||||||
import { NotificationsServiceStub } from '../shared/testing/notifications-service.stub';
|
import { NotificationsServiceStub } from '../shared/testing/notifications-service.stub';
|
||||||
import { RegisterEmailFormComponent } from './register-email-form.component';
|
import {
|
||||||
import { createSuccessfulRemoteDataObject$ } from '../shared/remote-data.utils';
|
RegisterEmailFormComponent,
|
||||||
|
TYPE_REQUEST_REGISTER,
|
||||||
|
TYPE_REQUEST_FORGOT
|
||||||
|
} from './register-email-form.component';
|
||||||
|
import { createSuccessfulRemoteDataObject$, createFailedRemoteDataObject$ } from '../shared/remote-data.utils';
|
||||||
import { ConfigurationDataService } from '../core/data/configuration-data.service';
|
import { ConfigurationDataService } from '../core/data/configuration-data.service';
|
||||||
import { ConfigurationProperty } from '../core/shared/configuration-property.model';
|
import { ConfigurationProperty } from '../core/shared/configuration-property.model';
|
||||||
|
|
||||||
@@ -44,6 +48,7 @@ describe('RegisterEmailFormComponent', () => {
|
|||||||
]
|
]
|
||||||
}))
|
}))
|
||||||
});
|
});
|
||||||
|
jasmine.getEnv().allowRespy(true);
|
||||||
|
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
imports: [CommonModule, RouterTestingModule.withRoutes([]), TranslateModule.forRoot(), ReactiveFormsModule],
|
imports: [CommonModule, RouterTestingModule.withRoutes([]), TranslateModule.forRoot(), ReactiveFormsModule],
|
||||||
@@ -69,6 +74,15 @@ describe('RegisterEmailFormComponent', () => {
|
|||||||
const elem = fixture.debugElement.queryAll(By.css('input#email'))[0].nativeElement;
|
const elem = fixture.debugElement.queryAll(By.css('input#email'))[0].nativeElement;
|
||||||
expect(elem).toBeDefined();
|
expect(elem).toBeDefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should not retrieve the validDomains for TYPE_REQUEST_FORGOT', () => {
|
||||||
|
spyOn(configurationDataService, 'findByPropertyName');
|
||||||
|
comp.typeRequest = TYPE_REQUEST_FORGOT;
|
||||||
|
|
||||||
|
comp.ngOnInit();
|
||||||
|
|
||||||
|
expect(configurationDataService.findByPropertyName).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
describe('email validation', () => {
|
describe('email validation', () => {
|
||||||
it('should be invalid when no email is present', () => {
|
it('should be invalid when no email is present', () => {
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
import {Component, Input, OnInit} from '@angular/core';
|
import { Component, Input, OnInit, OnDestroy } from '@angular/core';
|
||||||
import {EpersonRegistrationService} from '../core/data/eperson-registration.service';
|
import {EpersonRegistrationService} from '../core/data/eperson-registration.service';
|
||||||
import {NotificationsService} from '../shared/notifications/notifications.service';
|
import {NotificationsService} from '../shared/notifications/notifications.service';
|
||||||
import {TranslateService} from '@ngx-translate/core';
|
import {TranslateService} from '@ngx-translate/core';
|
||||||
@@ -7,8 +7,9 @@ import { FormBuilder, FormControl, FormGroup, Validators, ValidatorFn } from '@a
|
|||||||
import {Registration} from '../core/shared/registration.model';
|
import {Registration} from '../core/shared/registration.model';
|
||||||
import {RemoteData} from '../core/data/remote-data';
|
import {RemoteData} from '../core/data/remote-data';
|
||||||
import {ConfigurationDataService} from '../core/data/configuration-data.service';
|
import {ConfigurationDataService} from '../core/data/configuration-data.service';
|
||||||
import {getAllCompletedRemoteData} from '../core/shared/operators';
|
import { getAllSucceededRemoteDataPayload } from '../core/shared/operators';
|
||||||
import { ConfigurationProperty } from '../core/shared/configuration-property.model';
|
import { ConfigurationProperty } from '../core/shared/configuration-property.model';
|
||||||
|
import { Subscription } from 'rxjs';
|
||||||
|
|
||||||
export const TYPE_REQUEST_FORGOT = 'forgot';
|
export const TYPE_REQUEST_FORGOT = 'forgot';
|
||||||
export const TYPE_REQUEST_REGISTER = 'register';
|
export const TYPE_REQUEST_REGISTER = 'register';
|
||||||
@@ -20,7 +21,7 @@ export const TYPE_REQUEST_REGISTER = 'register';
|
|||||||
/**
|
/**
|
||||||
* Component responsible to render an email registration form.
|
* Component responsible to render an email registration form.
|
||||||
*/
|
*/
|
||||||
export class RegisterEmailFormComponent implements OnInit {
|
export class RegisterEmailFormComponent implements OnDestroy, OnInit {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The form containing the mail address
|
* The form containing the mail address
|
||||||
@@ -42,6 +43,8 @@ export class RegisterEmailFormComponent implements OnInit {
|
|||||||
validMailDomains: string[];
|
validMailDomains: string[];
|
||||||
TYPE_REQUEST_REGISTER = TYPE_REQUEST_REGISTER;
|
TYPE_REQUEST_REGISTER = TYPE_REQUEST_REGISTER;
|
||||||
|
|
||||||
|
subscriptions: Subscription[] = [];
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private epersonRegistrationService: EpersonRegistrationService,
|
private epersonRegistrationService: EpersonRegistrationService,
|
||||||
private notificationService: NotificationsService,
|
private notificationService: NotificationsService,
|
||||||
@@ -52,6 +55,10 @@ export class RegisterEmailFormComponent implements OnInit {
|
|||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ngOnDestroy(): void {
|
||||||
|
this.subscriptions.forEach((sub: Subscription) => sub.unsubscribe());
|
||||||
|
}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
const validators: ValidatorFn[] = [
|
const validators: ValidatorFn[] = [
|
||||||
Validators.required,
|
Validators.required,
|
||||||
@@ -64,13 +71,13 @@ export class RegisterEmailFormComponent implements OnInit {
|
|||||||
})
|
})
|
||||||
});
|
});
|
||||||
this.validMailDomains = [];
|
this.validMailDomains = [];
|
||||||
this.configurationService.findByPropertyName('authentication-password.domain.valid')
|
if (this.typeRequest === TYPE_REQUEST_REGISTER) {
|
||||||
.pipe(getAllCompletedRemoteData())
|
this.subscriptions.push(this.configurationService.findByPropertyName('authentication-password.domain.valid')
|
||||||
.subscribe((remoteData: RemoteData<ConfigurationProperty>) => {
|
.pipe(getAllSucceededRemoteDataPayload())
|
||||||
if (remoteData.payload) {
|
.subscribe((configurationProperty: ConfigurationProperty) => {
|
||||||
for (const remoteValue of remoteData.payload.values) {
|
for (const remoteValue of configurationProperty.values) {
|
||||||
this.validMailDomains.push(remoteValue);
|
this.validMailDomains.push(remoteValue);
|
||||||
if (this.validMailDomains.length !== 0 && this.typeRequest === TYPE_REQUEST_REGISTER) {
|
if (this.validMailDomains.length !== 0) {
|
||||||
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('|')),
|
||||||
@@ -78,8 +85,8 @@ export class RegisterEmailFormComponent implements OnInit {
|
|||||||
this.form.updateValueAndValidity();
|
this.form.updateValueAndValidity();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -87,7 +94,7 @@ export class RegisterEmailFormComponent implements OnInit {
|
|||||||
*/
|
*/
|
||||||
register() {
|
register() {
|
||||||
if (!this.form.invalid) {
|
if (!this.form.invalid) {
|
||||||
this.epersonRegistrationService.registerEmail(this.email.value, this.typeRequest).subscribe((response: RemoteData<Registration>) => {
|
this.subscriptions.push(this.epersonRegistrationService.registerEmail(this.email.value, this.typeRequest).subscribe((response: RemoteData<Registration>) => {
|
||||||
if (response.hasSucceeded) {
|
if (response.hasSucceeded) {
|
||||||
this.notificationService.success(this.translateService.get(`${this.MESSAGE_PREFIX}.success.head`),
|
this.notificationService.success(this.translateService.get(`${this.MESSAGE_PREFIX}.success.head`),
|
||||||
this.translateService.get(`${this.MESSAGE_PREFIX}.success.content`, {email: this.email.value}));
|
this.translateService.get(`${this.MESSAGE_PREFIX}.success.content`, {email: this.email.value}));
|
||||||
@@ -100,7 +107,7 @@ export class RegisterEmailFormComponent implements OnInit {
|
|||||||
this.notificationService.error('title', response.errorMessage);
|
this.notificationService.error('title', response.errorMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -3013,7 +3013,7 @@
|
|||||||
|
|
||||||
"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.not-email-form": "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.error.not-valid-domain": "Use email with allowed domains: {{ domains }}",
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user