1

基本上我想要完成的是创建一个基于奏鸣曲用户的新登录表单,这是奏鸣曲电子商务中使用的 fos 用户实现。新的登录表单应该与原始登录表单相同,但布局不同。

我做了什么:
-创建了新的树枝文件
-添加了路由:

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

内容:

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

- 在 security.yml 中添加了新的防火墙(非常类似于 '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

之后,当我填写好的凭据时,它会很好地登录我,但是当我输入错误的凭据时,它会将我重定向到 /login 而不是 /partner/login 并显示“错误凭据”消息。我该如何解决?我错过了什么吗?

编辑1:
我检查了管理员登录是如何进行的,发现表单操作与正常登录不同的控制器看起来与fos用户“检查”操作相同:

    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.');
}

我将它复制到我的控制器,然后在提交带有错误凭据的表单后,我得到的就是这个错误:

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

2 回答 2

1

You should change the failure_path to your new route:

  form_login:
        failure_path:   /partner/login

Or

  form_login:
        failure_path:   m2m_partner_login

The second way is cleaner because it uses route name instead of the url. So if you change the url in your xml it wont break your firewall.

http://symfony.com/doc/current/cookbook/security/form_login.html#redirecting-on-login-failure

I'm guessing if you dont provide the failure_path, it fallbacks to the default failure path (/login).

edit1:

You need to add in your route xml:

<route id="m2m_partner_login_check" pattern="/login_check">
    <default key="_controller">ApplicationSonataUserBundle:Partner:check</default>
    <requirement key="_method">POST</requirement>
</route>

<route id="m2m_partner_logout" pattern="/logout">
    <default key="_controller">ApplicationSonataUserBundle:Partner:logout</default>
</route>

Maybe this will fix the exception.

于 2014-12-11T13:33:55.943 回答
1

检查防火墙元素的顺序。合作伙伴应高于主要部分,如

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



      main:
       .....
于 2014-12-17T13:07:22.690 回答