我正在尝试通过自定义身份验证处理程序在数据库中写入一些登录失败信息。 我的问题是获得对数据库的访问权限,因为我不知道 Doctrine 对象可能存储在哪里
这是我现在的代码:
namespace MyApp\FrontBundle\Controller;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request as Request;
use Symfony\Component\HttpFoundation\RedirectResponse as RedirectResponse;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\Security\Http\Authentication as Auth;
use Symfony\Component\Security\Core\Exception\AuthenticationException as AuthException;
class SecurityHandler implements Auth\AuthenticationFailureHandlerInterface
{
public function onAuthenticationFailure(Request $request, AuthException $token)
{
try
{
$lastLoginFailure = new DateTime();
// get database object here
}
catch(\Exception $ex)
{
}
}
}
有什么想法吗?
最佳答案
将您的 SecurityHandler 变成一个服务,然后将 doctrine 实体管理器注入(inject)其中。
关于authentication - 从 Symfony2 中的身份验证失败处理程序访问原则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9491652/