简体   繁体   English

symfony2 FOSUserBundle重定向错误

[英]symfony2 FOSUserBundle redirecting wrong

I've got FOSUserBundle installed and is working to an extent.. It logs me in, it does everything its supposed to -- except redirect me to the right place.. 我已经安装了FOSUserBundle并且工作到了一定程度..它记录了我,它做了它应该做的一切 - 除了将我重定向到正确的地方..

I have my routes for it setup in my AdminBundle routes.yml file (the very routes from the FOSUserBundle installation documentation on github) 我在AdminBundle routes.yml文件中设置了我的路由(来自github上FOSUserBundle安装文档的路径)

I've created a firewall for it: 我为它创建了一个防火墙:

security:
encoders:
    "FOS\UserBundle\Model\UserInterface": sha512

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

providers:
    fos_userbundle:
        id: fos_user.user_manager

firewalls:
    admin_area:
        pattern:    ^/admin/
        form_login:
            check_path: /admin/login_check
            login_path: /admin/login
            provider: fos_userbundle
        anonymous: true
        logout:
            path:   /admin/logout
            target: /admin/

access_control:
     - { path: ^/admin/login$, roles: IS_AUTHENTICATED_ANONYMOUSLY }
     - { path: ^/admin/, roles: ROLE_ADMIN }

The only problem is, when i go to http://mysite.dev/admin it redirects me to http://mysite.dev/admin/login which is correct... So I then login and it redirects me to http://mysite.dev/ instead of /admin 唯一的问题是,当我去http://mysite.dev/admin时,它会将我重定向到http://mysite.dev/admin/login这是正确的...所以我然后登录并将它重定向到http: //mysite.dev/而不是/ admin

It's important to note that I've extended the login form to make it look like my own.. by creating in the views folder for my AdminBundle a layout.html.twig to give it a look like the rest of the design for the admin that i'll be using.. 重要的是要注意我已经扩展了登录表单,使其看起来像我自己的......通过在我的AdminBundle的views文件夹中创建一个layout.html.twig,使其看起来像管理员的其余设计我会用...

Any ideas? 有任何想法吗? Thanks.. 谢谢..

You need to place a hidden input named "_target_path" on your log in form, this is used by symfony to check where the user should be redirected after he or she has been successfully authenticated. 您需要在登录表单中放置一个名为“_target_path”的隐藏输入,symfony使用它来检查用户在成功通过身份验证后应该重定向到哪里。 You can customize it. 你可以自定义它。 Check the documentation at: http://symfony.com/doc/current/cookbook/security/form_login.html 请查看以下文档: http//symfony.com/doc/current/cookbook/security/form_login.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM