src/EventSubscriber/DetectMassRegistrationSubscriber.php line 37

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Harmonizely\EventSubscriber;
  4. use FOS\UserBundle\Event\GetResponseUserEvent;
  5. use FOS\UserBundle\FOSUserEvents;
  6. use Harmonizely\Model\User;
  7. use Harmonizely\Service\RegistrationAbuse\MassRegistrationDetector;
  8. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  9. /**
  10.  * Triggers the mass-registration-from-single-IP check once a registration is
  11.  * confirmed.
  12.  *
  13.  * Runs with a negative priority so it fires after
  14.  * {@see AcceptTermsOnRegistrationSubscriber} has persisted the terms row that
  15.  * carries the IP address, ensuring the just-registered user is counted.
  16.  */
  17. final class DetectMassRegistrationSubscriber implements EventSubscriberInterface
  18. {
  19.     private MassRegistrationDetector $detector;
  20.     public function __construct(MassRegistrationDetector $detector)
  21.     {
  22.         $this->detector $detector;
  23.     }
  24.     public static function getSubscribedEvents(): array
  25.     {
  26.         return [
  27.             FOSUserEvents::REGISTRATION_CONFIRM => ['onRegistrationConfirm', -100],
  28.         ];
  29.     }
  30.     public function onRegistrationConfirm(GetResponseUserEvent $event): void
  31.     {
  32.         if (!$event->getUser() instanceof User) {
  33.             return;
  34.         }
  35.         $this->detector->check($event->getRequest()->getClientIp());
  36.     }
  37. }