<?php
namespace App\EventListener;
use App\Entity\CustomValue;
use Lexik\Bundle\JWTAuthenticationBundle\Event\AuthenticationSuccessEvent;
use Doctrine\ORM\EntityManager;
class AuthenticationSuccessListener
{
function __construct(EntityManager $entityManager) {
$this->entityManager = $entityManager;
}
/**
* @param AuthenticationSuccessEvent $event
*/
public function onAuthenticationSuccessResponse(AuthenticationSuccessEvent $event)
{
$data = $event->getData();
$user = $event->getUser();
$surveyUrl = $this->entityManager->getRepository(CustomValue::class)->findOneBy(['type' => CustomValue::SURVEY_URL_POST])->getContent();
$totalPushCountLimit = (int) $this->entityManager->getRepository(CustomValue::class)->findOneBy(['type' => CustomValue::TOTAL_PUSH_COUNT_LIMIT])->getContent();
$dailyPushCountLimit = (int) $this->entityManager->getRepository(CustomValue::class)->findOneBy(['type' => CustomValue::DAILY_PUSH_COUNT_LIMIT])->getContent();
$pushHourGap = (int) $this->entityManager->getRepository(CustomValue::class)->findOneBy(['type' => CustomValue::PUSH_HOUR_GAP])->getContent();
$data['data'] = array(
'id' => $user->getId(),
'user_type' => $user->getUserType(),
'name' => $user->getName(),
'pre_test_completed' => $user->isPreTestCompleted(),
'post_test_completed' => $user->isPostTestCompleted(),
'survey_url' => $surveyUrl,
'lost_push_hour_gap' => $pushHourGap,
'lost_push_daily_limit' => $dailyPushCountLimit,
'lost_push_total_limit' => $totalPushCountLimit,
'longitude' => $user->getLongitude(),
'latitude' => $user->getLatitude(),
);
$event->setData($data);
}
}