php - 如果我扩展 AbstractFormLoginAuthenticator,如何在 Symfony4 中使用电子邮件而不是用户名?
问题描述
我的email
字段中有字段,login.html.twig
并且想将最后输入email
的,而不是用户名传递给我的模板。如何获取email
表单 AuthenticationUtils::getLastUsername()?
解决方案
只需传递给类的方法内的email
会话:getCredentials()
LoginAuthenticator
public function getCredentials(Request $request)
{
$credentials = [
'email' => $request->request->get('email'),
'password' => $request->request->get('password')
];
$request->getSession()->set(
Security::LAST_USERNAME,
$credentials['email']
);
return $credentials;
}