dongli5785 2012-03-08 20:34
浏览 46

Symfony-2.0错误登录重定向网址

I have a problem with my symfony 2.0 application. I couldn't find the right solution via google so I'm here :)

I've tried to create a login form. This is my security.yml file:

security:
encoders:
    Domicon\AdminBundle\Entity\User:
        algorithm: sha1
        encode_as_base64: false
        iterations: 10

providers:
    admin:
        entity: { class: DomiconAdminBundle:User, property: email }

role_hierarchy:
    ROLE_ADMIN:       ROLE_USER
    ROLE_SUPER_ADMIN: ROLE_ADMIN

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

    admin_area:
        pattern:    ^/admin.*
        form_login:
            check_path: /admin/login_check
            login_path: /admin/login
        logout:
            path:   /admin/logout
            target: /admin
        anonymous: ~
        logout: true
        http_basic:
            realm: "Secured Admin Area"
        provider: admin 

access_control:
    - { path: ^/admin/login.*, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/admin.*, role: ROLE_ADMIN }

The code of my controller looks like the code in symfony 2.0 docs http://symfony.com/doc/current/book/security.html#using-a-traditional-login-form

My routes

DomiconAdminBundle_login:
pattern:  /login
defaults: { _controller: DomiconAdminBundle:User:login }

DomiconAdminBundle_login_check:
    pattern:   /login_check

The login form is displayed correctly, but if I submit the form the application redirects back to the login form and the url has changed to

http://localhost/Domicon/web/app_dev.php/admin/login?_username=admin&_password=pass

I got no error or anything else. I don't understand why I get no error and why the url changed to this.

  • 写回答

1条回答 默认 最新

  • duanlou2917 2012-04-23 12:27
    关注

    I think you forgot to give the action in <form> tag and you need to tell where to redirect if the login is success.

    And another thing I notice that You had given /login in routing.yml and in security.yml you had given /admin/login.

    Third one is login_path: /admin/login_check in security.yml and in routing.yml you had given

    /login_check.

    Change /login to /admin/login in routing.yml

    Change /login_check to /admin/login_check in routing.yml

    <form action="{{ path('DomiconAdminBundle_login_check') }}" method="post">
      <div>  
        <label for="username">Username:</label>
        <input type="text" id="username" name="_username" value="{{ last_username }}" />
        </div>
      <div> 
        <label for="password">Password:</label>
        <input type="password" id="password" name="_password" />
    </div>
        {#
            If you want to control the URL the user is redirected to on success #}
            <input type="hidden" name="_target_path" value="/yourredirectpath" />
    
    
        <input type="submit" name="login" value="Submit" />
    </form>
    

    Hope this helps.

    评论

报告相同问题?

悬赏问题

  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上