承接 clarkeash/doorman 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

clarkeash/doorman

Composer 安装命令:

composer require clarkeash/doorman

包简介

README 文档

README

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
9.x 7.x
10.x 8.x
11.x 9.x
12.x 10.x

Installation

You can pull in the package using composer:

composer require "clarkeash/doorman=^10.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('me@ashleyclarke.me')->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('me@ashleyclarke.me')->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', 'me@ashleyclarke.me');

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', 'me@ashleyclarke.me');

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

Cleanup

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

php artisan doorman:cleanup

Create a new invite

You can create a new invite from the command line using the make command:

php artisan doorman:make
php artisan doorman:make --uses=5 --expiry=2025-12-31 --email=me@ashleyclarke.me
php artisan doorman:make --unlimited

clarkeash/doorman 适用场景与选型建议

clarkeash/doorman 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 127.26k 次下载、GitHub Stars 达 1.04k, 最近一次更新时间为 2017 年 04 月 08 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 clarkeash/doorman 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 clarkeash/doorman 我们能提供哪些服务?
定制开发 / 二次开发

基于 clarkeash/doorman 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 1042
  • Watchers: 15
  • Forks: 46
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-04-08