src/Bundle/Croatia/EventSubscriber/UserEventsSubscriber.php line 44

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace App\Bundle\Croatia\EventSubscriber;
  3. use App\Contracts\HttpFoundation\RequestInfoInterface;
  4. use App\Event\UserPasswordResetedEvent;
  5. use App\Event\UserRegisteredEvent;
  6. use Psr\Log\LoggerInterface;
  7. use GuzzleHttp\Client;
  8. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  9. use App\Helper\UserHelper;
  10. class UserEventsSubscriber implements EventSubscriberInterface
  11. {
  12.     /**
  13.      * @var Client
  14.      */
  15.     private $neturalClient;
  16.     /** @var RequestInfoInterface */
  17.     private $requestInfo;
  18.     /** @var UserHelper */
  19.     protected $userHelper;
  20.     public function __construct(Client $neturalClientRequestInfoInterface $requestInfoUserHelper $userHelper)
  21.     {
  22.         $this->neturalClient $neturalClient;
  23.         $this->requestInfo $requestInfo;
  24.         $this->userHelper $userHelper;
  25.     }
  26.     /**
  27.      * @inheritDoc
  28.      */
  29.     public static function getSubscribedEvents()
  30.     {
  31.         return [
  32.             UserRegisteredEvent::class => 'onUserRegistered',
  33.             UserPasswordResetedEvent::class => 'onUserPasswordReseted',
  34.         ];
  35.     }
  36.     public function onUserPasswordReseted(UserPasswordResetedEvent $event)
  37.     {
  38.         $user $event->getUser();
  39.         $this->neturalClient->post('/restV/sendform/passwordReset', [
  40.             'body' => json_encode([
  41.                 'link' => sprintf(
  42.                     '%s/user/passwort-aendern/?memberid=%s&hash=%s',
  43.                     getenv('MAIL_PASSWORD_ACTIVATION_URL'),
  44.                     $user->getMemberId(),
  45.                     $event->getResetCode()
  46.                 ),
  47.                 'forename' => $user->getFirstName(),
  48.                 'surname' => $user->getLastName(),
  49.                 'nickname' => $user->getUsername(),
  50.                 'to' => $user->getEmail(),
  51.                 'locale' => $this->requestInfo->getMasterRequest()->getLocale(),
  52.                 'country' => getenv('APP_COUNTRY')
  53.             ])
  54.         ]);
  55.     }
  56.     public function onUserRegistered(UserRegisteredEvent $event)
  57.     {
  58.         $user $event->getUser();
  59.         $activationLink sprintf(
  60.             '%s/user/register/finish/?memberid=%s&code=%s&userId=%s',
  61.             getenv('MAIL_PASSWORD_ACTIVATION_URL'),
  62.             $user->getMemberId(),
  63.             $event->getActivationCode(),
  64.             $user->getMemberId()
  65.         );
  66.         if ($user->getAppleUserId()) {
  67.             // automatically activate user, if apple id is given
  68.             $this->userHelper->activateAppleUser($user->getMemberId());
  69.             // $this->neturalClient->request('GET', $activationLink);
  70.         } else {
  71.             $this->neturalClient->post('/restV/sendform/registration', [
  72.                 'body' => json_encode([
  73.                     'link' => $activationLink,
  74.                     'refId' => $user->getMemberId(),
  75.                     'forename' => $user->getFirstName(),
  76.                     'surname' => $user->getLastName(),
  77.                     'nickname' => $user->getUsername(),
  78.                     'to' => $user->getEmail(),
  79.                     'locale' => $this->requestInfo->getMasterRequest()->getLocale(),
  80.                     'country' => getenv('APP_COUNTRY')
  81.                 ])
  82.             ]);
  83.         }
  84.     }
  85. }