Skip to content

Commit

Permalink
Use a custom email validator with backend regex
Browse files Browse the repository at this point in the history
  • Loading branch information
reiterl committed Nov 2, 2023
1 parent eebb15f commit 48e4f99
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 5 deletions.
20 changes: 20 additions & 0 deletions client/src/app/infrastructure/utils/validators/email.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import {AbstractControl, ValidationErrors, ValidatorFn} from '@angular/forms';

const EMAIL_VALIDATION_REGEX = /[A-Z0-9._+\-ÄÖÜ]+@[A-Z0-9.\-ÄÖÜ]+\.[A-ZÄÖÜ]{2,}/i

export function createEmailValidator(): ValidatorFn {
return (control:AbstractControl) : ValidationErrors | null => {

const value = control.value;

if (!value) {
return null;
}

const validEmail = EMAIL_VALIDATION_REGEX.test(value);
if (!validEmail) {
return {"email": "Please enter a valid email address"};
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { BaseUiComponent } from 'src/app/ui/base/base-ui-component';
import { GENDERS } from '../../../../../domain/models/users/user';
import { ViewUser } from '../../../../../site/pages/meetings/view-models/view-user';
import { OneOfValidator } from '../../validators';
import { createEmailValidator } from 'src/app/infrastructure/utils/validators/email';

@Component({
selector: `os-user-detail-view`,
Expand Down Expand Up @@ -294,7 +295,7 @@ export class UserDetailViewComponent extends BaseUiComponent implements OnInit,
first_name: [``],
last_name: [``],
gender: [``],
email: [``, [Validators.email]],
email: [``, [createEmailValidator()]],
last_email_sent: [``],
default_password: [``],
is_active: [true],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { TranslateService } from '@ngx-translate/core';
import { BaseComponent } from 'src/app/site/base/base.component';
import { ComponentServiceCollectorService } from 'src/app/site/services/component-service-collector.service';
import { UserControllerService } from 'src/app/site/services/user-controller.service';
import { createEmailValidator } from 'src/app/infrastructure/utils/validators/email';

@Component({
selector: `os-reset-password`,
Expand Down Expand Up @@ -33,7 +34,7 @@ export class ResetPasswordComponent extends BaseComponent implements OnInit {
) {
super(componentServiceCollector, translate);
this.resetPasswordForm = formBuilder.group({
email: [``, [Validators.required, Validators.email]]
email: [``, [Validators.required, createEmailValidator()]]
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { MeetingComponentServiceCollectorService } from 'src/app/site/pages/meet
import { PERSONAL_FORM_CONTROLS, ViewUser } from 'src/app/site/pages/meetings/view-models/view-user';
import { OrganizationSettingsService } from 'src/app/site/pages/organization/services/organization-settings.service';
import { UserService } from 'src/app/site/services/user.service';
import { createEmailValidator } from 'src/app/infrastructure/utils/validators/email';

import { GroupControllerService } from '../../../../../../modules/groups/services/group-controller.service';
import {
Expand Down Expand Up @@ -152,7 +153,7 @@ export class ParticipantCreateWizardComponent extends BaseMeetingComponent imple
username: [``],
first_name: [``],
last_name: [``],
email: [``, Validators.email]
email: [``, createEmailValidator()]
},
{
validators: [OneOfValidator.validation([`username`, `first_name`, `last_name`, `email`], `name`)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
PollTypeVerbose
} from 'src/app/domain/models/poll/poll-constants';
import { ObjectReplaceKeysConfig } from 'src/app/infrastructure/utils';
import { createEmailValidator } from 'src/app/infrastructure/utils/validators/email';

import { OrganizationSettingsService } from '../../../organization/services/organization-settings.service';
import { AssignmentPollMethodVerbose } from '../../pages/assignments/modules/assignment-poll/definitions';
Expand Down Expand Up @@ -905,7 +906,7 @@ export const meetingSettings: SettingsGroup[] = fillInSettingsDefaults([
key: `users_email_replyto`,
label: _(`Reply address`),
type: `email`,
validators: [Validators.email]
validators: [createEmailValidator()]
},
{
key: `users_email_subject`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { OrganizationControllerService } from 'src/app/site/pages/organization/s
import { ViewOrganization } from 'src/app/site/pages/organization/view-models/view-organization';
import { ComponentServiceCollectorService } from 'src/app/site/services/component-service-collector.service';
import { OperatorService } from 'src/app/site/services/operator.service';
import { createEmailValidator } from 'src/app/infrastructure/utils/validators/email';

@Component({
selector: `os-organization-settings`,
Expand Down Expand Up @@ -70,7 +71,7 @@ export class OrganizationSettingsComponent extends BaseComponent {
privacy_policy: [this._currentOrgaSettings.privacy_policy],
login_text: [this._currentOrgaSettings.login_text],
users_email_body: [this._currentOrgaSettings.users_email_body],
users_email_replyto: [this._currentOrgaSettings.users_email_replyto, [Validators.email]],
users_email_replyto: [this._currentOrgaSettings.users_email_replyto, [createEmailValidator()]],
users_email_sender: [this._currentOrgaSettings.users_email_sender],
users_email_subject: [this._currentOrgaSettings.users_email_subject],
default_language: [this._currentOrgaSettings.default_language]
Expand Down

0 comments on commit 48e4f99

Please sign in to comment.