Register users with RECAPTCHA
authorGustavo Martin Morcuende <gu.martinm@gmail.com>
Sun, 27 May 2012 20:23:02 +0000 (22:23 +0200)
committerGustavo Martin Morcuende <gu.martinm@gmail.com>
Sun, 27 May 2012 20:23:02 +0000 (22:23 +0200)
apps/userfront/config/app.yml
apps/userfront/modules/register/actions/actions.class.php
lib/form/doctrine/UsersRegisterForm.class.php

index e5ccf79..7dd4cef 100644 (file)
@@ -16,3 +16,6 @@ all:
      remember_cookie_path:        /userfront.php     # used by sfGuardSecurityUser.class.php. The scope of the Remeber cookie
      remember_cookie_domain:      .localhost
 
+  recaptcha:
+     private_key: 6Lcg9dESAAAAACrrfQ5l9OLp3nq93lN1ra1q-8Kn
+     public_key:  6Lcg9dESAAAAAG-QQLfE8By9c8ufO8WjuhBMz2-M
index 7c1aac2..8d14a9d 100644 (file)
@@ -28,7 +28,11 @@ class registerActions extends sfActions
 
     if ($request->isMethod('post'))
     {
-      $this->form->bind($request->getParameter($this->form->getName()));
+      $captcha = array('recaptcha_challenge_field' => $request->getParameter('recaptcha_challenge_field'),
+                       'recaptcha_response_field'  => $request->getParameter('recaptcha_response_field'),
+                      );
+      $this->form->bind(array_merge($request->getParameter($this->form->getName()), array('captcha' => $captcha)));
+      //$this->form->bind($request->getParameter($this->form->getName()));
       if ($this->form->isValid())
       {
         $user = $this->form->save();
index 96ec05b..fc004cd 100644 (file)
@@ -20,5 +20,9 @@ class UsersRegisterForm extends BasesfGuardRegisterForm
 
     $this->validatorSchema['language_id'] = new sfValidatorDoctrineChoice(array('model'    => $this->getRelatedModelName('Language'),
                                                                                 'required' => true));
+
+    $this->widgetSchema['captcha'] = new sfWidgetFormReCaptcha(array('public_key' => sfConfig::get('app_recaptcha_public_key')));
+
+    $this->validatorSchema['captcha'] = new sfValidatorReCaptcha(array('private_key' => sfConfig::get('app_recaptcha_private_key')));
   }   
 }