ipnoz/active-session-bundle

此Symfony扩展包提供了控制和限制用户会话的工具

安装: 35

依赖: 0

建议: 0

安全: 0

星标: 0

分支: 0

类型:symfony-bundle

v2.0.1 2023-02-03 20:48 UTC

This package is auto-updated.

Last update: 2024-09-06 01:01:44 UTC


README

此Symfony扩展包提供了控制和限制用户会话的工具

要求

php >= 7.1
Symfony 3.4

安装

1. 需求此包

composer require ipnoz/active-session-bundle

2. 创建ActiveSession实体

use Ipnoz\ActiveSessionBundle\Entity\ActiveSession;

/**
 * @ORM\Table()
 * @ORM\Entity(repositoryClass="App\Repository\ActiveSessionRepository")
 */
class ActiveSession extends BaseActiveSession
{
     /**
      * @var integer
      *
      * @ORM\Column(type="integer")
      * @ORM\Id
      * @ORM\GeneratedValue(strategy="AUTO")
      */
      private $id;
    
      public function getId(): ?int
      {
           return $this->id;
      }
}

3. 并创建仓库

use Ipnoz\ActiveSessionBundle\Repository\ActiveSessionRepository as BaseActiveSessionRepository;

class ActiveSessionRepository extends BaseActiveSessionRepository
{
}

4. 设置配置

ipnoz_active_session:

    # Set the maximum of active sessions one user can cumulate
    max_session:          5 # Default

    # Add a delay in day before block a session wich reached the max session limit
    block_delay:          0 # Default

    # The class name of the app user
    user_class:           App\Entity\User # Required

    # The class name of the active session
    active_session_class: App\Entity\ActiveSession # Required

    cookie_name:          ipnoz-active-session # Default

    # List of route name or controller name to exclude of the control
    excluded:             []

    command:
        deactivate_olds_in_days: 14 # Default

5. 在app/Kernel.php中启用此扩展包

new \Ipnoz\ActiveSessionBundle\IpnozActiveSessionBundle()

6. 更新数据库,以便扩展包可以使用Doctrine持久化实体

bin/console doctrine:schema:update --force

事件

ipnoz_active_session.event.access_blocked
ipnoz_active_session.event.session_created
ipnoz_active_session.event.limit_reached

控制台

路径
tests/_support/TestsApp/bin/console
停用旧的活跃会话
tests/_support/TestsApp/bin/console ipnoz:active-session:deactivate-olds

测试设置

vendor/bin/codecept build

tests/_support/TestsApp/bin/console doctrine:database:create
tests/_support/TestsApp/bin/console doctrine:schema:update --complete --force

运行测试

vendor/bin/codecept run