1

大家,早安。我正在玩一些 Symfony2,并且我已经实现了文档所说的基本身份验证。

我可以登录,但在调试栏中显示“您未通过身份验证”。

当我尝试检索令牌时,我得到 NULL,因此,我无法获取用户、用户名或任何我想要的东西。

我已经阅读了大量的帖子,但我找不到任何线索为什么会这样。

任何可能的解决方案?

登录表单

{% if error %}
    <div>{{ error.message }}</div>
{% endif %}

<form action="{{ path('login_check') }}" method="post">
<label for="username">User:</label>
<input id="username" type="text" name="_username" value="{{ last_username }}" />
<label for="password">Password:</label>
<input id="password" type="password" name="_password" /> <input type="submit" name="login" />
</form>


登录动作

public function loginAction()
{

    $request = $this->getRequest();
    $session = $request->getSession();


    if ($request->attributes->has(SecurityContext::AUTHENTICATION_ERROR))
    {
        $error = $request->attributes->get(SecurityContext::AUTHENTICATION_ERROR);
    }
    else
    {
        $error = $session->get(SecurityContext::AUTHENTICATION_ERROR);
    }



    return $this->render('JillFBAdminBundle:Security:login.html.twig', array(
        'last_username' => $session->get(SecurityContext::LAST_USERNAME),
        'error'         => $error,
    ));
}


安全.yml

providers:
    administrators:
        entity: { class: JillFBSiteBundle:User, property: username }

firewalls:
    admin_area:
        provider: administrators
        security: true
        anonymous: false
        pattern: ^/admin/
        form_login:
            check_path: /admin/login_check
            login_path: /login
        logout:
            path: /admin/logout
            target: /home



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

代币

5123898f6f3d2   192.168.1.83    GET     http://192.168.1.83:88/Jill/app_dev.php/admin/              Tue, 19 Feb 2013 15:17:51 +0100
5123898f07be5   192.168.1.83    POST    http://192.168.1.83:88/Jill/app_dev.php/admin/login_check   Tue, 19 Feb 2013 15:17:51 +0100
4

0 回答 0