I'm working on resetting password system with FosUser, and I don't know how can I remove the auto-login after user changes his password ?
Thanks for help, I don't want to override, I change directly FOS files.
I'm working on resetting password system with FosUser, and I don't know how can I remove the auto-login after user changes his password ?
Thanks for help, I don't want to override, I change directly FOS files.
If you want to override the bundle, you will have to comment the line 132 in \vendor\friendsofsymfony\user-bundle\FOS\UserBundle\Controller\ResettingController.php :
which disable the auto-login. But as bartek says, it is not a good way to do that. Although it is only for one line... I hope it will help you, as I am concerned, I have comment a same line in the regitration by an overloading file on line :
To disable the auto-login after the registration.
Finally I think I found a light but clean way of doing this : events can be stopped ! check http://symfony.com/doc/current/components/event_dispatcher/introduction.html at Stopping Event Flow/Propagation. The event making login after registration seems to be REGISTRATION_COMPLETED, so make a subscriber to this event with a high priority
Then if you fear that some important listener/subscribers loose the event, adjust the listen priority...
I also used a kind of similar solution as @David suggested. My requirement was that only Admin can create users and if user successfully created it should redirect to the list of the users page.
What I have done is that I have handled two/three event. The first one REGISTRATION_SUCCESS where I attached my custom redirect URL to the event as below (also mentioned in the doc):
And if you look at the code of FOSUserbundle RegistrationController after success two more events has been dispatching REGISTRATION_CONFIRM/ED. So I handled these events and have stopped them:
Hope this could help someone.
The proper way :)
Compiler Passes in Symfony allow you to manipulate other services. In this case you want to override
fos_user.listener.authentication
to use your custom subscriber instead of the one provided with FOSUserBundleFOS\UserBundle\EventListener\AuthenticationListener
. You can just extends the provided one to subscribe only to the registration events and NOT to the resetting password event:To do so just define a Compiler Pass like this:
And then register your compiler pass in your bundle definition:
That's it!
Here's something to read: http://symfony.com/doc/current/cookbook/service_container/compiler_passes.html
The service you are going to override: https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Resources/config/listeners.xml
And the original class: https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/EventListener/AuthenticationListener.php