Use a listener to skip registration

This commit is contained in:
Yassine Guedidi 2022-05-05 23:29:25 +02:00
parent bfc28d4c0b
commit 007bd31bee
4 changed files with 51 additions and 24 deletions

View file

@ -41,12 +41,6 @@ homepage:
fos_user:
resource: "@FOSUserBundle/Resources/config/routing/all.xml"
fos_user_registration_register:
path: /register
defaults:
_controller: Wallabag\UserBundle\Controller\RegistrationController::registerAction
methods: [GET, POST]
fos_oauth_server_token:
resource: "@FOSOAuthServerBundle/Resources/config/routing/token.xml"

View file

@ -1,18 +0,0 @@
<?php
namespace Wallabag\UserBundle\Controller;
use FOS\UserBundle\Controller\RegistrationController as FOSRegistrationController;
use Symfony\Component\HttpFoundation\Request;
class RegistrationController extends FOSRegistrationController
{
public function registerAction(Request $request)
{
if ($this->container->getParameter('fosuser_registration')) {
return parent::registerAction($request);
}
return $this->redirectToRoute('fos_user_security_login', [], 301);
}
}

View file

@ -0,0 +1,44 @@
<?php
namespace Wallabag\UserBundle\EventListener;
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));
}
}

View file

@ -9,6 +9,13 @@ services:
- '@=service(''craue_config'').get(''wallabag_support_url'')'
- '%domain_name%'
Wallabag\UserBundle\EventListener\RegistrationListener:
arguments:
- '%fosuser_registration%'
- '@router'
tags:
- { name: kernel.event_subscriber }
wallabag_user.password_resetting:
class: Wallabag\UserBundle\EventListener\PasswordResettingListener
arguments: