<?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\SpamValidationScheduler;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* Schedules the delayed spam re-check as soon as a registration is confirmed.
*
* Until now the check was only scheduled from content-save paths (profile edit,
* organization update, cancellation policy, event types, …). A spammer whose
* banned content lives entirely in the registration data (e.g. an email like
* "juliaju.test+cryptocurrency@gmail.com") therefore stayed unblocked until they
* happened to save something in account settings. Scheduling here mirrors
* {@see EditProfileSubscriber} so every fresh account is screened automatically.
*
* All registration variants (email/password, OAuth, API verification code)
* converge on FOSUserEvents::REGISTRATION_CONFIRM, so this single hook covers
* them all.
*/
final class ValidateUserSpamOnRegistrationSubscriber implements EventSubscriberInterface
{
private SpamValidationScheduler $spamValidationScheduler;
public function __construct(SpamValidationScheduler $spamValidationScheduler)
{
$this->spamValidationScheduler = $spamValidationScheduler;
}
public static function getSubscribedEvents(): array
{
return [
FOSUserEvents::REGISTRATION_CONFIRM => ['onRegistrationConfirm', -100],
];
}
public function onRegistrationConfirm(GetResponseUserEvent $event): void
{
$user = $event->getUser();
if (!$user instanceof User) {
return;
}
$this->spamValidationScheduler->schedule($user->getId());
}
}