cethyworks/invitation-bundle

提供了一种在特殊的“仅邀请码”安全防火墙后面保护路由的方法。

安装: 205

依赖项: 0

建议者: 0

安全: 0

星星: 2

关注者: 2

分支: 0

开放问题: 0

类型:symfony-bundle

v1.0 2017-07-21 15:34 UTC

This package is not auto-updated.

Last update: 2024-09-21 15:07:48 UTC


README

提供了一种在特殊的 "仅邀请码" 安全防火墙后面保护路由的方法。

CircleCI

安装

1. 使用Composer require

$ composer require cethyworks/invitation-bundle 

2. 注册包

// AppKernel.php
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = [
            // ...
            new Cethyworks\InvitationBundle\CethyworksInvitationBundle(),
        ];
        // ...

如何使用

内存中的邀请码

1. 更新 security.yml 以添加邀请提供者、邀请和防火墙

security:
    # ...
    providers:
        in_memory_invitation_provider:
            invitation_memory:
                invitations:
                    - { code: foo }
                    - { code: bar }
    # ...
    firewalls:
        # ...            
        invitation:
            pattern: ^/invite-only-url
            provider: in_memory_invitation_provider
            guard:
                authenticator:
                    cethyworks_invitation.authenticator
            anonymous: false
        # ...

4. 前往 /invite-only-url?code=foo。就这样。

使用内存提供者中的电子邮件

1. 更新 config.yml

cethyworks_invitation:
    invitation_class: Cethyworks\InvitationBundle\Model\Invitation

2. 更新 security.yml

security:
        # ...
        providers:
            in_memory_invitation_provider:
                invitation_memory:
                    invitations:
                        - { code: foo, email: foo@email.foo }
                        - { code: bar, email: bar@email.bar }
        # ...

数据库中的邀请码

1. 扩展 Cethyworks\InvitationBundle\Model\Invitation 以持久化它

<?php
namespace AppBundle\Entity;

use Cethyworks\InvitationBundle\Model\GenerateCodeTrait;
use Cethyworks\InvitationBundle\Model\Invitation as BaseInvitation;
use Doctrine\ORM\Mapping as ORM;

/**
 * Invitation
 *
 * @ORM\Table()
 * @ORM\Entity()
 */
class Invitation extends BaseInvitation
{
    // optional, provides a shortcut to generate random code
    use GenerateCodeTrait;
    
    /**
     * @var int
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;
    
    /**
     * Invitation constructor.
     */
    public function __construct()
    {
        $this->generateCode();
    }
}

2. 使用新的 Invitation 类更新 config.yml

cethyworks_invitation:
    invitation_class: AppBundle\Entity\Invitation

3. 更新 security.yml 以添加邀请提供者和防火墙

security:
    # ...
    providers:
        cethyworks_invitation_entity_provider:
            invitation_entity: ~
                # entity_property: 'code'
                # repository_method: 'findOneBy'
                # manager_name: null
    # ...
    firewalls:
        # ...            
        invitation:
            pattern: ^/invite-only-url
            provider: cethyworks_invitation_entity_provider
            guard:
                authenticator:
                    cethyworks_invitation.authenticator
            anonymous: false
        # ...

4. 前往 /invite-only-url?code=some_code。就这样。

待办事项

  • 处理失败(重定向?)
  • 展示仓库
  • 插件
    • 将邀请与用户关联
    • 手动设置邀请码的表单
    • 可消费的
    • 发送邀请