我一直在Symfony2中编写自定义身份验证提供程序。到目前为止,一切正常,但是当我输入错误的密码时,将显示一个内部服务器错误消息:“LDAP身份验证失败”。
现在,这是我要显示的消息,但我想在登录表单上方显示它,而不抛出内部服务器错误。在我的听众中,我有以下内容:
try {
$authToken= $this->authenticationManager->authenticate($token);
$this->securityContext->setToken($authToken);
return;
} catch (AuthenticationException $failed) {
throw new BadCredentialsException($failed->getMessage(), 0);
}
那么,有没有人可以告诉我我需要怎么做才能向用户显示一条消息,而不是引发内部服务器错误?
提前致谢。
最佳答案
您可以在 Controller 的登录表单中手动添加错误。例如:
$form->get('username')
->addError(new FormError($message));
关于php - Symfony2-显示错误的凭证错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23264305/