From ff98e8e6dedd0cda03677cad4478da5cde3c6bb7 Mon Sep 17 00:00:00 2001 From: Gustavo Martin Morcuende Date: Sun, 27 May 2012 22:23:02 +0200 Subject: [PATCH] Register users with RECAPTCHA --- apps/userfront/config/app.yml | 3 +++ apps/userfront/modules/register/actions/actions.class.php | 6 +++++- lib/form/doctrine/UsersRegisterForm.class.php | 4 ++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/apps/userfront/config/app.yml b/apps/userfront/config/app.yml index e5ccf79..7dd4cef 100644 --- a/apps/userfront/config/app.yml +++ b/apps/userfront/config/app.yml @@ -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 diff --git a/apps/userfront/modules/register/actions/actions.class.php b/apps/userfront/modules/register/actions/actions.class.php index 7c1aac2..8d14a9d 100644 --- a/apps/userfront/modules/register/actions/actions.class.php +++ b/apps/userfront/modules/register/actions/actions.class.php @@ -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(); diff --git a/lib/form/doctrine/UsersRegisterForm.class.php b/lib/form/doctrine/UsersRegisterForm.class.php index 96ec05b..fc004cd 100644 --- a/lib/form/doctrine/UsersRegisterForm.class.php +++ b/lib/form/doctrine/UsersRegisterForm.class.php @@ -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'))); } } -- 2.1.4