From: Tim Düsterhus Date: Sat, 13 Dec 2014 16:14:13 +0000 (+0100) Subject: Properly support reCAPTCHA V2 in RecaptchaForm X-Git-Tag: 2.1.0_Beta_1~36 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=8d5bb577a43b4773ac61bf08ca4dcd04ab835cb0;p=GitHub%2FWoltLab%2FWCF.git Properly support reCAPTCHA V2 in RecaptchaForm --- diff --git a/wcfsetup/install/files/lib/form/RecaptchaForm.class.php b/wcfsetup/install/files/lib/form/RecaptchaForm.class.php index 99b2f3b741..735cd8eb5c 100644 --- a/wcfsetup/install/files/lib/form/RecaptchaForm.class.php +++ b/wcfsetup/install/files/lib/form/RecaptchaForm.class.php @@ -1,6 +1,7 @@ challenge = StringUtil::trim($_POST['recaptcha_challenge_field']); - if (isset($_POST['recaptcha_response_field'])) $this->response = StringUtil::trim($_POST['recaptcha_response_field']); + if (!RECAPTCHA_PUBLICKEY || !RECAPTCHA_PRIVATEKEY) { + // V1 + if (isset($_POST['recaptcha_challenge_field'])) $this->challenge = StringUtil::trim($_POST['recaptcha_challenge_field']); + if (isset($_POST['recaptcha_response_field'])) $this->response = StringUtil::trim($_POST['recaptcha_response_field']); + } + else { + // V2 + if (isset($_POST['g-recaptcha-response'])) $this->response = $_POST['g-recaptcha-response']; + } } /** @@ -69,7 +77,15 @@ abstract class RecaptchaForm extends AbstractForm { */ protected function validateCaptcha() { if ($this->useCaptcha) { - RecaptchaHandler::getInstance()->validate($this->challenge, $this->response); + if (!RECAPTCHA_PUBLICKEY || !RECAPTCHA_PRIVATEKEY) { + // V1 + RecaptchaHandler::getInstance()->validate($this->challenge, $this->response); + } + else { + // V2 + RecaptchaHandlerV2::getInstance()->validate($this->response); + } + $this->useCaptcha = false; } } @@ -89,7 +105,17 @@ abstract class RecaptchaForm extends AbstractForm { public function assignVariables() { parent::assignVariables(); - RecaptchaHandler::getInstance()->assignVariables(); + if (!RECAPTCHA_PUBLICKEY || !RECAPTCHA_PRIVATEKEY) { + // V1 + RecaptchaHandler::getInstance()->assignVariables(); + } + else { + // V2 + WCF::getTPL()->assign(array( + 'recaptchaLegacyMode' => true + )); + } + WCF::getTPL()->assign(array( 'useCaptcha' => $this->useCaptcha ));