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 action inaccessible and I don't know how? Till now, I just put the ROLE_ADMIN in the access control for the route register to avoid that visitors can go throw it.
Any tips?
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
Take a look at the routing configuration imported from
If you want just the basic security actions, just import
instead of
This way you can simply select which components (security, profile, resetting, change_password) you want to use or event import only specific routes from those components.
Another simple solution (the one I used) is to overwrite the
registerAction()
defaultFOSUserBundle
controller method:Doing this will leave active other routes, as the confirmation page.
I simply overwrote the register action and redirect the user to my first registration page (getStarted).
You can try to change your routing.yml
And in your DefaultController
This is how I solve this issue...
First you have to define your listener in the services.yml file:
Then create your class RegistrationListener:
Hope it helps.
If you use the JMSSecurityExtraBundle you can use the
denyAll
directive like so:- { path: ^/register, access: denyAll }