How to definitely disable registration in FOSUserBundle

后端 未结 7 2410
无人及你
无人及你 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

    There are many ways to solve this issue. You can simply remove fos_user_registration_register route from routing.yml. Or use more complicated solution: set up event listener to FOS\UserBundle\FOSUserEvents::REGISTRATION_INITIALIZE event and redirect user to login page.

    services.xml

    
        
        
    
    

    RegistrationListener.php

    router = $router;
        }
    
        public static function getSubscribedEvents()
        {
            return [
                FOSUserEvents::REGISTRATION_INITIALIZE => 'onRegistrationInitialize',
            ];
        }
    
        public function onRegistrationInitialize(GetResponseUserEvent $event)
        {
            $url = $this->router->generate('fos_user_security_login');
            $response = new RedirectResponse($url);
    
            $event->setResponse($response);
        }
    }
    

提交回复
热议问题