9

I recently updated symfony2 using composer, and now I can't login. Here are the relevant files. Let me know if more data is needed.

app/config/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

app/config/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 }

vendor/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>

vendor/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 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}

going onto dashboard.muchomonitor.com/login shows it doesn't work, despite what the above command said.

EDIT: I have solved the problem. In 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 }
No_name
  • 2,732
  • 3
  • 32
  • 48

2 Answers2

11

First of all ... your login url should (according to your current configuration) be /login and not /login/.

The url /login/ (with a trailing slash) does indeed not exist in your routing configuration.

The right way would be letting the router generate the url using the route's name and not hardcoding that url /login into any of your templates.

{{ path('fos_user_security_login') }}

Further ... Please read my answer here which explains the way <firewall>.login.check_path works.

Change the provider for your main firewall from user to fos_userbundle.

There is no additonal provider configuration under 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

Further you have declared logout twice in your firewall configuration (second overwrites first):

firewalls:
    # ...
    logout:       true
    # ...
    logout:
        path:   /logout
        target: /login
Community
  • 1
  • 1
Nicolai Fröhlich
  • 51,330
  • 11
  • 126
  • 130
  • I have changed the provider from user to fos_userbundle. Still the same error. – No_name Nov 03 '13 at 21:02
  • I tried copying and pasting your firewall and I got this error "Cannot import resource "/var/www/html/app/config/security.yml" from "/var/www/html/app/config/config.yml". (Unable to parse at line 20 (near " csrf_provider: form.csrf_provider").)" – No_name Nov 03 '13 at 23:37
  • I was missing `form_login:` in my answer - corrected that and added more information. please report back. – Nicolai Fröhlich Nov 03 '13 at 23:53
  • You are correct, /login/ is not a valid route via the console. I pasted in your new firewall and I'm still getting the same error. Would a stack trace help? – No_name Nov 04 '13 at 02:02
  • Yes please add it to the question and please add your template aswell so we can see how you generate the url and where. – Nicolai Fröhlich Nov 04 '13 at 12:16
  • Specifically which template? The login template? – No_name Nov 04 '13 at 18:04
  • I have fixed it, will update question soon with solution. Thanks! – No_name Nov 04 '13 at 20:59
0

I got the similar problem, although I resolved differently (using Symfony 3.1, but perhaps it is the same work around).

When I executed in the console the command bin/console debug:router, I could see that the routes for the authentication provided by the FoS User bundle were correct, and they displayed properly.

Now, the problem is that in the console, the default environment was DEV, whereas from the broser, it was PROD.

I executed the same command above, but explicitely passing the environment, as follows:

bin/console debug:router --env=dev, and I got the same results as earlier.

But when executing bin/console debug:router --env=prod, I got an error in the console, saying that the routing.yml file could not be found.

That was correct. I had changed the structure of the app/config directory, and created a folder for each environment, with the relevant files in each folder (much neater configuration, IMHO).

But it looks like the path for routing.yml for the PROD environment is hardcoded in some vendors (example, in vendor/sensio/generator-bundle/Command), and because of that, the location of that file can't be changed.

After re-arranging the configuration folder, everything worked (but I had to clear the cache of the PROD environment, as follows: bin/console cache:clear --no-warmup --env=prod .

Nicolas
  • 1,320
  • 2
  • 16
  • 28