ipnoz / active-session-bundle
此Symfony扩展包提供了控制和限制用户会话的工具
v2.0.1
2023-02-03 20:48 UTC
Requires
- php: >=8.1
- doctrine/annotations: ^1.0
- symfony/dependency-injection: >=6.2
- symfony/event-dispatcher: >=6.2
- symfony/framework-bundle: >=6.2
- symfony/runtime: ^6.2
- symfony/security-bundle: >=6.2
- symfony/twig-bundle: >=6.2
Requires (Dev)
- codeception/codeception: >=4.1
- codeception/module-asserts: >=1.0.0
- codeception/module-doctrine2: >=1.1
- codeception/module-phpbrowser: >=1.0.0
- codeception/module-symfony: >=1.5
- doctrine/doctrine-bundle: >=1.0
- doctrine/orm: >=2.7
- symfony/config: >=6.2
- symfony/console: >=6.2
- symfony/debug-bundle: >=6.2
- symfony/finder: >=6.2
- symfony/http-foundation: >=6.2
- symfony/property-access: >=6.2
- symfony/routing: >=6.2
- symfony/twig-bridge: >=6.2
Suggests
- symfony/console: Needed to be able to use commands
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