Skip to content
This repository was archived by the owner on Nov 28, 2019. It is now read-only.

Patch 2 #61

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions _config.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
/**
* @package recaptcha
*/
// Ensure compatibility with PHP 7.2 ("object" is a reserved word),
// with SilverStripe 3.6 (using Object) and SilverStripe 3.7 (using SS_Object)
if (!class_exists('SS_Object')) class_alias('Object', 'SS_Object');
20 changes: 11 additions & 9 deletions code/RecaptchaField.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,14 @@ public function Field($properties = array())
*/
public function validate($validator)
{
/** @var array $request */
/** @var array $postVars */
if(SapphireTest::is_running_test()) {
$request = $_REQUEST;
$postVars = $_REQUEST;
} else {
$request = Controller::curr()->getRequest();
$postVars = Controller::curr()->getRequest()->postVars();
}
// don't bother querying the recaptcha-service if fields were empty
if (!array_key_exists('g-recaptcha-response', $request) || empty($request['g-recaptcha-response'])) {
if (!array_key_exists('g-recaptcha-response', $postVars) || empty($postVars['g-recaptcha-response'])) {
$validator->validationError(
$this->name,
_t(
Expand All @@ -181,7 +181,7 @@ public function validate($validator)
return false;
}

$response = $this->recaptchaHTTPPost($_REQUEST['g-recaptcha-response']);
$response = $this->recaptchaHTTPPost($postVars['g-recaptcha-response']);

if (!$response) {
$validator->validationError(
Expand Down Expand Up @@ -288,10 +288,12 @@ class RecaptchaField_HTTPClient extends Object
public function post($url, $postVars)
{
$ch = curl_init($url);
if (!empty(RecaptchaField::$proxy_server)) {
curl_setopt($ch, CURLOPT_PROXY, RecaptchaField::$proxy_server);
if (!empty(RecaptchaField::$proxy_auth)) {
curl_setopt($ch, CURLOPT_PROXYUSERPWD, RecaptchaField::$proxy_auth);
$proxyServer = Config::inst()->get('RecaptchaField', 'proxy_server');
if (!empty($proxyServer)) {
curl_setopt($ch, CURLOPT_PROXY, $proxyServer);
$proxyAuth = Config::inst()->get('RecaptchaField', 'proxy_auth');
if (!empty($proxyAuth)) {
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyAuth);
}
}

Expand Down