src/AdminBundle/EventListener/AuthenticationFailureListener.php line 26

Open in your IDE?
  1. <?php
  2. namespace App\AdminBundle\EventListener;
  3. use App\AdminBundle\Service\UserManager;
  4. use Lexik\Bundle\JWTAuthenticationBundle\Event\AuthenticationFailureEvent;
  5. use Symfony\Component\HttpFoundation\RequestStack;
  6. class AuthenticationFailureListener
  7. {
  8.     //private $requestStack;
  9.     //private $userManager;
  10.     //private $templating;
  11.     public function __construct(/*RequestStack $requestStack, UserManager $userManager, $templating*/)
  12.     {
  13.         //$this->requestStack = $requestStack;
  14.         //$this->userManager = $userManager;
  15.         //$this->templating = $templating;
  16.     }
  17.     /**
  18.      * @param AuthenticationFailureEvent $event
  19.      */
  20.     public function onAuthenticationFailureResponse(AuthenticationFailureEvent $event)
  21.     {
  22.         // Check failed login attemps
  23.         //$username = $this->requestStack->getCurrentRequest()->get("_username");
  24.         //if ($username !== '') {
  25.         //    $user = $this->userManager->findUserByEmail($username);
  26.         //    if ($user) {
  27.         //        $failedAttemps = $user->getFailedLoginAttemps() + 1;
  28.         //        $user->setFailedLoginAttemps($failedAttemps);
  29.         //        $this->userManager->updateUser($user);
  30.         //        if ($failedAttemps == 3) {
  31.         //            $parameters = array(
  32.         //                'firstName' => $user->getFirstName(),
  33.         //                'email' => $user->getEmail()
  34.         //            );
  35.         //            $html = $this->templating->render(
  36.         //                'Emails/failed_login_attemps.html.twig', $parameters
  37.         //            );
  38.         //
  39.         //            DEV NOTE: if re-enabling replace with AWS SES call
  40.         //            $message = new Swift_Message();
  41.         //            $message
  42.         //                ->setFrom('info@iwplatform.com', 'Integrated Wealth Platform')
  43.         //                ->addTo($user->getEmail(), $user->getFirstName())
  44.         //                ->setSubject('Incorrect Login Attempts')
  45.         //                ->setReplyTo('support@iwplatform.com')
  46.         //                ->setBccAddress('info@iwplatform.com')
  47.         //                ->setBody($html, 'text/html')
  48.         //            ;
  49.         //
  50.         //            // Send the email
  51.         //            ...
  52.         //        }
  53.         //    }
  54.         //}
  55.         // Delay the response as to make it take 1 second
  56.         // This is to even the response time no matter which route it took (user not found, wrong password, etc.), so it can't be used to pick information about username existance
  57.         $soFarExecutionTime microtime(true) - $_SERVER["REQUEST_TIME_FLOAT"];
  58.         usleep(abs($soFarExecutionTime) * 1000000);
  59.     }
  60. }