All Projects → clarkeash → Doorman

clarkeash / Doorman

Licence: mit
Limit access to your Laravel applications by using invite codes

Projects that are alternatives of or similar to Doorman

Orm
A drop-in Doctrine ORM 2 implementation for Laravel 5+ and Lumen
Stars: ✭ 712 (-22.02%)
Mutual labels:  laravel, laravel-package
Laravel Blade Directives
A collection of nice Laravel Blade directives
Stars: ✭ 813 (-10.95%)
Mutual labels:  laravel, laravel-package
Laravel User Verification
PHP package built for Laravel 5.* to easily handle a user email verification and validate the email
Stars: ✭ 755 (-17.31%)
Mutual labels:  laravel, laravel-package
Chatify
A Laravel package that allows you to add a complete user messaging system into your new/existing Laravel application.
Stars: ✭ 885 (-3.07%)
Mutual labels:  laravel, laravel-package
Eloquent Ldap
A Laravel 5.1 package that first tries to log the user against the internal database if that fails, it tries against the configured LDAP/AD server.
Stars: ✭ 19 (-97.92%)
Mutual labels:  laravel, laravel-package
Sweet Alert
A BEAUTIFUL, RESPONSIVE, CUSTOMIZABLE, ACCESSIBLE (WAI-ARIA) REPLACEMENT FOR JAVASCRIPT'S POPUP BOXES FOR LARAVEL
Stars: ✭ 696 (-23.77%)
Mutual labels:  laravel, laravel-package
Laravel Notify
Flexible Flash notifications for Laravel
Stars: ✭ 787 (-13.8%)
Mutual labels:  laravel, laravel-package
Laravel Options
Global key-value store in the database
Stars: ✭ 626 (-31.43%)
Mutual labels:  laravel, laravel-package
Simple Cache
An easy to use Caching trait for Laravel's Eloquent Models.
Stars: ✭ 19 (-97.92%)
Mutual labels:  laravel, laravel-package
Laravel Log
Simple API to write logs for Laravel.
Stars: ✭ 19 (-97.92%)
Mutual labels:  laravel, laravel-package
Laravel Heyman
Declarative style of authorization and validation in laravel.
Stars: ✭ 677 (-25.85%)
Mutual labels:  laravel, laravel-package
Blade Migrations Laravel
An intelligent alternative version of Laravel 5/6 Database Migrations - uses raw-sql syntax, transactions, auto-rollback, UP-DOWN-UP testing
Stars: ✭ 25 (-97.26%)
Mutual labels:  laravel, laravel-package
Laravel Open Source Projects
A Web Artisan list of categorized OPEN SOURCE PROJECTS built with Laravel PHP Framework.
Stars: ✭ 676 (-25.96%)
Mutual labels:  laravel, laravel-package
Chat
A Laravel chat package. You can use this package to create a chat/messaging Laravel application.
Stars: ✭ 710 (-22.23%)
Mutual labels:  laravel, laravel-package
Laravel Shopify
A full-featured Laravel package for aiding in Shopify App development
Stars: ✭ 634 (-30.56%)
Mutual labels:  laravel, laravel-package
Twitter
Twitter API for Laravel 5.5+, 6.x, 7.x & 8.x
Stars: ✭ 755 (-17.31%)
Mutual labels:  laravel, laravel-package
Snooze
A package to simplify automating future notifications and reminders in Laravel
Stars: ✭ 515 (-43.59%)
Mutual labels:  laravel, laravel-package
Laravel Visits
📊 Laravel Visits is a counter that can be attached to any model to track its visits using Redis or Eloquent. (with tags, IP protection and caching)
Stars: ✭ 582 (-36.25%)
Mutual labels:  laravel, laravel-package
Package Skeleton
📦 My base for PHP packages.
Stars: ✭ 6 (-99.34%)
Mutual labels:  laravel, laravel-package
Laravel Aws Sns
Laravel package for the AWS SNS Events
Stars: ✭ 24 (-97.37%)
Mutual labels:  laravel, laravel-package

