Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable login and register page #889

Closed
sfraoua opened this issue Dec 2, 2012 · 10 comments · Fixed by #2236
Closed

Disable login and register page #889

sfraoua opened this issue Dec 2, 2012 · 10 comments · Fixed by #2236
Milestone

Comments

@sfraoua
Copy link

sfraoua commented Dec 2, 2012

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 ?

@sfraoua
Copy link
Author

sfraoua commented Dec 3, 2012

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 !

@alexandre-melard
Copy link

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

@winzou
Copy link

winzou commented Dec 31, 2012

@mylen it does not solve his problem, as every user has the role IS_AUTHENTICATED_ANONYMOUSLY, even the authenticated ones.

@alexandre-melard
Copy link

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" notifications@github.com 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//issues/889#issuecomment-11774742.

@ghost
Copy link

ghost commented Jan 20, 2013

should be this a configurable option of the bundle? what do people think? I know i always do that myself too.

@Baachi
Copy link

Baachi commented Jan 28, 2013

@tannana86 You should use this code.

public function registerAction()
{
    if ($this->container->get('security.context')->isGranted('ROLE_USER')) {
        return new RedirectResponse('/some-page');
    }
}

@dwaligora
Copy link

@Baachi what do you think about this #996 ?

@dupuchba
Copy link

@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

@electricBonfire
Copy link

@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.

@electricBonfire
Copy link

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants