src/EventSubscriber/ValidateUserSpamOnRegistrationSubscriber.php line 43

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\SpamValidationScheduler;
  8. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  9. /**
  10.  * Schedules the delayed spam re-check as soon as a registration is confirmed.
  11.  *
  12.  * Until now the check was only scheduled from content-save paths (profile edit,
  13.  * organization update, cancellation policy, event types, …). A spammer whose
  14.  * banned content lives entirely in the registration data (e.g. an email like
  15.  * "juliaju.test+cryptocurrency@gmail.com") therefore stayed unblocked until they
  16.  * happened to save something in account settings. Scheduling here mirrors
  17.  * {@see EditProfileSubscriber} so every fresh account is screened automatically.
  18.  *
  19.  * All registration variants (email/password, OAuth, API verification code)
  20.  * converge on FOSUserEvents::REGISTRATION_CONFIRM, so this single hook covers
  21.  * them all.
  22.  */
  23. final class ValidateUserSpamOnRegistrationSubscriber implements EventSubscriberInterface
  24. {
  25.     private SpamValidationScheduler $spamValidationScheduler;
  26.     public function __construct(SpamValidationScheduler $spamValidationScheduler)
  27.     {
  28.         $this->spamValidationScheduler $spamValidationScheduler;
  29.     }
  30.     public static function getSubscribedEvents(): array
  31.     {
  32.         return [
  33.             FOSUserEvents::REGISTRATION_CONFIRM => ['onRegistrationConfirm', -100],
  34.         ];
  35.     }
  36.     public function onRegistrationConfirm(GetResponseUserEvent $event): void
  37.     {
  38.         $user $event->getUser();
  39.         if (!$user instanceof User) {
  40.             return;
  41.         }
  42.         $this->spamValidationScheduler->schedule($user->getId());
  43.     }
  44. }