Permalink
Browse files

MDL-13796 Most of the recaptcha implementation is done.

  • Loading branch information...
1 parent 688df12 commit 49e1894df376d6baea4f52036af5355f06f3f437 nicolasconnault committed Mar 10, 2008
View
@@ -25,7 +25,9 @@
get_string('authinstructions', 'auth'), ''));
$temp->add(new admin_setting_configtext('allowemailaddresses', get_string('allowemailaddresses', 'admin'), get_string('configallowemailaddresses', 'admin'), '', PARAM_NOTAGS));
$temp->add(new admin_setting_configtext('denyemailaddresses', get_string('denyemailaddresses', 'admin'), get_string('configdenyemailaddresses', 'admin'), '', PARAM_NOTAGS));
-
+
+ $temp->add(new admin_setting_configtext('recaptchapublickey', get_string('recaptchapublickey', 'admin'), get_string('configrecaptchapublickey', 'admin'), '', PARAM_NOTAGS));
+ $temp->add(new admin_setting_configtext('recaptchaprivatekey', get_string('recaptchaprivatekey', 'admin'), get_string('configrecaptchaprivatekey', 'admin'), '', PARAM_NOTAGS));
$ADMIN->add('authsettings', $temp);
View
@@ -197,6 +197,13 @@ function config_form($config, $err, $user_fields) {
* Processes and stores configuration data for this authentication plugin.
*/
function process_config($config) {
+ // set to defaults if undefined
+ if (!isset($config->recaptcha)) {
+ $config->recaptcha = false;
+ }
+
+ // save settings
+ set_config('recaptcha', $config->recaptcha, 'auth/email');
return true;
}
View
@@ -1,7 +1,25 @@
<!-- No config needed -->
-<div style="text-align: center"><?php print_string('none'); ?></div>
+<?php
+ // set to defaults if undefined
+ if (!isset($config->recaptcha)) {
+ $config->recaptcha = false;
+ }
+
+ $yesno = array( get_string('no'), get_string('yes') );
+
+?>
<table cellspacing="0" cellpadding="5" border="0">
+<tr>
+ <td colspan="3">
+ <h2 class="main"><?php print_string('auth_emailsettings', 'auth') ?> </h2>
+ </td>
+</tr>
+<tr>
+ <td align="right"><label for="recaptcha"><?php print_string('auth_emailrecaptcha_key', 'auth') ?></label></td>
+ <td><?php choose_from_menu($yesno, 'recaptcha', $config->recaptcha, ''); ?></td>
+ <td><?php print_string('auth_emailrecaptcha', 'auth') ?></td>
+</tr>
<?php
print_auth_lock_options('email', $user_fields, get_string('auth_fieldlocks_help', 'auth'), false, false);
View
@@ -188,6 +188,8 @@
</pre>If this is left empty, no password is required.';
$string['configrcache'] = 'Use the cache to store database records. Remember to set \'cachetype\' as well!';
$string['configrcachettl'] = 'Time-to-live for cached records, in seconds. Use a short (&lt;15) value here.';
+$string['configrecaptchaprivatekey'] = 'String of characters used to communicate between your Moodle server and the recaptcha.net server. Obtain one for this site by visiting http://recaptcha.net';
+$string['configrecaptchapublickey'] = 'String of characters used to display the reCAPTCHA element in the signup form. Generated by http://recaptcha.net';
$string['configrequestedstudentname'] = 'Word for student used in requested courses';
$string['configrequestedstudentsname'] = 'Word for students used in requested courses';
$string['configrequestedteachername'] = 'Word for teacher used in requested courses';
@@ -586,6 +588,8 @@
$string['questioncwqpfsok'] = 'Good. There are no \'random\' questions in your quizzes that are set up to select questions from a mixture of shared and unshared question categories.';
$string['rcache'] = 'Record cache';
$string['rcachettl'] = 'Record cache TTL';
+$string['recaptchapublickey'] = 'ReCAPTCHA public key';
+$string['recaptchaprivatekey'] = 'ReCAPTCHA private key';
$string['releasenoteslink'] = 'For information about this version of Moodle, please see the online <a target=\"_blank\" href=\"$a\">Release Notes</a>';
$string['remotelangnotavailable'] = 'Because Moodle can not connect to download.moodle.org, we are unable to do language pack installation automatically. Please download the appropriate zip file(s) from the list below, copy them to your $a directory and unzip them manually.';
$string['renameerrors'] = 'Rename errors';
View
@@ -117,6 +117,9 @@
$string['auth_emailtitle'] = 'Email-based self-registration';
$string['auth_emailnoinsert'] = 'Could not add your record to the database!';
$string['auth_emailnoemail'] = 'Tried to send you an email but failed!';
+$string['auth_emailrecaptcha'] = 'Adds a visual/audio confirmation form element to the signup page for email self-registering users. This protects your site against spammers and contributes to a worthwhile cause. See http://recaptcha.net/learnmore.html for more details.';
+$string['auth_emailrecaptcha_key'] = 'Enable reCAPTCHA element';
+$string['auth_emailsettings'] = 'Settings';
// FirstClass plugin
$string['auth_fccreators'] = 'List of groups whose members are allowed to create new courses. Separate multiple groups with \';\'. Names must be spelled exactly as on FirstClass server. System is case-sensitive.';
@@ -374,5 +377,10 @@
$string['unlocked'] = 'Unlocked';
$string['unlockedifempty'] = 'Unlocked if empty';
$string['locked'] = 'Locked';
-
+$string['incorrectpleasetryagain'] = 'Incorrect. Please try again.';
+$string['enterthewordsabove'] = 'Enter the words above:';
+$string['enterthenumbersyouhear'] = 'Enter the numbers you hear:';
+$string['getanothercaptcha'] = 'Get another CAPTCHA';
+$string['getanaudiocaptcha'] = 'Get an audio CAPTCHA';
+$string['getanimagecaptcha'] = 'Get an image CAPTCHA';
?>
View
@@ -0,0 +1,84 @@
+<?php
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * textarea_counter.php
+ *
+ * @category Admin
+ * @package admin
+ * @author Nicolas Connault <nicolasconnault@gmail.com>
+ * @version $Id$
+ */
+
+
+/**
+ * @category Admin
+ * @package admin
+ */
+class MoodleQuickForm_recaptcha extends HTML_QuickForm_input {
+
+ /**
+ * <code>
+ * $form->addElement('textarea_counter', 'message', 'Message',
+ * array('cols'=>60, 'rows'=>10), 160);
+ * </code>
+ */
+ function HTML_QuickForm_recaptcha($elementName = null, $elementLabel = null, $attributes = null) {
+ parent::HTML_QuickForm_input($elementName, $elementLabel, $attributes);
+ $this->_type = 'recaptcha';
+ }
+
+ /**
+ * Returns the recaptcha element in HTML
+ *
+ * @since 1.0
+ * @access public
+ * @return string
+ */
+ function toHtml() {
+ global $CFG;
+ require_once $CFG->libdir . '/recaptchalib.php';
+
+ $html = '<script type="text/javascript">
+ var RecaptchaOptions = {
+ theme : \'custom\',
+ tabindex : 2,
+ custom_theme_widget : \'recaptcha_widget\'
+ };
+ </script>' . "\n";
+
+
+ if (empty($_SESSION['recaptcha_error'])) {
+ $_SESSION['recaptcha_error'] = null;
+ }
+ $error = $_SESSION['recaptcha_error'];
+ unset($_SESSION['recaptcha_error']);
+
+ $strincorrectpleasetryagain = get_string('incorrectpleasetryagain', 'auth');
+ $strenterthewordsabove = get_string('enterthewordsabove', 'auth');
+ $strenterthenumbersyouhear = get_string('enterthenumbersyouhear', 'auth');
+ $strgetanothercaptcha = get_string('getanothercaptcha', 'auth');
+ $strgetanaudiocaptcha = get_string('getanaudiocaptcha', 'auth');
+ $strgetanimagecaptcha = get_string('getanimagecaptcha', 'auth');
+
+ $html .= '
+<div id="recaptcha_widget" style="display:none">
+
+<div id="recaptcha_image"></div>
+<div class="recaptcha_only_if_incorrect_sol" style="color:red">' . $strincorrectpleasetryagain . '</div>
+
+<span class="recaptcha_only_if_image">' . $strenterthewordsabove . '</span>
+<span class="recaptcha_only_if_audio">' . $strenterthenumbersyouhear . '</span>
+
+<input type="text" id="recaptcha_response_field" name="recaptcha_response_field" />
+
+<div><a href="javascript:Recaptcha.reload()">' . $strgetanothercaptcha . '</a></div>
+<div class="recaptcha_only_if_image"><a href="javascript:Recaptcha.switch_type(\'audio\')">' . $strgetanaudiocaptcha . '</a></div>
+<div class="recaptcha_only_if_audio"><a href="javascript:Recaptcha.switch_type(\'image\')">' . $strgetanimagecaptcha . '</a></div>
+</div>';
+
+ return $html . recaptcha_get_html($CFG->recaptchapublickey, $error);
+ }
+}
+
+?>
View
@@ -1876,4 +1876,5 @@ function getStopFieldsetElements(){
MoodleQuickForm::registerElementType('submit', "$CFG->libdir/form/submit.php", 'MoodleQuickForm_submit');
MoodleQuickForm::registerElementType('questioncategory', "$CFG->libdir/form/questioncategory.php", 'MoodleQuickForm_questioncategory');
MoodleQuickForm::registerElementType('advcheckbox', "$CFG->libdir/form/advcheckbox.php", 'MoodleQuickForm_advcheckbox');
+MoodleQuickForm::registerElementType('recaptcha', "$CFG->libdir/form/recaptcha.php", 'MoodleQuickForm_recaptcha');
?>
Oops, something went wrong.

0 comments on commit 49e1894

Please sign in to comment.