Symfony2 - FOSUserBundle - Multiple Logon Locations

I use FOSUserBundle and I need the ability to log in from two different routes (or more). These routes will have different patterns, as well as entrance to different areas. The only thing that differs between the inputs is the required resolution. Routes will be something like strings

site.com/login

site.com/admin/login

and possibly site.com/ajax_login

I managed to figure out how to get various templates for rendering by pulling everything except the CSRF token from the FOSUserBundle login.html.twig file (which is overloaded), then creating routes that display their own login fields, as well as the login login (so that only CSRF marker gets rendered). This does not work for the administrator / login, as the form returns to the login, and if it fails, it displays this page instead.

Is there an easy way to achieve this?

+5
source share
3 answers

For a while, the same question stuck with me, and then I created the solution myself. I knew there should be a simple solution ...

pull, . : https://github.com/FriendsOfSymfony/FOSUserBundle/pull/1186.

. SecurityController renderLogin

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

:

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

. _ form_login login_path /admin/login, .

+2

, , , , ( , )

firewalls:
    admin:
        context:            site
        switch_user:        true
        pattern:            /admin(.*)
        form_login:
            provider:       fos_userbundle
            login_path:     /admin/login
            success_handler: admin_authentication_handler
            use_forward:    false
            check_path:     /admin/login_check
            failure_path:   null
            use_referer:    true
            always_use_default_target_path: true
            default_target_path: /admin/
        logout:
            path:           /admin/logout
            target:         /admin/login
        anonymous:    true
    public:
        pattern:   ^/
        context:            site
        form_login:
            login_path:     /login
            success_handler: authentication_handler
            failure_handler: authentication_handler
            provider: fos_userbundle
        anonymous: true
        logout: true

, AJAX, , XmlHttpRequest .

+1

?

?

<form action="{{ path('form_submit') }}" method="post" {{ form_enctype(form) }}>

.

0

All Articles