All Projects → maize-tech → laravel-email-domain-rule

maize-tech / laravel-email-domain-rule

Licence: MIT license
A package to validate email domains in a user registration form

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to laravel-email-domain-rule

Relay Authentication
An example app demonstrating role based authentication and file upload with Relay and GraphQL.
Stars: ✭ 153 (+155%)
Mutual labels:  registration
Laravel Auth
Laravel 8 with user authentication, registration with email confirmation, social media authentication, password recovery, and captcha protection. Uses offical [Bootstrap 4](http://getbootstrap.com). This also makes full use of Controllers for the routes, templates for the views, and makes use of middleware for routing. The project can be stood u…
Stars: ✭ 2,692 (+4386.67%)
Mutual labels:  registration
djaodjin-signup
Django app for frictionless signup
Stars: ✭ 18 (-70%)
Mutual labels:  registration
Yii2 Angular Boilerplate
Yii2 REST API + Angular10 Boilerplate (Frontend/Backend)
Stars: ✭ 194 (+223.33%)
Mutual labels:  registration
Elastix
Official elastix repository
Stars: ✭ 222 (+270%)
Mutual labels:  registration
maks
Motion Averaging
Stars: ✭ 52 (-13.33%)
Mutual labels:  registration
Deepmapping
code/webpage for the DeepMapping project
Stars: ✭ 140 (+133.33%)
Mutual labels:  registration
spec-pattern
Specification design pattern for JavaScript and TypeScript with bonus classes
Stars: ✭ 43 (-28.33%)
Mutual labels:  rule
Cupoch
Robotics with GPU computing
Stars: ✭ 225 (+275%)
Mutual labels:  registration
icra20-hand-object-pose
[ICRA 2020] Robust, Occlusion-aware Pose Estimation for Objects Grasped by Adaptive Hands
Stars: ✭ 42 (-30%)
Mutual labels:  registration
Django Graphql Auth
Django registration and authentication with GraphQL.
Stars: ✭ 200 (+233.33%)
Mutual labels:  registration
Deepglobalregistration
[CVPR 2020 Oral] A differentiable framework for 3D registration
Stars: ✭ 222 (+270%)
Mutual labels:  registration
PSRule.Rules.CAF
A suite of rules to validate Azure resources against the Cloud Adoption Framework (CAF) using PSRule.
Stars: ✭ 54 (-10%)
Mutual labels:  rule
3d Pointcloud
Papers and Datasets about Point Cloud.
Stars: ✭ 179 (+198.33%)
Mutual labels:  registration
napari-hub
Discover, install, and share napari plugins
Stars: ✭ 44 (-26.67%)
Mutual labels:  registration
D3feat
[TensorFlow] Implementation of CVPR'20 oral paper - D3Feat: Joint Learning of Dense Detection and Description of 3D Local Features https://arxiv.org/abs/2003.03164
Stars: ✭ 143 (+138.33%)
Mutual labels:  registration
Django Rest Registration
User-related REST API based on the awesome Django REST Framework
Stars: ✭ 240 (+300%)
Mutual labels:  registration
Bee-Connect
Ruby on Rails App. A good example of how to build social networking system with live chat support, blogging,groups etc.
Stars: ✭ 30 (-50%)
Mutual labels:  registration
rules-framework
A generic rules framework that allows defining and evaluating rules for complex business scenarios.
Stars: ✭ 35 (-41.67%)
Mutual labels:  rule
registration
✏️ Hackathon registration server
Stars: ✭ 60 (+0%)
Mutual labels:  registration

Social Card of Laravel Email Domain Rule

Laravel Email Domain Rule

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

This package allows to define a subset of allowed email domains and validate any user registration form with a custom rule.

Installation

You can install the package via composer:

composer require maize-tech/laravel-email-domain-rule

You can publish and run the migrations with:

php artisan vendor:publish --provider="Maize\EmailDomainRule\EmailDomainRuleServiceProvider" --tag="email-domain-rule-migrations"
php artisan migrate

You can publish the config file with:

php artisan vendor:publish --provider="Maize\EmailDomainRule\EmailDomainRuleServiceProvider" --tag="email-domain-rule-config"

This is the content of the published config file:

return [

    /*
    |--------------------------------------------------------------------------
    | Email Domain model
    |--------------------------------------------------------------------------
    |
    | Here you may specify the fully qualified class name of the email domain model.
    |
    */

    'email_domain_model' => Maize\EmailDomainRule\Models\EmailDomain::class,

    /*
    |--------------------------------------------------------------------------
    | Email Domain wildcard
    |--------------------------------------------------------------------------
    |
    | Here you may specify the character used as wildcard for all email domains.
    |
    */

    'email_domain_wildcard' => '*',

    /*
    |--------------------------------------------------------------------------
    | Validation message
    |--------------------------------------------------------------------------
    |
    | Here you may specify the message thrown if the validation rule fails.
    |
    */

    'validation_message' => 'The selected :attribute does not have a valid domain.',
];

Usage

Basic

To use the package, run the migration and fill in the table with a list of accepted email domains for your application.

You can then just add the custom validation rule to validate, for example, a user registration form.

use Maize\EmailDomainRule\EmailDomainRule;
use Illuminate\Support\Facades\Validator;

$email = '[email protected]';

Validator::make([
    'email' => $email,
], [
    'email' => [
        'string',
        'email',
        new EmailDomainRule,
    ],
])->validated(); 

That's all! Laravel will handle the rest by validating the input and throwing an error message if validation fails.

Wildcard domains

If needed, you can optionally add wildcard domains to the email_domains database table: the custom rule will handle the rest.

The default wildcard character is an asterisk (*), but you can customize it within the email_domain_wildcard setting.

use Maize\EmailDomainRule\EmailDomainRule;
use Maize\EmailDomainRule\Models\EmailDomain;
use Illuminate\Support\Facades\Validator;

EmailDomain::create(['domain' => '*.example.com']);

Validator::make([
    'email' => '[email protected]',
], [
    'email' => ['string', 'email', new EmailDomainRule],
])->fails(); // returns true as the given domain is not in the list

Validator::make([
    'email' => '[email protected]',
], [
    'email' => ['string', 'email', new EmailDomainRule],
])->fails(); // returns false as the given domain matches the wildcard domain

Model customization

You can also override the default EmailDomain model to add any additional field by changing the email_domain_model setting.

This can be useful when working with a multi-tenancy scenario in a single database system: in this case you can just add a tenant_id column to the migration and model classes, and apply a global scope to the custom model.

use Maize\EmailDomainRule\EmailDomainRule as BaseEmailDomain;
use Illuminate\Database\Eloquent\Builder;

class EmailDomain extends BaseEmailDomain
{
    protected $fillable = [
        'domain',
        'tenant_id',
    ];

    protected static function booted()
    {
        static::addGlobalScope('tenantAware', function (Builder $builder) {
            $builder->where('tenant_id', auth()->user()->tenant_id);
        });
    }
}

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].