Symfony2 - FOSUserBundle - Multiple Login Locations

后端 未结 3 652
青春惊慌失措
青春惊慌失措 2021-01-06 01:14

I\'m using the FOSUserBundle and I require the ability to login from 2 different routes(or more). These routes will have different templates and also login to different area

3条回答
  •  误落风尘
    2021-01-06 01:35

    I was stucked with the same question for a while and then i created a solution on my own. I knew there must be an easy solution...

    I've submitted pull request which allows you to create new login templates more easily. Check the pull request here: https://github.com/FriendsOfSymfony/FOSUserBundle/pull/1186.

    There is also another quite easy way how to achieve this. Extend SecurityController and change renderLogin method with following content

    protected function renderLogin(array $data, $template)
    {
        return $this->container->get('templating')->renderResponse('YourBundle:Security:login.html.twig');
    }
    

    Then create a route to your newly created controller:

    admin.login:
        pattern: /admin/login
        defaults: { _controller: YourBundle:Security:login }
    

    After this only you have to do is to alter your security config accordingly. Change your form_login login_path to /admin/login and you are good to go.

提交回复
热议问题