定制 magenettic/module-email-validation 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

magenettic/module-email-validation

Composer 安装命令:

composer require magenettic/module-email-validation

包简介

Email validation rules for Magento 2

README 文档

README

Email validation rules module for Magento 2.4.x

Overview

This module adds custom email validation rules for customer registration, allowing merchants to block or allow specific email domains and addresses.

Features

1. Blocked Email Domains (Blacklist)

Rejects customer registrations with emails from specified domains.

Example: If terminator.com is in the blacklist, any email like john@terminator.com will be rejected.

2. Allowed Email Domains (Whitelist)

Stores a list of allowed email domains.

Example: If company.com is in the whitelist, emails like john@company.com will be allowed.

3. Force Whitelist

When enabled, only emails from domains in the whitelist will be accepted. All other domains will be blocked.

4. Blocked Emails (Blacklist)

Rejects specific email addresses completely.

Example: If spam@example.com is in the list, this exact email will be rejected even if the domain is not blocked.

Configuration

Navigate to: Stores > Settings > Configuration > Customers > Customer Configuration > Email Validation

Setting Description
Enable Email Validation Enable/disable the module
Blocked Email Domains Enter domains one per line (e.g., terminator.com)
Allowed Email Domains Enter allowed domains one per line
Force Whitelist When enabled, only whitelist domains are accepted
Blocked Emails Enter complete emails one per line

Requirements

  • Magento 2.4.x
  • PHP 8.2+

Installation

Inform the repository in you composer.json

"repositories": [
    {
      "type": "vcs",
      "url": "https://github.com/magenettic/module-email-validation.git"
    }
  ],

Run composer installation

composer require magenettic/module-email-validation

Run the magento CLI commands

bin/magento module:enable Magenettic_EmailValidation
bin/magento setup:upgrade
bin/magento cache:flush

Validation Flow

Customer submits email
    |
    v
Check if email is in blocked emails list
    |
    v
Check if domain is in blocked domains list
    |
    v
Check if Force Whitelist is enabled
    |-- No  --> Allow domain (unless blocked)
    |
    +-- Yes --> Check if domain is in allowed domains list
                  |-- Yes --> Allow email
                  +-- No  --> Reject email

Examples

Scenario 1: Block a specific domain

Blocked Domains: terminator.com
Force Whitelist: No

user@terminator.com --> REJECTED
user@gmail.com      --> ALLOWED

Scenario 2: Allow only specific domains

Allowed Domains: company.com, partner.org
Force Whitelist: Yes

user@company.com    --> ALLOWED
user@partner.org    --> ALLOWED
user@gmail.com      --> REJECTED

Scenario 3: Block specific email

Blocked Emails: spam@spammer.com, test@test.com
Force Whitelist: No

spam@spammer.com    --> REJECTED
test@test.com       --> REJECTED
user@gmail.com      --> ALLOWED

Testing

Unit Tests

The module includes comprehensive unit tests covering:

  • Helper/DataTest.php - Tests for configuration parsing and validation logic
  • Plugin/BeforeEmailValidatorPluginTest.php - Tests for email validation plugin

Run Tests

vendor/bin/phpunit -c dev/tests/unit/phpunit.xml.dist app/code/Magenettic/EmailValidation/Test/Unit/

Test Results

27 tests, 61 assertions - OK

Test Coverage

Component Tests Coverage
Helper\Data 18 tests isEnabled, isWhitelistForced, getBlockedDomains, getAllowedDomains, getBlockedEmails, extractDomain, isDomainBlocked, isDomainAllowed, isEmailBlocked
Plugin\BeforeEmailValidatorPlugin 8 tests beforeCreateAccountWithPasswordHash, beforeCreateAccount

Module Structure

Magenettic/EmailValidation/
├── Helper/Data.php                    # Configuration helper
├── Plugin/
│   ├── BeforeEmailValidatorPlugin.php  # Blocks registration
│   └── AroundEmailValidatorPlugin.php  # Global validation
├── Test/Unit/
│   ├── Helper/DataTest.php
│   └── Plugin/BeforeEmailValidatorPluginTest.php
├── etc/
│   ├── adminhtml/system.xml           # Configuration fields
│   ├── di.xml                         # Plugin registration
│   └── module.xml                     # Module declaration
├── composer.json
├── README.md
└── registration.php

License

MIT

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 6
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-06-18

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固