<?php
namespace App\AdminBundle\EventListener;
use App\AdminBundle\Service\UserManager;
use App\AdminBundle\Entity\User;
use Lexik\Bundle\JWTAuthenticationBundle\Event\AuthenticationSuccessEvent;
class AuthenticationSuccessListener
{
private $userManager;
public function __construct(UserManager $userManager)
{
$this->userManager = $userManager;
}
/**
* @param AuthenticationSuccessEvent $event
*/
public function onAuthenticationSuccessResponse(AuthenticationSuccessEvent $event)
{
$data = $event->getData();
$user = $event->getUser();
if (!$user instanceof User) {
return;
}
// Reset failed login attemps
if ($user->getFailedLoginAttemps() > 0) {
$user->setFailedLoginAttemps(0);
$this->userManager->updateUser($user);
}
// Get the user init info from the user manager and set it in the event
$data['data'] = $this->userManager->getUserAndHouseholdInitInfo();
$event->setData($data);
// Remove not used anymore PHP session data from server
session_destroy();
}
}