Doorman

GitHub Workflow Status GitHub release (latest SemVer)

Doorman provides a way to limit access to your Laravel applications by using invite codes.

Invite Codes:

  • Can be tied to a specific email address.
  • Can be available to anyone (great for sharing on social media).
  • Can have a limited number of uses or unlimited.
  • Can have an expiry date, or never expire.

Laravel Support

Laravel Doorman
5.x 3.x
6.x 4.x
7.x 5.x
8.x 6.x

Installation

You can pull in the package using composer:

$ composer require "clarkeash/doorman=^6.0"

Next, migrate the database:

$ php artisan migrate

Usage

Generate Invites

Make a single generic invite code with 1 redemption, and no expiry.

Doorman::generate()->make();

Make 5 generic invite codes with 1 redemption each, and no expiry.

Doorman::generate()->times(5)->make();

Make an invite with 10 redemptions and no expiry.

Doorman::generate()->uses(10)->make();

Make an invite with unlimited redemptions and no expiry.

Doorman::generate()->unlimited()->make();

Make an invite that expires on a specific date.

$date = Carbon::now('UTC')->addDays(7);
Doorman::generate()->expiresOn($date)->make();

Make an invite that expires in 14 days.

Doorman::generate()->expiresIn(14)->make();

Make an invite for a specific person.

Doorman::generate()->for('[email protected]')->make();

Alternatively instead of calling make() which will return a collection of invites you can call once() if you only want a single invite generated.

$invite = Doorman::generate()->for('[email protected]')->once();
dd($invite->code);

Redeem Invites

You can redeem an invite by calling the redeem method. Providing the invite code and optionally an email address.

Doorman::redeem('ABCDE');
// or
Doorman::redeem('ABCDE', '[email protected]');

If doorman is able to redeem the invite code it will increment the number of redemptions by 1, otherwise it will throw an exception.

  • InvalidInviteCode is thrown if the code does not exist in the database.
  • ExpiredInviteCode is thrown if an expiry date is set and it is in the past.
  • MaxUsesReached is thrown if the invite code has already been used the maximum number of times.
  • NotYourInviteCode is thrown if the email address for the invite does match the one provided during redemption, or one was not provided during redemption.

All of the above exceptions extend DoormanException so you can catch that exception if your application does not need to do anything specific for the above exceptions.

try {
    Doorman::redeem(request()->get('code'), request()->get('email'));
} catch (DoormanException $e) {
    return response()->json(['error' => $e->getMessage()], 422);
}

Check Invites without redeeming them

You can check an invite by calling the check method. Providing the invite code and optionally an email address. (It has the same signature as the redeem method except it will return true or false instead of throwing an exception.

Doorman::check('ABCDE');
// or
Doorman::check('ABCDE', '[email protected]');

Change Error Messages (and translation support)

In order to change the error message returned from doorman, we need to publish the language files like so:

$ php artisan vendor:publish --tag=doorman-translations

The language files will then be in /resources/lang/vendor/doorman/en where you can edit the messages.php file, and these messages will be used by doorman. You can create support for other languages by creating extra folders with a messages.php file in the /resources/lang/vendor/doorman directory such as de where you could place your German translations. Read the localisation docs for more info.

Validation

If you would perfer to validate an invite code before you attempt to redeem it or you are using Form Requests then you can validate it like so:

public function store(Request $request)
{
    $this->validate($request, [
        'email' => 'required|email|unique:users',
        'code' => ['required', new DoormanRule($request->get('email'))],
    ]);

    // Add the user to the database.
}

You should pass the email address into the constructor to validate the code against that email. If you know the code can be used with any email, then you can leave the parameter empty.

Config - change table name

First publish the package configuration:

$ php artisan vendor:publish --tag=doorman-config

In config/doorman.php you will see:

return [
    'invite_table_name' => 'invites',
];

If you change the table name and then run your migrations Doorman will then use the new table name.

Console

To remove used and expired invites you can use the cleanup command:

$ php artisan doorman:cleanup
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].