fosuserbundle找不到“GET / login /”的路线

时间:2013-11-03 08:38:03

标签: symfony routing fosuserbundle

我最近使用composer更新了symfony2,现在我无法登录。这是相关文件。如果需要更多数据,请与我们联系。

应用程序/配置/ routing.yml中

app_admin:
resource: "@AppAdminBundle/Resources/config/routing.yml"
prefix:   /admin
host: dashboard.muchomonitor.com

app_website:
resource: "@AppWebsiteBundle/Resources/config/routing.yml"
prefix:   /
host: www.muchomonitor.com

app_monitor:
resource: "@AppMonitorBundle/Resources/config/routing.yml"
prefix:   /
host: dashboard.muchomonitor.com

fos_user_security:
resource: "@FOSUserBundle/Resources/config/routing/security.xml"
host: dashboard.muchomonitor.com

fos_user_security_reset:
resource: "@FOSUserBundle/Resources/config/routing/resetting.xml"
prefix: /login
host: dashboard.muchomonitor.com

应用程序/配置/ security.yml

security:
encoders:
    FOS\UserBundle\Model\UserInterface: sha512

role_hierarchy:
    ROLE_ADMIN:       ROLE_USER
    ROLE_SUPER_ADMIN: ROLE_ADMIN

providers:
    fos_userbundle:
        id: fos_user.user_provider.username
    user:
        entity: { class: App\MonitorBundle\Entity\User, property: username }

firewalls:
    main:
        pattern: ^/
        provider: user
        form_login:
            provider: fos_userbundle
            csrf_provider: form.csrf_provider
            login_path: fos_user_security_login
            check_path: fos_user_security_check
            default_target_path: /
        logout:       true
        anonymous:    true
        logout:
            path:   /logout
            target: /login

access_control:
    - { path: ^/admin, role: ROLE_SUPER_ADMIN, host: dashboard.muchomonitor.com }
    - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY, host: dashboard.muchomonitor.com }
    - { path: ^/_, role: ROLE_ADMIN } # Development mode
    - { path: ^/public-status, role: IS_AUTHENTICATED_ANONYMOUSLY, host: dashboard.muchomonitor.com }
    - { path: ^/ipn, role: IS_AUTHENTICATED_ANONYMOUSLY, host: dashboard.muchomonitor.com }
    - { path: ^/invoice, role: IS_AUTHENTICATED_ANONYMOUSLY, host: dashboard.muchomonitor.com }
    - { path: ^/, role: ROLE_USER, host: dashboard.muchomonitor.com }

供应商/ friendsofsymfony /用户束/ FOS / UserBundle /资源/配置/路由/ security.xml文件

<?xml version="1.0" encoding="UTF-8" ?>

<routes xmlns="http://symfony.com/schema/routing"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">

    <route id="fos_user_security_login" pattern="/login">
        <default key="_controller">FOSUserBundle:Security:login</default>
    </route>

    <route id="fos_user_security_check" pattern="/login_check">
        <default key="_controller">FOSUserBundle:Security:check</default>
        <requirement key="_method">POST</requirement>
    </route>

    <route id="fos_user_security_logout" pattern="/logout">
        <default key="_controller">FOSUserBundle:Security:logout</default>
    </route>

</routes>

供应商/ friendsofsymfony /用户束/ FOS / UserBundle /资源/配置/路由/ resetting.xml

<?xml version="1.0" encoding="UTF-8" ?>

<routes xmlns="http://symfony.com/schema/routing"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">

    <route id="fos_user_resetting_request" pattern="/request">
        <default key="_controller">FOSUserBundle:Resetting:request</default>
        <requirement key="_method">GET</requirement>
    </route>

    <route id="fos_user_resetting_send_email" pattern="/send-email">
        <default key="_controller">FOSUserBundle:Resetting:sendEmail</default>
        <requirement key="_method">POST</requirement>
    </route>

    <route id="fos_user_resetting_check_email" pattern="/check-email">
        <default key="_controller">FOSUserBundle:Resetting:checkEmail</default>
        <requirement key="_method">GET</requirement>
    </route>

    <route id="fos_user_resetting_reset" pattern="/reset/{token}">
        <default key="_controller">FOSUserBundle:Resetting:reset</default>
        <requirement key="_method">GET|POST</requirement>
    </route>

