src/EventListener/LoginFailureListener.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\EventListener;
  3. use Symfony\Component\Security\Http\Event\LoginFailureEvent;
  4. use App\Services\Security\IpTools;
  5. class LoginFailureListener
  6. {
  7.     public function __construct(IpTools $ipTools)
  8.     {
  9.         $this->ipTools $ipTools;
  10.     }
  11.     public function onLoginFailure(LoginFailureEvent $event)
  12.     {
  13.         // Get username in the request event
  14.         $username null;
  15.         if ($event->getRequest() !== null)
  16.         {
  17.             $username $event->getRequest()->request->get('_username');
  18.         }
  19.         // Fail2ban
  20.         $this->ipTools->fail2ban(array('username' => $username));
  21.     }
  22. }