src/EventListener/PostEmailVerificationSubscriber.php line 36

Open in your IDE?
  1. <?php
  2. namespace BitBag\OpenMarketplace\EventListener;
  3. use Sylius\Component\Resource\ResourceActions;
  4. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  5. use Sylius\Bundle\UserBundle\UserEvents;
  6. use Sylius\Component\User\Model\UserInterface;
  7. use Symfony\Component\EventDispatcher\GenericEvent;
  8. use Symfony\Component\HttpClient\HttpClient;
  9. use Psr\Log\LoggerInterface;
  10. use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
  11. class PostEmailVerificationSubscriber implements EventSubscriberInterface
  12. {
  13.     private $logger;
  14.     private $tokenStorage;
  15.     public function __construct(LoggerInterface $loggerTokenStorageInterface $tokenStorage)
  16.     {
  17.         $this->logger $logger;
  18.         $this->tokenStorage $tokenStorage;
  19.     }
  20.     public static function getSubscribedEvents()
  21.     {
  22.         return [
  23.             ResourceActions::UPDATE => 'preEmailVerification',
  24.             UserEvents::POST_EMAIL_VERIFICATION => 'postEmailVerification',
  25.         ];
  26.     }
  27.     public function preEmailVerification(GenericEvent $event)
  28.     {
  29.     }
  30.     public function postEmailVerification(GenericEvent $event)
  31.     {
  32.         $urlbase 'https://back.enimad.com/';
  33.         $token=$_ENV['TOKEN_ENILEADS'];
  34.         $sequence=$_ENV['SEQUENCE_ONBOARDING'];
  35.         $date = new \DateTime();
  36.         $formattedDate $date->format('Y-m-d');
  37.         // Si $PR=$_COOKIE['PR']; exisite alors on récupère la valeur de la variable
  38.         if (isset($_COOKIE['PR'])) {
  39.             $PR $_COOKIE['PR'];
  40.         } else {
  41.             $PR '0';
  42.         }
  43.         $user $event->getSubject();
  44.         $mail $user->getEmail();
  45.         $customer $user->getCustomer();
  46.         $ValueFinal=array(array('date-activation',$formattedDate));
  47.         $client HttpClient::create();
  48.         // Récupération de l'ID du lead
  49.         $url_getID $urlbase.'rest/lead/Check_mail/'.$mail.'?token='.$token;
  50.         $response $client->request('GET'$url_getID);
  51.         $data $response->toArray();
  52.         $id_lead $data['reponse'];
  53.         $url $urlbase.'rest/lead/'.$id_lead.'/update_data?token='.$token.'&data='urlencode(json_encode($ValueFinal));
  54.         $response $client->request('GET'$url);
  55.         // Ajout du tag
  56. //                dd($Tags);
  57.         $Tags 'validation';
  58.         $url_addTag $urlbase.'rest/lead/'.$id_lead.'/addTag?token='.$token.'&tag='.$Tags;
  59.         $response $client->request('GET'$url_addTag);
  60.         $Tags2 'newsletter';
  61.         $url_addTag2 $urlbase.'rest/lead/'.$id_lead.'/addTag?token='.$token.'&tag='.$Tags2;
  62.         $response $client->request('GET'$url_addTag2);
  63.         // Actions to perform after email verification
  64.     }
  65. }