src/EventListener/AuthenticationSuccessListener.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\EventListener;
  3. use App\Entity\CustomValue;
  4. use Lexik\Bundle\JWTAuthenticationBundle\Event\AuthenticationSuccessEvent;
  5. use Doctrine\ORM\EntityManager;
  6. class AuthenticationSuccessListener
  7. {
  8.     function __construct(EntityManager $entityManager) {
  9.         $this->entityManager $entityManager;
  10.     }
  11.     /**
  12.      * @param AuthenticationSuccessEvent $event
  13.      */
  14.     public function onAuthenticationSuccessResponse(AuthenticationSuccessEvent $event)
  15.     {
  16.         $data $event->getData();
  17.         $user $event->getUser();
  18.         $surveyUrl $this->entityManager->getRepository(CustomValue::class)->findOneBy(['type' => CustomValue::SURVEY_URL_POST])->getContent();
  19.         $totalPushCountLimit = (int) $this->entityManager->getRepository(CustomValue::class)->findOneBy(['type' => CustomValue::TOTAL_PUSH_COUNT_LIMIT])->getContent();
  20.         $dailyPushCountLimit = (int) $this->entityManager->getRepository(CustomValue::class)->findOneBy(['type' => CustomValue::DAILY_PUSH_COUNT_LIMIT])->getContent();
  21.         $pushHourGap = (int) $this->entityManager->getRepository(CustomValue::class)->findOneBy(['type' => CustomValue::PUSH_HOUR_GAP])->getContent();
  22.         $data['data'] = array(
  23.             'id' => $user->getId(),
  24.             'user_type' => $user->getUserType(),
  25.             'name' => $user->getName(),
  26.             'pre_test_completed' => $user->isPreTestCompleted(),
  27.             'post_test_completed' => $user->isPostTestCompleted(),
  28.             'survey_url' => $surveyUrl,
  29.             'lost_push_hour_gap' => $pushHourGap,
  30.             'lost_push_daily_limit' => $dailyPushCountLimit,
  31.             'lost_push_total_limit' => $totalPushCountLimit,
  32.             'longitude' => $user->getLongitude(),
  33.             'latitude' => $user->getLatitude(),
  34.         );
  35.         $event->setData($data);
  36.     }
  37. }