登录fos用户symfony后重定向

时间:2014-05-25 17:06:47

标签: symfony-2.1

用fos用户登录后如何重定向?为什么我的代码不能工作? 在这里我的security.yml

   main:
        pattern: ^/
        form_login:
            provider: fos_userbundle
            login_path: /login
            check_path: /login_check
            always_use_default_target_path: false
            # default_target_path:            /home 
            # target_path_parameter:          _target_path
            # use_referer:                    false
        oauth:
            failure_path: /login
            login_path: /login
            check_path: /login
            provider: fos_userbundle
            resource_owners:
                facebook:           "/login/check-facebook"
            oauth_user_provider:
                # service: hwi_oauth.user.provider.fosub_bridge
                service: project_home_userprovider

        anonymous: ~
        logout:
            path: /logout
            target: /login


access_control:
    - { path: ^/login$, roles: [IS_AUTHENTICATED_ANONYMOUSLY] }
    - { path: ^/admin, roles: [ROLE_ADMIN] }
    - { path: ^/murid, roles: [ROLE_MURID] }

这是我的路线

    murid:
    resource: "@muridBundle/Resources/config/routing.yml"
    prefix:   /

admin:
    resource: "@adminBundle/Resources/config/routing.yml"
    prefix:   /admin

home:
    resource: "@homeBundle/Resources/config/routing.yml"
    prefix:   /

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

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

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

hwi_oauth_security:
    resource: "@HWIOAuthBundle/Resources/config/routing/login.xml"
    prefix: /login

hwi_oauth_connect:
    resource: "@HWIOAuthBundle/Resources/config/routing/connect.xml"
    prefix: /login

hwi_oauth_redirect:
    resource: "@HWIOAuthBundle/Resources/config/routing/redirect.xml"
    prefix: /login

facebook_login:
    pattern: /login/check-facebook

成功登录后,它总是直接到symfony主页..你帮我吗?如何重定向到具有不同ROLE的另一个页面?

2 个答案:

答案 0 :(得分:2)

你会找到她的解决方案

http://symfony.com/doc/current/cookbook/security/form_login.html

不知道为什么,但我无法在此处发布代码,所以我发布了我找到答案的网址:)希望对您有所帮助

答案 1 :(得分:0)

您需要定义 default_target_path 。如果使用OAuth,您也应该定义它。

main:
    form_login:
        default_target_path: "/your-path"
    oauth:
        default_target_path: "/your-path"

如果您想根据角色检查this solution更改default_target_path。