9

我最近使用composer更新了symfony2,现在我无法登录。以下是相关文件。让我知道是否需要更多数据。

应用程序/配置/路由.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/user-bundle/FOS/UserBundle/Resources/config/routing/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/user-bundle/FOS/UserBundle/Resources/config/routing/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 应用程序/控制台路由:调试

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 }
4

2 回答 2

11

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

/login/您的路由配置中确实存在url (带有尾部斜杠)。

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

{{ path('fos_user_security_login') }}

进一步...请在此处阅读我的答案,该答案解释了工作方式<firewall>.login.check_path

将主防火墙的提供程序从 更改userfos_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
于 2013-11-03T10:19:40.683 回答
0

我遇到了类似的问题,尽管我以不同的方式解决了(使用 Symfony 3.1,但也许它是相同的解决方法)。

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

现在,问题是在控制台中,默认环境是 DEV,而在 broser 中,它是 PROD。

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

bin/console debug:router --env=dev,我得到了和之前一样的结果。

但是执行bin/console debug:router --env=prod的时候,控制台报错,说routing.yml找不到文件。

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

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

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

于 2017-06-08T23:22:06.620 回答