我创建了一个身份证明表格,但即使没有提交表格,也会出现错误消息“登录错误”。
我使用 app/config/security.yml 的帐户来检查表单。
我的控制器:
public function loginAction() {
$request = $this->getRequest();
$session = $request->getSession();
$error = null;
if ($request->attributes->has(SecurityContext::AUTHENTICATION_ERROR)) {
$error = "Oop's ! Bad login";
} else {
$error = "Oop's ! Bad login";
$session->remove(SecurityContext::AUTHENTICATION_ERROR);
}
return $this->render('CmsCmsBundle:Main:Log/login.html.twig', array(
'last_username' => $session->get(SecurityContext::LAST_USERNAME),
'error' => $error,
));
}
我的观点 :
{% if error %}
<div class="flash flash-error">
{{ error }}
</div> {% endif %}
<form action="{{ path('cms_cms_logcheck') }}" method="post">
<div class="form-align">
<label for="username">Login :</label>
<input type="text" id="username" name="_username" value="{{ last_username }}" required/>
</div>
<div class="form-align">
<label for="password">Pwd :</label>
<input type="password" id="password" name="_password" required/>
</div>
<input type="hidden" name="_target_path" value="/private" />
<input type="submit" class="btn btn-primary" value="Connexion">
</form>
任何想法?
谢谢