diff --git a/client/src/app/infrastructure/utils/validators/email.ts b/client/src/app/infrastructure/utils/validators/email.ts new file mode 100644 index 0000000000..d7d51c6fcf --- /dev/null +++ b/client/src/app/infrastructure/utils/validators/email.ts @@ -0,0 +1,19 @@ +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; + }; +} diff --git a/client/src/app/site/modules/user-components/components/user-detail-view/user-detail-view.component.ts b/client/src/app/site/modules/user-components/components/user-detail-view/user-detail-view.component.ts index 05fd194eae..631769d776 100644 --- a/client/src/app/site/modules/user-components/components/user-detail-view/user-detail-view.component.ts +++ b/client/src/app/site/modules/user-components/components/user-detail-view/user-detail-view.component.ts @@ -12,6 +12,7 @@ import { } from '@angular/core'; import { UntypedFormBuilder, UntypedFormGroup, ValidatorFn, Validators } from '@angular/forms'; import { Subscription } from 'rxjs'; +import { createEmailValidator } from 'src/app/infrastructure/utils/validators/email'; import { OperatorService } from 'src/app/site/services/operator.service'; import { BaseUiComponent } from 'src/app/ui/base/base-ui-component'; @@ -294,7 +295,7 @@ export class UserDetailViewComponent extends BaseUiComponent implements OnInit, first_name: [``], last_name: [``], gender: [``], - email: [``], + email: [``, [createEmailValidator()]], last_email_sent: [``], default_password: [``], is_active: [true], diff --git a/client/src/app/site/pages/login/pages/reset-password/components/reset-password/reset-password.component.ts b/client/src/app/site/pages/login/pages/reset-password/components/reset-password/reset-password.component.ts index 1bec55a54a..6fee15dfde 100644 --- a/client/src/app/site/pages/login/pages/reset-password/components/reset-password/reset-password.component.ts +++ b/client/src/app/site/pages/login/pages/reset-password/components/reset-password/reset-password.component.ts @@ -1,6 +1,7 @@ import { Component, OnInit } from '@angular/core'; import { UntypedFormBuilder, UntypedFormGroup, Validators } from '@angular/forms'; import { TranslateService } from '@ngx-translate/core'; +import { createEmailValidator } from 'src/app/infrastructure/utils/validators/email'; 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'; @@ -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()]] }); } diff --git a/client/src/app/site/pages/meetings/pages/participants/pages/participant-detail/pages/participant-detail-manage/components/participant-create-wizard/participant-create-wizard.component.ts b/client/src/app/site/pages/meetings/pages/participants/pages/participant-detail/pages/participant-detail-manage/components/participant-create-wizard/participant-create-wizard.component.ts index 7be55d1911..04b7418b87 100644 --- a/client/src/app/site/pages/meetings/pages/participants/pages/participant-detail/pages/participant-detail-manage/components/participant-create-wizard/participant-create-wizard.component.ts +++ b/client/src/app/site/pages/meetings/pages/participants/pages/participant-detail/pages/participant-detail-manage/components/participant-create-wizard/participant-create-wizard.component.ts @@ -7,6 +7,7 @@ import { BehaviorSubject, distinctUntilChanged, Observable } from 'rxjs'; import { Id } from 'src/app/domain/definitions/key-types'; import { User } from 'src/app/domain/models/users/user'; import { SearchUsersPresenterService } from 'src/app/gateways/presenter/search-users-presenter.service'; +import { createEmailValidator } from 'src/app/infrastructure/utils/validators/email'; import { OneOfValidator, UserDetailViewComponent } from 'src/app/site/modules/user-components'; import { BaseMeetingComponent } from 'src/app/site/pages/meetings/base/base-meeting.component'; import { ViewGroup } from 'src/app/site/pages/meetings/pages/participants'; @@ -152,7 +153,7 @@ export class ParticipantCreateWizardComponent extends BaseMeetingComponent imple username: [``], first_name: [``], last_name: [``], - email: [``] + email: [``, createEmailValidator()] }, { validators: [OneOfValidator.validation([`username`, `first_name`, `last_name`, `email`], `name`)] diff --git a/client/src/app/site/pages/meetings/services/meeting-settings-definition.service/meeting-settings-definitions.ts b/client/src/app/site/pages/meetings/services/meeting-settings-definition.service/meeting-settings-definitions.ts index 9cdfb48f96..d459a9fdb3 100644 --- a/client/src/app/site/pages/meetings/services/meeting-settings-definition.service/meeting-settings-definitions.ts +++ b/client/src/app/site/pages/meetings/services/meeting-settings-definition.service/meeting-settings-definitions.ts @@ -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'; @@ -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`, diff --git a/client/src/app/site/pages/organization/pages/accounts/pages/account-detail/components/account-detail/account-detail.component.html b/client/src/app/site/pages/organization/pages/accounts/pages/account-detail/components/account-detail/account-detail.component.html index a74dfacd19..a5bd7d4987 100644 --- a/client/src/app/site/pages/organization/pages/accounts/pages/account-detail/components/account-detail/account-detail.component.html +++ b/client/src/app/site/pages/organization/pages/accounts/pages/account-detail/components/account-detail/account-detail.component.html @@ -75,6 +75,9 @@

{{ 'Organization specific information' | translate }}

placeholder="{{ 'Default vote weight' | translate }}" formControlName="default_vote_weight" /> + + Please select a vote weight bigger than zero. + diff --git a/client/src/app/site/pages/organization/pages/accounts/pages/account-detail/components/account-detail/account-detail.component.ts b/client/src/app/site/pages/organization/pages/accounts/pages/account-detail/components/account-detail/account-detail.component.ts index 6f33379992..53888bc807 100644 --- a/client/src/app/site/pages/organization/pages/accounts/pages/account-detail/components/account-detail/account-detail.component.ts +++ b/client/src/app/site/pages/organization/pages/accounts/pages/account-detail/components/account-detail/account-detail.component.ts @@ -1,5 +1,6 @@ import { KeyValue } from '@angular/common'; import { Component, OnInit, ViewChild } from '@angular/core'; +import { Validators } from '@angular/forms'; import { ActivatedRoute } from '@angular/router'; import { marker as _ } from '@colsen1991/ngx-translate-extract-marker'; import { TranslateService } from '@ngx-translate/core'; @@ -61,7 +62,7 @@ export class AccountDetailComponent extends BaseComponent implements OnInit { public readonly additionalFormControls = { default_structure_level: [``], default_number: [``], - default_vote_weight: [``], + default_vote_weight: [``, Validators.min(0.000001)], organization_management_level: [], committee_management_ids: [] }; @@ -203,6 +204,10 @@ export class AccountDetailComponent extends BaseComponent implements OnInit { return Object.keys(item).length; } + public get isDefaultVoteWeightError(): boolean { + return this.personalInfoFormValue.default_vote_weight < 0.000001; + } + private generateParticipationTableData(): void { const tableData: ParticipationTableData = this.user.committees.mapToObject(item => { return { diff --git a/client/src/app/site/pages/organization/pages/settings/modules/settings-detail/components/organization-settings/organization-settings.component.ts b/client/src/app/site/pages/organization/pages/settings/modules/settings-detail/components/organization-settings/organization-settings.component.ts index 955bd129b0..dfe74238c4 100644 --- a/client/src/app/site/pages/organization/pages/settings/modules/settings-detail/components/organization-settings/organization-settings.component.ts +++ b/client/src/app/site/pages/organization/pages/settings/modules/settings-detail/components/organization-settings/organization-settings.component.ts @@ -1,9 +1,10 @@ import { ChangeDetectionStrategy, Component } from '@angular/core'; -import { UntypedFormBuilder, UntypedFormGroup, Validators } from '@angular/forms'; +import { UntypedFormBuilder, UntypedFormGroup } from '@angular/forms'; import { marker as _ } from '@colsen1991/ngx-translate-extract-marker'; import { TranslateService } from '@ngx-translate/core'; import { availableTranslations } from 'src/app/domain/definitions/languages'; import { objectToFormattedString } from 'src/app/infrastructure/utils'; +import { createEmailValidator } from 'src/app/infrastructure/utils/validators/email'; import { BaseComponent } from 'src/app/site/base/base.component'; import { ORGANIZATION_ID } from 'src/app/site/pages/organization/services/organization.service'; import { OrganizationControllerService } from 'src/app/site/pages/organization/services/organization-controller.service'; @@ -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]