2022-05-05 21:29:25 +00:00
|
|
|
<?php
|
|
|
|
|
2023-12-30 22:54:25 +00:00
|
|
|
namespace Wallabag\CoreBundle\Event\Listener;
|
2022-05-05 21:29:25 +00:00
|
|
|
|
|
|
|
use FOS\UserBundle\Event\GetResponseUserEvent;
|
|
|
|
use FOS\UserBundle\FOSUserEvents;
|
|
|
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
|
|
|
use Symfony\Component\HttpFoundation\RedirectResponse;
|
|
|
|
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
|
|
|
|
|
|
|
class RegistrationListener implements EventSubscriberInterface
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
private $registrationEnabled;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var UrlGeneratorInterface
|
|
|
|
*/
|
|
|
|
private $urlGenerator;
|
|
|
|
|
|
|
|
public function __construct($registrationEnabled, UrlGeneratorInterface $urlGenerator)
|
|
|
|
{
|
|
|
|
$this->registrationEnabled = $registrationEnabled;
|
|
|
|
$this->urlGenerator = $urlGenerator;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function getSubscribedEvents()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
FOSUserEvents::REGISTRATION_INITIALIZE => 'onRegistrationInitialize',
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function onRegistrationInitialize(GetResponseUserEvent $event)
|
|
|
|
{
|
|
|
|
if ($this->registrationEnabled) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$event->setResponse(new RedirectResponse($this->urlGenerator->generate('fos_user_security_login'), 301));
|
|
|
|
}
|
|
|
|
}
|