ipnoz / active-session-bundle
This Symfony bundle provides tools to control and limit user sessions
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: 2025-03-06 02:07:21 UTC
README
This Symfony bundle provides tools to control and limit user sessions
Requirements
php >= 7.1
Symfony 3.4
Installation
1. Require the package
composer require ipnoz/active-session-bundle
2. Create ActiveSession entity
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. And create repository
use Ipnoz\ActiveSessionBundle\Repository\ActiveSessionRepository as BaseActiveSessionRepository;
class ActiveSessionRepository extends BaseActiveSessionRepository
{
}
4. Set configuration
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. Enable the bundle in app/Kernel.php
new \Ipnoz\ActiveSessionBundle\IpnozActiveSessionBundle()
6. Update the database so bundle can persist entities using Doctrine
bin/console doctrine:schema:update --force
Events
ipnoz_active_session.event.access_blocked
ipnoz_active_session.event.session_created
ipnoz_active_session.event.limit_reached
Console
path
tests/_support/TestsApp/bin/console
Deactivate old active sessions
tests/_support/TestsApp/bin/console ipnoz:active-session:deactivate-olds
Tests setup
vendor/bin/codecept build
tests/_support/TestsApp/bin/console doctrine:database:create
tests/_support/TestsApp/bin/console doctrine:schema:update --complete --force
Run tests
vendor/bin/codecept run