How to definitely disable registration in FOSUserBundle

后端 未结 7 2623
无人及你
无人及你 2021-02-19 03:02

In my project, I allow only one user to manage the content of the website. This user will be added using the command line at first.

Now, I want to get the registration a

7条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-19 03:22

    This is how I solve this issue...

    First you have to define your listener in the services.yml file:

    services:
        registrationListner:
          class: App\YourBundle\Listener\RegistrationListener
          arguments: [@service_container]
          tags:
        - { name: kernel.event_listener, event: kernel.request, method: onKernelRequest}
    

    Then create your class RegistrationListener:

    router = $container->get('router');
    }
    
    public function onKernelRequest(GetResponseEvent $event)
    {
    
        $route = $event->getRequest()->attributes->get('_route');
        if ($route == 'fos_user_registration_register') {
            //here we're gonna to redirect to you_route for example, I guess in the most cases it will be the index...
            $event->setResponse(new RedirectResponse($this->router->generate('your_route'))); 
        }
    }
    }
    

    Hope it helps.

提交回复
热议问题