Hello,
Im trying to disable login and register pages for authentified user.
This is the process :
1) sign up
2) logged and redirected to home
3) trying to access to /login or /register
4) redirct user to index
Can someone help me please ?
after three days of search i finally found the way to do it !!!
In the FOS securityController (for login) : add this to login action
if($session->get("_security_main"))
{
$route = $this->container->get('router')->generate('site_faim_homepage');
return new RedirectResponse($route);
}
and it's ok !
You should really have a look there:
http://symfony.com/doc/current/book/security.html
I advice you to use the firewall for exemple my config:
security:
access_control:
- { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
full security params:
https://github.com/mylen/EventFlowAnalyser/blob/master/app/config/security.yml
@mylen it does not solve his problem, as every user has the role IS_AUTHENTICATED_ANONYMOUSLY, even the authenticated ones.
Well... i'm using that method in my app and it's working as expected maybe
some side effect...
Le 31 déc. 2012 10:51, "winzou" [email protected] a écrit :
@mylen https://github.com/mylen it does not solve his problem, as every
user has the role IS_AUTHENTICATED_ANONYMOUSLY, even the authenticated ones.—
Reply to this email directly or view it on GitHubhttps://github.com/FriendsOfSymfony/FOSUserBundle/issues/889#issuecomment-11774742.
should be this a configurable option of the bundle? what do people think? I know i always do that myself too.
@tannana86 You should use this code.
public function registerAction()
{
if ($this->container->get('security.context')->isGranted('ROLE_USER')) {
return new RedirectResponse('/some-page');
}
}
@Baachi what do you think about this https://github.com/FriendsOfSymfony/FOSUserBundle/issues/996 ?
@tannana86 I don't think you need an option or anything for that as it depends on your application. If you simply don't want to display the login/register form just use in your twig file
{% if is_granted("ROLE") == false%}
{{ form_widget(form) }}
{% endif %}
If you strickly don't want your user to access /login or /register page, maybe you should simply implement an EventListener that hooks FOSUserEvents on login/registration and do a redirection, it's quite easy if you follow the doc
@dupuchba Could you expand on how you would use an EventListener for this task? I went through the docs as well as the FOS\UserBundle\FOSUserEvents FOS\UserBundle\EventListener\ and FOS\UseBundle\Event\ files but couldn't quite wrap my head around it.
@dupuchba I managed to do this for the registration page using the FOS\UserBundle\FOSUserEvents::FOSUserREGISTRATION_INITIALIZE event. I don't see an event that is fired for loading the login page