<?php
declare(strict_types=1);
namespace Harmonizely\EventSubscriber;
use FOS\UserBundle\Event\GetResponseUserEvent;
use FOS\UserBundle\FOSUserEvents;
use Harmonizely\Model\User;
use Harmonizely\Service\RegistrationAbuse\MassRegistrationDetector;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* Triggers the mass-registration-from-single-IP check once a registration is
* confirmed.
*
* Runs with a negative priority so it fires after
* {@see AcceptTermsOnRegistrationSubscriber} has persisted the terms row that
* carries the IP address, ensuring the just-registered user is counted.
*/
final class DetectMassRegistrationSubscriber implements EventSubscriberInterface
{
private MassRegistrationDetector $detector;
public function __construct(MassRegistrationDetector $detector)
{
$this->detector = $detector;
}
public static function getSubscribedEvents(): array
{
return [
FOSUserEvents::REGISTRATION_CONFIRM => ['onRegistrationConfirm', -100],
];
}
public function onRegistrationConfirm(GetResponseUserEvent $event): void
{
if (!$event->getUser() instanceof User) {
return;
}
$this->detector->check($event->getRequest()->getClientIp());
}
}