我可以登录,但在调试栏中会说“您未经过身份验证”。
当我尝试检索令牌时,我得到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>
则loginAction
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,
));
}
的 security.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