</routes>

php app / console route:debug

Name                           Method   Scheme Host                       Path
app_admin_users                ANY      ANY    dashboard.muchomonitor.com /admin
app_admin_add_user             ANY      ANY    dashboard.muchomonitor.com /admin
app_admin_edit_user            ANY      ANY    dashboard.muchomonitor.com /admin
app_admin_delete_user          ANY      ANY    dashboard.muchomonitor.com                                    /admin/user/{id}/delete
app_admin_login_user           ANY      ANY    dashboard.muchomonitor.com  /admin/user/{id}/login
app_admin_plans                ANY      ANY    dashboard.muchomonitor.com /admin/plans
app_admin_delete_plan          ANY      ANY    dashboard.muchomonitor.com /admin/plans/{id}/delete
app_admin_edit_plan            ANY      ANY    dashboard.muchomonitor.com /admin/plans/{id}/edit
app_admin_add_plan             ANY      ANY    dashboard.muchomonitor.com /admin/plans/add
app_admin_invoices             ANY      ANY    dashboard.muchomonitor.com /admin/invoices
app_admin_delete_invoice       ANY      ANY    dashboard.muchomonitor.com /admin/invoices/{id}/delete
app_admin_edit_invoice         ANY      ANY    dashboard.muchomonitor.com /admin/invoices/{id}/edit
app_admin_add_invoice          ANY      ANY    dashboard.muchomonitor.com /admin/invoices/add
app_website_index              ANY      ANY    www.muchomonitor.com       /
app_website_pricing            ANY      ANY    www.muchomonitor.com       /pricing
app_website_privacy_policy     ANY      ANY    www.muchomonitor.com       /legal/privacypolicy
app_website_signup             ANY      ANY    www.muchomonitor.com       /signup
app_website_tos                ANY      ANY    www.muchomonitor.com       /legal/termsofservice
app_website_contact_us         ANY      ANY    www.muchomonitor.com       /contactus
app_monitor_dashboard          ANY      ANY    dashboard.muchomonitor.com /
app_monitor_dashboard_search   ANY      ANY    dashboard.muchomonitor.com /dashboard/search/{filter}
app_monitor_dashboard_toggle   ANY      ANY    dashboard.muchomonitor.com /dashboard/toggle/{monitor}
app_monitor_dashboard_delete   ANY      ANY    dashboard.muchomonitor.com /dashboard/delete
app_monitor_dashboard_test     ANY      ANY    dashboard.muchomonitor.com /dashboard/test
app_monitor_monitors           ANY      ANY    dashboard.muchomonitor.com /monitors
app_monitor_monitors_edit      ANY      ANY    dashboard.muchomonitor.com /monitors/edit/{monitor}
app_monitor_monitors_new       ANY      ANY    dashboard.muchomonitor.com /monitors/new
app_monitor_monitors_toggle    ANY      ANY    dashboard.muchomonitor.com /monitors/toggle/{monitor}
app_monitor_monitors_delete    ANY      ANY    dashboard.muchomonitor.com /monitors/delete
app_monitor_monitors_test      ANY      ANY    dashboard.muchomonitor.com /monitors/test
app_monitor_report             ANY      ANY    dashboard.muchomonitor.com /report
app_monitor_reports            ANY      ANY    dashboard.muchomonitor.com /report
app_monitor_report_specific    ANY      ANY    dashboard.muchomonitor.com /report/{monitor}
app_monitor_accounts           ANY      ANY    dashboard.muchomonitor.com /accounts
app_monitor_accounts_edit      ANY      ANY    dashboard.muchomonitor.com /accounts/edit/{id}
app_monitor_accounts_new       ANY      ANY    dashboard.muchomonitor.com /accounts/new
app_monitor_accounts_delete    ANY      ANY    dashboard.muchomonitor.com /accounts/delete
app_monitor_billing            ANY      ANY    dashboard.muchomonitor.com /billing
app_monitor_billing_all        ANY      ANY    dashboard.muchomonitor.com /billing/all
app_monitor_billing_invoice    ANY      ANY    dashboard.muchomonitor.com /invoice/{key}/{id}
app_monitor_notifications      ANY      ANY    dashboard.muchomonitor.com /notifications
app_monitor_ipn                ANY      ANY    dashboard.muchomonitor.com /ipn
app_monitor_ipn_stripe         ANY      ANY    dashboard.muchomonitor.com /ipn-stripe
fos_user_security_login        ANY      ANY    dashboard.muchomonitor.com /login
fos_user_security_check        POST     ANY    dashboard.muchomonitor.com /login_check
fos_user_security_logout       ANY      ANY    dashboard.muchomonitor.com /logout
fos_user_resetting_request     GET      ANY    dashboard.muchomonitor.com /login/request
fos_user_resetting_send_email  POST     ANY    dashboard.muchomonitor.com /login/send-email
fos_user_resetting_check_email GET      ANY    dashboard.muchomonitor.com /login/check-email
fos_user_resetting_reset       GET|POST ANY    dashboard.muchomonitor.com /login/reset/{token}

