2
votes

I'm new to Symfony2 and I try to use FOSUserBundle. However the /login url is not using the correct controller but the old controller I was using before :

"OC\UserBundle\Controller\SecurityController::loginAction"

Symfony profiler routing tool tells me that the road "fos_user_security_login" was found for /login pattern :

fos_user_security_login        /login         Route matches!

But the profiler homepage also tells me that :

Request Attributes

Key Value
_controller "OC\\UserBundle\\Controller\\SecurityController::loginAction"
_route      "fos_user_security_login"

I checked more than 10 times but I couldn't find any reference to the old controller in any files such as routing and security files, except in the cache (using the phpStorm advanced search function). Of course I cleared the cache by using the following command :

app/console cache:clear

Do you have any idea where this might come from ?

Here are my routing and security files :

vendor/friendsofsymfony/user-bundle/Ressources/config/routing/security.xml

(Here we can see that this is the FOSUserBundle:Security:login controller that should be used)

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

app/config/routing.yml

oc_platform:
    resource: "@OCPlatformBundle/Resources/config/routing.yml"
    prefix:   /

app:
    resource: "@AppBundle/Controller/"
    type:     annotation



fos_user_security:
    resource: "@FOSUserBundle/Resources/config/routing/security.xml"

fos_user_profile:
    resource: "@FOSUserBundle/Resources/config/routing/profile.xml"
    prefix: /profile

fos_user_register:
    resource: "@FOSUserBundle/Resources/config/routing/registration.xml"
    prefix: /register

fos_user_resetting:
    resource: "@FOSUserBundle/Resources/config/routing/resetting.xml"
    prefix: /resetting

fos_user_change_password:
    resource: "@FOSUserBundle/Resources/config/routing/change_password.xml"
    prefix: /profile

app/config/security.yml

security:
    encoders:
        OC\UserBundle\Entity\User: sha512

    role_hierarchy:
        ROLE_ADMIN:       [ROLE_TESTEUR, ROLE_MODERATEUR]
        ROLE_SUPER_ADMIN: [ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]

    providers:
        main:
            id: fos_user.user_provider.username


    firewalls:
        main_login:
            pattern: ^/login$
            anonymous: true

        main:
            pattern: ^/
            anonymous: true
            provider: main
            form_login:
                login_path: fos_user_security_login
                check_path: fos_user_security_check
            logout:
                path: fos_user_security_logout
                target: /
            remember_me:
                key: %secret%


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

        login:
            security: false

        secured_areas:
            anonymous: ~




    access_control:
        - { path: ^/demo/secured/hello/admin/, roles: ROLE_ADMIN }
        #- { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY, requires_channel: https }

src/OC/PlatformBundle/Ressources/config/routing.yml

oc_platform_homepage:
    path:     /hello/{name}
    defaults: { _controller: OCUserBundle:Default:index }


oc_affiche:
    path:     /hello-world
    defaults: { _controller: OCPlatformBundle:Default:affiche }


oc_home:
    path: /
    defaults: { _controller: OCPlatformBundle:Test:home }

oc_form_show:
    path: /addTest
    defaults: { _controller: OCPlatformBundle:Test:add }

oc_platform_test_view:
    path: /viewTest/{id}
    defaults: { _controller: OCPlatformBundle:Test:view }

oc_platform_test_viewAll:
    path: /viewTest
    defaults: { _controller: OCPlatformBundle:Test:viewAll }


oc_platform_test_user:
    path: /viewUser
    defaults: { _controller: OCPlatformBundle:Test:viewUser }

oc_platform_test_admin:
    path: /viewAdmin
    defaults: { _controller: OCPlatformBundle:Test:viewAdmin }
1
Try restart apache/nginx, maybe it's opcacheCyprian
I can find how to do that on Linux but not on Windows with WAMP. How can I do that ? Also I noticed that the "fos_user_security_login" road is the only one from the FOSUserBundle which is not working properly. I really don't know how to figure this out.pobklk
I don't use Windows so you need to find it by yourself. Anyway restarting the machine will do the work/ What do you see after: "php app/console router_debug fos_user_security_login" from command line?Cyprian
what does the output of app\console debug:router --show-controllers tell you?Twifty
I decided to start a new project, it was the simpliest solution. Thank you anyway !pobklk

1 Answers

0
votes

At a guess, you have a route mapped in @OCPlatformBundle/Resources/config/routing.yml.