summaryrefslogtreecommitdiff
path: root/apps/um/plugins/ReCaptcha.class.php
diff options
context:
space:
mode:
authorLuke Shumaker <LukeShu@sbcglobal.net>2012-01-07 08:21:00 -0800
committerLuke Shumaker <LukeShu@sbcglobal.net>2012-01-07 10:20:28 -0800
commit464f4d3497617fadb9d7752868f1175849cfa6d2 (patch)
tree0771bd935b30971bf2c244b6f158ed7496b644e5 /apps/um/plugins/ReCaptcha.class.php
parent3d64793a1ee45857856be1cd71c3a0a040a3e869 (diff)
Refactor to separate the framework from the app; drop message stuff, this app is just user management. Add a json view for individual usersHEADmaster
Diffstat (limited to 'apps/um/plugins/ReCaptcha.class.php')
-rw-r--r--apps/um/plugins/ReCaptcha.class.php47
1 files changed, 47 insertions, 0 deletions
diff --git a/apps/um/plugins/ReCaptcha.class.php b/apps/um/plugins/ReCaptcha.class.php
new file mode 100644
index 0000000..165493b
--- /dev/null
+++ b/apps/um/plugins/ReCaptcha.class.php
@@ -0,0 +1,47 @@
+<?php
+// We only include the recaptchalib.php file when we use it because we don't
+// want it polluting the global namespace thing.
+
+class ReCaptcha extends Plugin {
+ protected $config = array('public_key'=>'',
+ 'private_key'=>'');
+ public static function description() {
+ return 'Add a reCaptcha to keep out spam users.';
+ }
+ public static function configList() {
+ return array('public_key'=>'text',
+ 'private_key'=>'text');
+ }
+ public function init() {}
+
+ private $resp = null;
+ private function getResp() {
+ if ($this->resp===null) {
+ require_once('recaptchalib.php');
+ @$response = $_POST['recaptcha_response_field'];
+ @$challenge = $_POST['recaptcha_challenge_field'];
+ $this->resp = recaptcha_check_answer($this->config['private_key'],
+ $_SERVER['REMOTE_ADDR'],
+ $challenge,
+ $response);
+ }
+ return $this->resp;
+ }
+
+ private function getError() {
+ if ($_POST["recaptcha_response_field"] && !$this->antispam_verify()) {
+ return $this->getResp()->error;
+ } else {
+ return false;
+ }
+ }
+
+ public function antispam_verify() {
+ return $this->getResp()->is_valid;
+ }
+
+ public function antispam_html() {
+ require_once('recaptchalib.php');
+ return recaptcha_get_html($this->config['public_key'], $this->getError());
+ }
+}