Skip to content

Commit

Permalink
Merge pull request #30 from domstubbs/master
Browse files Browse the repository at this point in the history
Include 'remoteip' with verify requests where possible
  • Loading branch information
matt-west authored Jan 17, 2022
2 parents d311dab + 1b618c8 commit 2262634
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@
"siteKey" => "",
"secretKey" => "",
"validateContactForm" => true,

"shareUserIPs" => false,

];
7 changes: 7 additions & 0 deletions src/models/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ class Settings extends Model
*/
public $validateContactForm = true;

/**
* Share user IP addresses with Google
*
* @var bool
*/
public $shareUserIPs = false;



// Public Methods
Expand Down
8 changes: 8 additions & 0 deletions src/services/CraftRecaptchaService.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ public function verify($data)
'response' => $data
);

if ($settings->shareUserIPs) {
$ip = Craft::$app->getRequest()->userIP;

if ($ip) {
$params['remoteip'] = $ip;
}
}

$client = new GuzzleHttp\Client();
$response = $client->request('POST', $base, ['form_params' => $params]);

Expand Down
8 changes: 8 additions & 0 deletions src/templates/settings.twig
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,11 @@
name: 'validateContactForm',
on: settings['validateContactForm']})
}}

{{ forms.lightswitchField({
label: 'Share user IPs with Google?'|t('recaptcha'),
instructions: 'Enable to include requesting user IP addresses when making [siteverify](https://developers.google.com/recaptcha/docs/verify#api_request) requests.'|t('recaptcha'),
id: 'shareUserIPs',
name: 'shareUserIPs',
on: settings['shareUserIPs']})
}}
1 change: 1 addition & 0 deletions src/translations/en/recaptcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@
'Enter your reCAPTCHA site key.' => 'Enter your reCAPTCHA site key.',
'Enter your reCAPTCHA secret key.' => 'Enter your reCAPTCHA secret key.',
'Validate contact forms?' => 'Validate contact forms?',
'Share user IPs with Google?' => 'Share user IPs with Google?',
];

0 comments on commit 2262634

Please sign in to comment.