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 52 53 54 55 56 57 58 59
| <?php
namespace DD\MyBundle\Listener;
use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
use Symfony\Component\Security\Core\SecurityContext;
use Doctrine\Bundle\DoctrineBundle\Registry as Doctrine; // for Symfony 2.1.0+
// use Symfony\Bundle\DoctrineBundle\Registry as Doctrine; // for Symfony 2.0.x
/**
* Custom login listener.
*/
class LoginListener {
/** @var \Symfony\Component\Security\Core\SecurityContext */
private $securityContext;
/** @var \Doctrine\ORM\EntityManager */
private $em;
/**
* Constructor
*
* @param SecurityContext $securityContext
* @param Doctrine $doctrine
*/
public function __construct(SecurityContext $securityContext, Doctrine $doctrine) {
$this->securityContext = $securityContext;
$this->em = $doctrine->getEntityManager();
}
/**
* Do the magic.
*
* @param InteractiveLoginEvent $event
*/
public function onSecurityInteractiveLogin(InteractiveLoginEvent $event) {
if ($this->securityContext->isGranted('IS_AUTHENTICATED_FULLY')) {
var_dump('IS_AUTHENTICATED_FULLY');
}
if ($this->securityContext->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
var_dump('IS_AUTHENTICATED_REMEMBERED');
}
// do some other magic here
$user = $event->getAuthenticationToken()->getUser();
$classMetadata = $this->em->getClassMetadata('DDMyBundle:SiteElec');
foreach ($classMetadata->getFieldNames() as $num => $fieldname) {
$fieldtype = $classMetadata->getTypeOfField($fieldname);
$tableName = $classMetadata->getTableName();
echo('<pre>');
print_r($classMetadata);die;
}
}
} |
Partager