Search code examples
symfonysymfony-sonatasonata-user-bundle

sonata user new firewall keeps redirecting to wrong route


basicaly what i'm trying to accomplish is to create a new login form based on sonata user which is a fos user implementation used in sonata ecommerce. The new login form is supposed to do the same as the original login form but have different layout.

What i did:
- Created new twig file
- added routing:

m2m_partner:
resource: "@ApplicationSonataUserBundle/Resources/config/routing/partnerlogin.xml"
prefix: /partner

contents:

<route id="m2m_partner_login" pattern="/login">
<default key="_controller">ApplicationSonataUserBundle:Partner:login</default>
</route>

-Added new firewall in security.yml (pretty similar to the one in 'admin')

    partner:
        pattern:      /partner(.*)
        context:        user
        form_login:
            provider:       fos_userbundle
            login_path:     /partner/login
            use_forward:    false
            check_path:     /partner/login_check
            failure_path:   null
        logout:
            path: /partner/logout
            invalidate_session: false
            handlers: ['sonata.page.cms_manager_selector']
        anonymous:    true
        switch_user: true

After that when i fill in good credentials it logs me in fine but when i put bad credentials it redirects me to /login instead of /partner/login with 'bad credentials' message. How can i fix it? am i missing something?

edit 1:
i checked how admin login is going on and found out form action goes to a different controller than normal login which looks just the same as fos user 'check' action:

    public function checkAction()
{
    throw new \RuntimeException('You must configure the check path to be handled by the firewall using form_login in your security firewall configuration.');
}

i copied it to my controller and after this all i get after submitting form with bad credentials is this error:

 You must configure the check path to be handled by the firewall using form_login in your security firewall configuration. 

Solution

  • Check order of your firewals elements. Partner should be above main section like

     firewalls:
          partner:
             pattern:      /partner(.*)
             ......
    
    
    
          main:
           .....