php - Validate ReCaptcha inside FOSUser login form -


i using fosuserbundle , ewzrecaptchabunde. overrided login form add recaptcha field. working.

the problem login form validation not consider recaptcha field , if user enter correct login , password logged.

i have made sort of pre login event should test if captcha valid or not pre login listener extends usernamepasswordformauthenticationlistener , don't know how captcha value.

this attemptauthentication method override other one, in pre login listener

protected function attemptauthentication(request $request) {     // ...      // have added (return null everytime)     $captcha = $request->get($this->options['recaptcha'], null, true);      if ($captcha && true !== $captcha) {         throw new badcredentialsexception('invalid captcha.');     }      // ... } 

in usernamepasswordformauthenticationlistener use $username = $request->get($this->options['username'], null, true); username , password value. values input have _username or _password names (this defined in listener constructor).

i tried same method other field find captcha value captcha field div iframe inside, null everytime because doesn't find anything.

how can value returned captcha (true or false, i'm using new recaptcha) ? don't know how should find value , if possible of course.

it maybe not method allow captcha validation in login form.

thanks helping me.

if want check manualy given recaptcha code valid can create own authentication handler. handler have implement authenticationsuccesshandlerinterface , authenticationfailurehandlerinterface.

there 2 methods needs implemented: `

public function onauthenticationsuccess(request $request, tokeninterface $token) {     // validate captcha code }  public function onauthenticationfailure(request $request, authenticationexception $exception) {     // validate captcha code }` 

in order use session , routing need extend handler class containeraware inject these services via constructor of class.

register custom handler service: `

...     #app/config/security.yml         security.authentication_handler:             class: appbundle\handler\authenticationhandler         public: false         arguments:             - @router             - @session         calls:             - [ setcontainer, [@service_container ] ] 

to enable handlers add following lines security.yml file

... form_login: success_handler: security.authentication_handler failure_handler: security.authentication_handler

you consider using google recaptcha.


Comments