src/Lci/UserBundle/Listeners/detectLoginListener.php line 24

Open in your IDE?
  1. <?php
  2. // srv/www/htdocs/Symfony/src/Lci/UserBundle/Listener/detectLoginListener.php
  3. namespace Lci\UserBundle\Listeners;
  4. use Symfony\Component\Security\Core\Event\AuthenticationEvent;
  5. use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
  6. use Symfony\Component\HttpFoundation\Session\Session;
  7. class detectLoginListener {
  8.     // Login à capturer
  9.     protected $detectLogin;
  10.     protected $dateConnexion;
  11.     protected $session;
  12.     protected $serviceLog;
  13.     public function __construct(detectLogin $detectLoginSession $session$serviceLog) {
  14.         $this->detectLogin $detectLogin;
  15.         $this->session $session;
  16.         $date = new \Datetime();
  17.         $this->dateConnexion $date->format('d-m-Y à H:i:s');
  18.         $this->serviceLog $serviceLog;
  19.     }
  20.     public function successLogin(InteractiveLoginEvent $event) {
  21.         // Pour debug : Affiche toutes les variables de serveur dans le fichier connexions.log
  22.         /*
  23.         foreach($_SERVER as $key => $value) {
  24.             $this->serviceLog->setLog($key." = ".$value,'connexions.log');
  25.         }
  26.         */
  27.         if (preg_match('/login_check$/i',$_SERVER['REQUEST_URI'])) {
  28.             $token $event->getAuthenticationToken();
  29.             // Modification des informations et log de la connexion
  30.             $this->detectLogin->enregistreConnexion('SUCCESS'$this->dateConnexion$token$this->session);
  31.             $this->detectLogin->verif_totp_key($this->session$token->getUser());
  32.         }
  33.     }
  34.     public function failedLogin(AuthenticationEvent $event) {
  35.         if (preg_match('/login_check$/i',$_SERVER['REQUEST_URI'])) {
  36.             $token $event->getAuthenticationException();
  37.             $this->detectLogin->enregistreConnexion('FAILED'$this->dateConnexion$token$this->session);
  38.         }
  39.     }
  40. }