• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

Symfony2 身份验证“login_check"找不到路径

用户头像
it1352
帮助1

问题说明

我是 Symfony2 的新手,我正在尝试创建一个基本的注册 登录系统.因此,在 Symfony2 文档的帮助下,我创建了这个 security.yml:

I'm new to Symfony2 and I'm trying to create a basic registration login system. So, with the help of the Symfony2 documentation I created this security.yml:

security:
    encoders:
        TestCompany\InternetBundle\Entity\Member:
            algorithm:        sha1
            encode_as_base64: false
            iterations:       1

    role_hierarchy:
        ROLE_ADMIN:       ROLE_USER
        ROLE_SUPER_ADMIN: [ ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH ]

    providers:
        administrators:
            entity: { class: TestCompanyInternetBundle:Member, property: username }

    firewalls:
        admin_area:
            pattern:    ^/admin
            anonymous: ~
            form_login:
                login_path:  /login
                check_path:  /login_check

    access_control:
        - { path: ^/admin, roles: ROLE_ADMIN }

我使用了这个路由:

login_check:
    pattern:   /login_check
login:
    pattern:  /login
    defaults: { _controller: TestCompanyInternetBundle:Admin:login }

根据 http://symfony.com/doc/current/book/security.html#using-a-traditional-login-form 我不需要为 login_check 路由实现控制器.然而,Symfony 将这个错误返回给我:

According to http://symfony.com/doc/current/book/security.html#using-a-traditional-login-form I do NOT need to implement a controller for the login_check route. Yet, Symfony returns this error to me:

Unable to find the controller for path "/login_check". Maybe you forgot to add the matching route in your routing configuration?

你有没有发现我在这里做错了什么?登录页面几乎是文档中使用的页面的精确副本.错误发生在页面上:http://localhost/SymfonyTest/web/app_dev.php/login_check,这是我在使用登录表单后被发送到的页面.

Do you see anything I could have done wrong here? The login page is almost an exact copy of the one used in the documentation. The error occurs on the page: http://localhost/SymfonyTest/web/app_dev.php/login_check, which is the page I get sent to after using the login form.

正确答案

#1

http://symfony.com/doc/current/book/security.html#using-a-traditional-login-form

确保 /login_check 位于防火墙后面.

Be sure /login_check is behind a firewall.

因此,在您的示例中,您为安全区域指定了前缀/admin,因此您的登录检查路由也应具有该前缀,例如/admin/login_check

接下来,确保您的 check_path URL(例如/login_check)位于您用于表单登录的防火墙之后(在本例中,单个防火墙匹配所有 URL,包括/login_check).如果/login_check 与任何防火墙都不匹配,您将收到无法找到路径/login_check"的控制器异常.

Next, make sure that your check_path URL (e.g. /login_check) is behind the firewall you're using for your form login (in this example, the single firewall matches all URLs, including /login_check). If /login_check doesn't match any firewall, you'll receive a Unable to find the controller for path "/login_check" exception.

示例 security.yml 配置:

firewalls:
    dev:
        pattern:  ^/(_(profiler|wdt)|css|images|js)/
        security: false

    secured_area:
        pattern:    ^/
        form_login:
            login_path: /login
            check_path: /login_check
        logout:
            path:   /demo/secured/logout
            target: /demo/
        anonymous: ~

    ....

    access_control:
        - { path: ^/admin, roles: ROLE_ADMIN }

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /reply/detail/tangjcfaf
系列文章
更多 icon
同类精品
更多 icon
继续加载