Unable to find the controller for path “/login_check”

亡梦爱人 提交于 2019-12-10 13:49:46

问题


I have having trouble getting user authentication working on symfony. I have the login_path working properly, but check_path is malfunctioning. The path that I have specified gives the famous Unable to find the controller for path "/login_check". Maybe you forgot to add the matching route in your routing configuration?

I've looked at the other posts, and they all seem to do what I am doing. I am very new to symfony and having trouble grasping the concepts, so I would greatly appreciate some help.

I am using Symfony 2.1, if that makes a difference.

I believe that I have everything configured properly:

security.yml

security:
    encoders:
        Symfony\Component\Security\Core\User\User: plaintext
        Site\CommonBundle\Entity\User: plaintext

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

    providers:
        database:
            entity: { class: SiteCommonBundle:User }

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

        login_firewall:
            pattern:  ^/(login|logout|login_check)
            anonymous: ~

        secured:
            pattern: ^/secured/
            form_login:
                login_path: /login
                check_path: /login_check
            logout:
                path: /logout
                target: /


    access_control:
        - { path: ^/secured/, roles:ROLE_LIGHT }
        - { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY}

routing.yml

common_login:
    pattern:  /login
    defaults: { _controller: SiteCommonBundle:Default:login }

common_login_check:
    pattern: /login_check

回答1:


The login_check path needs to be within your secured area.

In your code, Pattern defines a prefix of '/secured' so your login_check also needs to be prefixed by '/secured'.

In your case, the secured firewall defines that all paths start with the prefix /secured but the path for your login check path is /login_check. Therefore the firewall cannot handle the form.

I think you should remove it from login_firewall as well.



来源:https://stackoverflow.com/questions/13997233/unable-to-find-the-controller-for-path-login-check

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!