简体   繁体   English

Symfony2 FOSUserBundle两个登录表单错误配置检查路径

[英]Symfony2 FOSUserBundle two login form error configure the check path

i need to have 2 login form. 我需要有2个登录表单。

1 -> main site 2 -> my backend 1 - >主站点2 - >我的后端

i have see many thread for this. 我看到很多线索。

I try to do it, but i have an error : "You must configure the check path to be handled by the firewall using form_login in your security firewall configuration." 我尝试这样做,但我有一个错误: “您必须使用安全防火墙配置中的form_login配置检查路径以由防火墙处理。”

But it's set in security.yml 但是它设置在security.yml中

My route is ok, my form is ok, and i don't see where is my error. 我的路线还可以,我的表格还可以,我看不出我的错误在哪里。

This is my security.yml 这是我的security.yml

admin_login:
        context: backend
        pattern: ^/th-admin/login
        anonymous: true

    admin_check:
        context: backend
        pattern: ^/th-admin/login_check
        anonymous: true

    admin_access_denied:
        context: backend
        pattern: ^/th-admin/access_denied
        anonymous: true

    admin:
        context: backend
        pattern: ^/th-admin

        form_login:
            provider: fos_userbundle
            csrf_provider: form.csrf_provider
            #use_referer: true # this is not needed if you always use default target
            #always_use_default_target_path: true
            #default_target_path: th_admin_dashboard
            login_path: th_admin_login
            check_path: th_admin_check

        logout:
            path:   th_admin_logout
            target: th_admin_login
        anonymous: false
        access_denied_url: th_admin_denied




    main:
        pattern: ^/
        form_login:
            provider: fos_userbundle
            csrf_provider: form.csrf_provider
            login_path: fos_user_security_login
            check_path: fos_user_security_check
        logout:       true
        anonymous:    true


access_control:
    - { path: ^/, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/th-admin/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/th-admin/access_denied, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/th-admin/, role: ROLE_ADMIN }

This is my fos_user configuration : 这是我的fos_user配置:

fos_user:
    db_driver: orm
    firewall_name: main
    user_class: TH\UserBundle\Entity\User

This is my custom form : 这是我的自定义表单:

            {% if error %}
            <div>{{ error.messageKey|trans(error.messageData, 'security') }}</div>
        {% endif %}


        <form class="m-t" role="form" method="post" action="{{ path("th_admin_check") }}">

            <input type="hidden" name="_csrf_token" value="{{ csrf_token }}" />

            <div class="form-group">
                <input name="_username" value="{{ last_username }}" type="email" class="form-control" placeholder="{{ 'admin.login.email'|trans }}" required="">
            </div>

            <div class="form-group">
                <input name="_password" type="password" class="form-control" placeholder="{{ 'admin.login.password'|trans }}" required="">
            </div>
            <input type="hidden" name="_submit" value="Login" />

            <button type="submit" class="btn btn-primary block full-width m-b">{{ 'admin.login.login'|trans }}</button>

        </form>

This is my routes : 这是我的路线:

th_admin_denied:
    path:     /access_denied
    defaults: { _controller: THAdminBundle:Default:accessDenied }

th_admin_login:
    path:     /login
    defaults: { _controller: FOSUserBundle:Security:login }

th_admin_check:
    path:     /login_check
    defaults: { _controller: FOSUserBundle:Security:check }

th_admin_logout:
    path:     /logout
    defaults: { _controller: FOSUserBundle:Security:logout }

th_admin_dashboard:
    path:     /
    defaults: { _controller: THAdminBundle:Dashboard:index }

I have try to clear cache, hard clear cache (empty folder with rm -rf) 我已经尝试清除缓存,硬清除缓存(空文件夹与rm -rf)

When i set the other check url, this work but this go to the main firewall. 当我设置其他检查URL时,这项工作但是这将转到主防火墙。 The main firewall work. 防火墙主要工作。 But my admin backend firewall doesn't work... 但我的管理员后端防火墙不起作用......

Anyone know where is my error ? 有谁知道我的错误在哪里?

Thx 谢谢

My problem is the firewall configuration. 我的问题是防火墙配置。

Need to have an order in access_control and does'nt create useless firewall. 需要在access_control中订购并且不会创建无用的防火墙。 Thx all for your reply. 谢谢你的回复。

This is the good configuration : 这是一个很好的配置:

firewalls:

    admin_firewall:
        pattern: ^/th-admin

        form_login:
            provider: fos_userbundle
            csrf_provider: form.csrf_provider
            #use_referer: true # this is not needed if you always use default target
            #always_use_default_target_path: true
            #default_target_path: th_admin_dashboard
            login_path: th_admin_login
            check_path: th_admin_check

        logout:
            path:   th_admin_logout
            target: th_admin_login
        anonymous: ~
        access_denied_url: th_admin_denied


    main:
        pattern: ^/
        form_login:
            provider: fos_userbundle
            csrf_provider: form.csrf_provider
            login_path: fos_user_security_login
            check_path: fos_user_security_check
        logout:       true
        anonymous:    true


access_control:
    - { path: /th-admin/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: /th-admin/access_denied, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/th-admin, role: ROLE_ADMIN }
    - { path: ^/th-admin/$, role: ROLE_ADMIN }
    - { path: ^/, role: IS_AUTHENTICATED_ANONYMOUSLY }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM