### Eclipse Workspace Patch 1.0 #P drupal-contrib-cvs Index: modules/captcha/captcha.module =================================================================== RCS file: sites/all/modules/captcha/captcha.module,v retrieving revision 1.27 diff -u -r1.27 captcha.module --- modules/captcha/captcha.module 2 Nov 2006 13:59:42 -0000 1.27 +++ modules/captcha/captcha.module 22 Dec 2006 04:27:13 -0000 @@ -9,17 +9,27 @@ $output .= "

Adds a Captcha to the registration form.

"; $output .= "

More help needed here.

"; break; - case 'admin/modules#description': - case 'admin/modules/captcha': - case 'admin/captcha': - $output = t("Adds a Captcha to the registration form."); - break; } return $output; } +function captcha_menu($may_cache) { + $items = array(); + if ($may_cache) { + $items[] = array( + 'path' => 'admin/settings/captcha', + 'title' => t('Captcha'), + 'description' => t('Administer how and where captchas are used.'), + 'callback' => 'drupal_get_form', + 'callback arguments' => array('captcha_admin_settings'), + 'access' => user_access('administer site configuration'), + 'type' => MENU_NORMAL_ITEM, + ); + } + return $items; +} -function captcha_settings() { +function captcha_admin_settings() { //this is where you can add more captcha points $captcha_points = array( @@ -62,7 +72,7 @@ '#description' => t('Select what kind of challenge you want to pose to the user') ); - return $form; + return system_settings_form($form); } @@ -92,27 +102,16 @@ if (!_captcha_validate($_POST['edit']['captcha_response'])) { //use call_func because module_invoke does not allow call by reference. if (module_hook($captcha_type, 'captchachallenge')) { - call_user_func_array($captcha_type.'_captchachallenge', array(&$form, &$_SESSION['captcha'])); + call_user_func_array($captcha_type.'_captchachallenge', array(&$form)); } } } } -/** -* On submit, captcha is reset -*/ -function captcha_submit() { - if($_SESSION['captcha_correct']) { - unset($_SESSION['captcha_correct']); - unset($_SESSION['captcha']); - } -} - function _captcha_validate($captcha_response) { - if ($_SESSION['captcha_correct']) return TRUE; if (is_array($captcha_response)) $captcha_response = $captcha_response['#value']; if (trim($captcha_response) == '') return FALSE; @@ -121,16 +120,16 @@ $trigger = NULL; if (module_hook($captcha_type, 'captchavalidate')) { - call_user_func_array($captcha_type.'_captchavalidate', array(&$captcha_response, &$_SESSION['captcha_correct'])); + call_user_func_array($captcha_type.'_captchavalidate', array(&$captcha_response, &$captcha_correct)); } - return $_SESSION['captcha_correct']; + return $captcha_correct; } /* * Default implementation of the captcha challenge & validation */ -function captcha_captchachallenge(&$form, &$captcha) { +function captcha_captchachallenge(&$form) { $x = rand(1,10); $y = rand(1,10); @@ -145,12 +144,15 @@ '#required' => TRUE, '#validate' => array('_captcha_validate' => array()) ); - + $form['captcha_key'] = array ( + '#type' => 'hidden', + '#value' => drupal_get_token($captcha), + ); } function captcha_captchavalidate(&$captcha_word, &$correct) { $captcha_word = drupal_strtolower($captcha_word); - if ($captcha_word == $_SESSION['captcha']) { + if (drupal_get_token($captcha_word) == $_POST['captcha_key']) { $correct = TRUE; } else { Index: modules/captcha/captcha.info =================================================================== RCS file: sites/all/modules/captcha/captcha.info diff -N modules/captcha/captcha.info --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ modules/captcha/captcha.info 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,3 @@ +; $Id: captcha.info,v 1.0 2006/12/21 01:06:58 mfer Exp $ +name = Captcha +description = Adds a Captcha to the registration form.