进入dashboard.muchomonitor.com/login显示它不起作用,尽管上面的命令说的。

编辑: 我已经解决了这个问题。在routing.yml

fos_user_security_login:
pattern:  /login/
defaults: { _controller: FOSUserBundle:Security:login }

fos_user_security_check:
pattern:  /login_check
defaults: { _controller: FOSUserBundle:Security:check }

fos_user_security_logout:
pattern:  /logout
defaults: { _controller: FOSUserBundle:Security:logout }

2 个答案:

答案 0 :(得分:10)

首先......您的登录网址应该(根据您当前的配置)为/login而不是/login/

网址/login / (带有斜杠)确实存在于您的路由配置中。

正确的方法是让路由器使用路线名称生成网址,而不是将网址/login硬编码到任何模板中。

{{ path('fos_user_security_login') }}

进一步......请阅读my answer here,其中解释了<firewall>.login.check_path的工作方式。

将主防火墙的提供程序从user更改为fos_userbundle

login_path下没有其他提供商配置。

firewalls:
    main:
        pattern: ^/
        provider: fos_userbundle
        form_login:
            csrf_provider:       form.csrf_provider
            login_path:          fos_user_security_login
            check_path:          fos_user_security_check
            default_target_path: app_website_index
        logout:
            path:   fos_user_security_logout
            target: fos_user_security_login
        anonymous:    true

此外,您已在防火墙配置中声明两次注销(第二次覆盖首先):

firewalls:
    # ...
    logout:       true
    # ...
    logout:
        path:   /logout
        target: /login

答案 1 :(得分:0)

我遇到了类似的问题,虽然我的解决方法不同(使用Symfony 3.1,但也许是同样的解决方法)。

当我在控制台中执行命令bin/console debug:router时,我可以看到FoS用户包提供的身份验证路由是正确的,并且它们正确显示。

现在,问题是在控制台中,默认环境是DEV,而从更加明显的是,它是PROD。

我执行了上面相同的命令,但明确地传递了环境,如下所示:

bin/console debug:router --env=dev,我得到了与之前相同的结果。

但是在执行bin/console debug:router --env=prod时,我在控制台中收到错误,说找不到routing.yml文件。

这是对的。我更改了app/config目录的结构,并为每个环境创建了一个文件夹,每个文件夹中都有相关文件(更整洁的配置,恕我直言)。

但看起来PROD环境中routing.yml的路径在某些供应商中是硬编码的(例如,在vendor/sensio/generator-bundle/Command中),因此,该文件的位置无法实现改变了。

重新安排配置文件夹后,一切正常(但我必须清除PROD环境的缓存,如下所示:bin/console cache:clear --no-warmup --env=prod