1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
| //src/Mc/UserBundle/Listener/LoginListener/LoginListener.php
<?php
namespace Mc\UserBundle\Listener;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\Security\Core\SecurityContext;
use Doctrine\Bundle\DoctrineBundle\Registry as Doctrine; // for Symfony 2.1.x
use Symfony\Component\HttpFoundation\Session\Session;
// use Symfony\Bundle\DoctrineBundle\Registry as Doctrine; // for Symfony 2.0.x
/**
* Custom login listener.
*/
class LoginListener
{
/** @var \Symfony\Component\Security\Core\SecurityContext */
private $context;
/** @var \Doctrine\ORM\EntityManager */
private $em;
/**
* Constructor
*
* @param SecurityContext $context
* @param Doctrine $doctrine
*/
public function __construct( SecurityContext $context , Doctrine $doctrine )
{
$this->context = $context;
$this->em = $doctrine->getEntityManager();
}
/**
* Do the magic.
*
* @param Event $event
*/
public function onSecurityInteractiveLogin( Event $event )
{
$user = $this->context->getToken()->getUser();
die('je veux que tu meures ici');
// do all your magic here
}
} |
Partager