Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add recaptcha for user notes

  • Loading branch information...
commit b02a7d750332c9658b3cb467fb206296a529352b 1 parent 8110d0d
Daniel O'Connor CloCkWeRX authored
4 include/pear-config.php
View
@@ -44,6 +44,8 @@
define('PEAR_WIKI_DSN', $_ENV['PEAR_WIKI_DSN']);
define('PEARWEB_BUGS_ML_EMAIL', $_ENV['PEARWEB_BUGS_ML_EMAIL']);
define('PEAR_DOCUMENTATION_ENGINE', $_ENV['PEAR_DOCUMENTATION_ENGINE']);
+ define('PEAR_RECAPTCHA_PUBLIC_KEY', $_ENV['PEAR_RECAPTCHA_PUBLIC_KEY']);
+ define('PEAR_RECAPTCHA_PRIVATE_KEY', $_ENV['PEAR_RECAPTCHA_PRIVATE_KEY']);
} else {
define('SITE', 'pear');
define('SITE_BIG', strtoupper(SITE));
@@ -106,6 +108,8 @@
define('PROPOSAL_MAIL_FROM', 'PEPr <bounce-no-user@php.net>');
define('PEAR_DOCUMENTATION_ENGINE', 'phpdocumentor');
+ define('PEAR_RECAPTCHA_PUBLIC_KEY', '6LdpSdgSAAAAAHXwkhHNrWZb2Mc-VAIxX8BI-dK6');
+ define('PEAR_RECAPTCHA_PRIVATE_KEY', '');
}
if (isset($_ENV['PEARWEB_PROTOCOL'])) {
8 public_html/notes/add-note-form.php
View
@@ -6,12 +6,10 @@
*/
define ('NOTE_ADD_ERROR_NO_URI', 'No URI passed to the form');
-/**
- * Numeral Captcha Class
- */
-require_once 'Text/CAPTCHA/Numeral.php';
+require_once 'Services/ReCaptcha.php';
+
+$captcha = new Services_ReCaptcha(PEAR_RECAPTCHA_PUBLIC_KEY, PEAR_RECAPTCHA_PRIVATE_KEY);
-$captcha = new Text_CAPTCHA_Numeral();
/**
* This parameter should be passed from the
20 public_html/notes/add-note.php
View
@@ -1,8 +1,12 @@
<?php
+require_once 'Services/ReCaptcha.php';
+
+$captcha = new Services_ReCaptcha(PEAR_RECAPTCHA_PUBLIC_KEY, PEAR_RECAPTCHA_PRIVATE_KEY);
+
session_start();
$post = $_POST;
-unset($_POST);
+
$loggedin = isset($auth_user) && $auth_user->registered;
@@ -46,18 +50,8 @@
* If the captcha is wrong, then regenerate it.
*/
if (!$loggedin) {
- if (!isset($_SESSION['answer']) || strlen(trim($_SESSION['answer'])) == 0) {
- $errors[] = 'Please activate cookies';
-
- } else if ($post['answer'] != $_SESSION['answer']) {
-
- $errors[] = 'Incorrect Captcha';
-
- require_once 'Text/CAPTCHA/Numeral.php';
-
- $captcha = new Text_CAPTCHA_Numeral();
- $spamCheck = $captcha->getOperation();
- $_SESSION['answer'] = $captcha->getAnswer();
+ if (!$captcha->validate()) {
+ $errors[] = 'Incorrect Captcha';
}
/**
* @todo Check akismet here aswell ?
9 templates/notes/add-note-form.tpl.php
View
@@ -2,7 +2,7 @@
<h1>Add a Note to <?php echo htmlspecialchars($noteUrl) ?></h1>
<?php
require 'pear-manual.php';
-// {{{ isset($error)
+
if (isset($errors)) {
?>
@@ -11,7 +11,6 @@
echo '<div class="errors">', htmlspecialchars($error), '</div>';
}
}
-// }}}
?>
<p>
@@ -57,8 +56,10 @@
</tr>
<?php if (!$loggedin) { ?>
<tr>
- <th class="form-label_left">Solve this: "<?php echo $spamCheck?> = ?"<br/></th>
- <td class="form-input"><input name="answer" size="40" maxlength="10" type="text"></td>
+ <th class="form-label_left"><br/></th>
+ <td class="form-input">
+ <?php print $captcha; ?>
+ </td>
</tr>
<?php } // if ($loggedin) ?>
<tr>
Please sign in to comment.
Something went wrong with that request. Please try again.