首先;
Adding Captcha to Symfony2 Login Page
我看到上面的谈话,但这不完全是我想要的。我只是想在验证之前检查验证码是否为假。
不,我不想使用捆绑包。
我需要知道,当symfony2执行安全登录事件时?
图:
登录表单提交 - >检查验证码 - >检查参数 - >做认证。
有什么想法吗?
答案 0 :(得分:2)
我可以在下面使用它。
<?php
namespace CS\UserBundle\Listener;
use Symfony\Component\Security\Core\Exception\BadCredentialsException;
use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
class LoginListener
{
public function onSecurityInteractiveLogin(InteractiveLoginEvent $event)
{
$request = $event->getRequest();
$captcha = $request->request->get('captcha');
if(!empty($captcha) && $captcha !== $request->getSession()->get('captcha')) {
throw new BadCredentialsException('Doğrulama Kodu Yanlış!');
}
}
}
服务(yml)
services:
cs_user.login_listener:
class: CS\UserBundle\Listener\LoginListener
tags:
- { name: kernel.event_listener, event: security.interactive_login }