First of all;
Adding Captcha to Symfony2 Login Page
I saw above conversation but this not exactly what i want. I just want to check if captcha is false right before authentication.
And no, i don't want to use a bundle for this.
I need to know, when symfony2 does security login events?
Diagram:
Login form submit -> check captcha -> check parameters -> do authentication.
Any idea?
I get it work with below.
<?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ış!');
}
}
}
Service (yml)
services:
cs_user.login_listener:
class: CS\UserBundle\Listener\LoginListener
tags:
- { name: kernel.event_listener, event: security.interactive_login }
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.