Skip to content
This repository was archived by the owner on Oct 20, 2023. It is now read-only.

Commit 82e6d55

Browse files
authored
Merge pull request #50 from CakeDC/develop
merge develop branch
2 parents 755fcd4 + 77053c5 commit 82e6d55

File tree

15 files changed

+262
-144
lines changed

15 files changed

+262
-144
lines changed

.travis.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
language: php
2+
3+
php:
4+
- 5.5
5+
- 5.6
6+
- 7.0
7+
env:
8+
global:
9+
- PLUGIN_NAME=Recaptcha
10+
- DB=mysql
11+
- MYSQL_CREATE_DB="mysql -e 'create database cakephp_test CHARACTER SET utf8 COLLATE utf8_general_ci;'"
12+
- REQUIRE="phpunit/phpunit:3.7.31"
13+
14+
matrix:
15+
- DB=mysql CAKE_VERSION=2.7
16+
17+
matrix:
18+
include:
19+
- php: 5.5
20+
env:
21+
- CAKE_VERSION=2.7
22+
- php: 5.6
23+
env:
24+
- CAKE_VERSION=2.7
25+
- php: 7.0
26+
env:
27+
- CAKE_VERSION=2.8
28+
before_script:
29+
- git clone https://github.com/steinkel/travis.git --depth 1 ../travis
30+
- ../travis/before_script.sh
31+
- if [ "$PHPCS" != 1 ]; then
32+
echo "
33+
require_once APP . DS . 'vendor' . DS . 'phpunit' . DS . 'phpunit' . DS . 'PHPUnit' . DS . 'Autoload.php';
34+
" >> ../cakephp/app/Config/bootstrap.php;
35+
fi
36+
37+
script:
38+
- ../travis/script.sh
39+
40+
after_success:
41+
- ../travis/after_success.sh
42+
43+
notifications:
44+
email: false
45+

Controller/Component/RecaptchaComponent.php

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class RecaptchaComponent extends Component {
3232
*
3333
* @var string
3434
*/
35-
public $apiUrl = 'http://www.google.com/recaptcha/api/verify';
35+
public $apiUrl = 'https://www.google.com/recaptcha/api/siteverify';
3636

3737
/**
3838
* Private API Key
@@ -119,11 +119,17 @@ public function initialize(Controller $controller, $settings = array()) {
119119
* @return void
120120
*/
121121
public function startup(Controller $controller) {
122-
extract($this->settings);
122+
$modelClass = Hash::get($this->settings, 'modelClass');
123+
$errorField = Hash::get($this->settings, 'errorField');
124+
125+
if (!($this->Controller->{$modelClass} instanceof Model)) {
126+
return;
127+
}
128+
123129
$this->Controller->helpers[] = 'Recaptcha.Recaptcha';
124-
$this->Controller->{$modelClass}->Behaviors->load('Recaptcha.Recaptcha', array(
125-
'field' => $errorField
126-
));
130+
$this->Controller->{$modelClass}->Behaviors->load('Recaptcha.Recaptcha', [
131+
'field' => $errorField,
132+
]);
127133

128134
$this->Controller->{$modelClass}->recaptcha = true;
129135
if (in_array($this->Controller->action, $this->actions)) {
@@ -143,42 +149,34 @@ public function startup(Controller $controller) {
143149
* @return boolean True if the response was correct
144150
*/
145151
public function verify() {
146-
if (isset($this->Controller->request->data['recaptcha_challenge_field']) &&
147-
isset($this->Controller->request->data['recaptcha_response_field'])) {
148-
149-
$response = $this->_getApiResponse();
150-
$response = explode("\n", $response->body());
151-
152-
if (empty($response[0])) {
153-
$this->error = __d('recaptcha', 'Invalid API response, please contact the site admin.', true);
154-
return false;
155-
}
152+
if (!isset($this->Controller->request->data['g-recaptcha-response'])) {
153+
return false;
154+
}
156155

157-
if ($response[0] === 'true') {
158-
return true;
159-
}
156+
$response = $this->_getApiResponse();
157+
if (!$response = json_decode($response->body())) {
158+
$this->error = __d('recaptcha', 'Invalid API response, please contact the site admin.', true);
159+
return false;
160+
}
160161

161-
if ($response[1] === 'incorrect-captcha-sol') {
162-
$this->error = __d('recaptcha', 'Incorrect captcha', true);
163-
} else {
164-
$this->error = $response[1];
165-
}
162+
if (!$response->success) {
163+
$this->error = __d('recaptcha', 'Incorrect captcha', true);
166164
}
167-
return false;
165+
166+
return $response->success;
168167
}
169168

170169
/**
171170
* Queries the Recaptcha API and and returns the raw response
172171
*
173-
* @return string
172+
* @return HttpSocketResponse
174173
*/
175174
protected function _getApiResponse() {
176175
$Socket = new HttpSocket();
177176
return $Socket->post($this->apiUrl, array(
178-
'privatekey' => $this->privateKey,
177+
'secret' => $this->privateKey,
179178
'remoteip' => env('REMOTE_ADDR'),
180-
'challenge' => $this->Controller->request->data['recaptcha_challenge_field'],
181-
'response' => $this->Controller->request->data['recaptcha_response_field']
179+
'response' => $this->Controller->request->data['g-recaptcha-response'],
182180
));
183181
}
184182

Docs/Documentation/Installation.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ Installation
33

44
To install the plugin, place the files in a directory labelled "Recaptcha/" in your "app/Plugin/" directory.
55

6+
Then, include the following line in your `app/Config/bootstrap.php` to load the plugin in your application.
7+
8+
```
9+
CakePlugin::load('Recaptcha');
10+
```
11+
612
Git Submodule
713
-------------
814

@@ -33,4 +39,4 @@ If any updates are added, go back to the base of your own repository, commit and
3339
Composer
3440
--------
3541

36-
The plugin also provides a "composer.json" file, to easily use the plugin through the Composer dependency manager.
42+
The plugin also provides a "composer.json" file, to easily use the plugin through the Composer dependency manager.

Docs/Documentation/Setup.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,24 @@ In the view simply call the helpers `display()` method to render the recaptcha i
2323
echo $this->Recaptcha->display();
2424
```
2525

26-
You could select another theme, setup it as parameter, for istance:
26+
To render multiple recatpchas on a page, pass `['explicit' => true]`:
27+
28+
```php
29+
echo $this->Recaptcha->display(['explicit' => true]);
30+
```
31+
32+
You could select another theme, setup it as parameter, for instance:
2733

2834
```php
2935
echo $this->Recaptcha->display(array(
3036
'recaptchaOptions' => array(
31-
'theme' => 'blackglass'
37+
'theme' => 'dark'
3238
)
3339
)
3440
);
3541
```
3642

37-
For the complete list of themes, take a look here: [http://code.google.com/intl/it-IT/apis/recaptcha/docs/customization.html](http://code.google.com/intl/it-IT/apis/recaptcha/docs/customization.html).
43+
For the complete list of configuration options, take a look here: [https://developers.google.com/recaptcha/docs/display#config](https://developers.google.com/recaptcha/docs/display#config). Please note you don't need to prefix option names with `data-`.
3844

3945
To check the result simply do something like this in your controller:
4046

Locale/deu/LC_MESSAGES/recaptcha.po

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@ msgid "To use reCAPTCHA Mailhide, you need to have the mcrypt php module install
3030
msgstr "Um reCAPTCHA Mailhide nutzen zu können muss das mcrypt PHP-Modul installiert werden."
3131

3232
#: View/Helper/RecaptchaHelper.php:207
33-
msgid "You need to set a private and public mail hide key. Please visit http://mailhide.recaptcha.net/apikey"
34-
msgstr "Es muss ein privater und öffentlicher mail hide Schlüssel erstellt werden. Bitte besuchen Sie: http://mailhide.recaptcha.net/apikey"
33+
msgid "You need to set a private and public mail hide key. Please visit https://www.google.com/recaptcha/mailhide/apikey"
34+
msgstr "Es muss ein privater und öffentlicher mail hide Schlüssel erstellt werden. Bitte besuchen Sie: https://www.google.com/recaptcha/mailhide/apikey"
3535

Locale/fre/LC_MESSAGES/recaptcha.po

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ msgid "To use reCAPTCHA Mailhide, you need to have the mcrypt php module install
2828
msgstr "Afin d'utiliser reCAPTCHA Mailhide, vous devez avoir le module php mcrypt installé."
2929

3030
#: View/Helper/RecaptchaHelper.php:207
31-
msgid "You need to set a private and public mail hide key. Please visit http://mailhide.recaptcha.net/apikey"
32-
msgstr "Vous devez définir les clés publique et privée mailhide. Veuillez visiter http://mailhide.recaptcha.net/apikey"
31+
msgid "You need to set a private and public mail hide key. Please visit https://www.google.com/recaptcha/mailhide/apikey"
32+
msgstr "Vous devez définir les clés publique et privée mailhide. Veuillez visiter https://www.google.com/recaptcha/mailhide/apikey"
3333

Locale/ita/LC_MESSAGES/recaptcha.po

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,6 @@ msgid "To use reCAPTCHA Mailhide, you need to have the mcrypt php module install
4040
msgstr "Per utilizzare reCAPTCHA Mailhide, devi aver istallato il modulo php mcrypt."
4141

4242
#: View/Helper/RecaptchaHelper.php:207
43-
msgid "You need to set a private and public mail hide key. Please visit http://mailhide.recaptcha.net/apikey"
44-
msgstr "Devi registrare reCAPTCHA Mailhide API key. http://mailhide.recaptcha.net/apikey"
43+
msgid "You need to set a private and public mail hide key. Please visit https://www.google.com/recaptcha/mailhide/apikey"
44+
msgstr "Devi registrare reCAPTCHA Mailhide API key. https://www.google.com/recaptcha/mailhide/apikey"
4545

Locale/por/LC_MESSAGES/recaptcha.po

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,6 @@ msgid "To use reCAPTCHA Mailhide, you need to have the mcrypt php module install
4040
msgstr "Para usar o reCAPTCHA Mailhide, você precisa ter o módulo php mcrypt instalado."
4141

4242
#: View/Helper/RecaptchaHelper.php:207
43-
msgid "You need to set a private and public mail hide key. Please visit http://mailhide.recaptcha.net/apikey"
44-
msgstr "Você precisa configurar uma chave privada e pública. Por favor, visite http://mailhide.recaptcha.net/apikey"
43+
msgid "You need to set a private and public mail hide key. Please visit https://www.google.com/recaptcha/mailhide/apikey"
44+
msgstr "Você precisa configurar uma chave privada e pública. Por favor, visite https://www.google.com/recaptcha/mailhide/apikey"
4545

Locale/recaptcha.pot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ msgid "To use reCAPTCHA Mailhide, you need to have the mcrypt php module install
3131
msgstr ""
3232

3333
#: View/Helper/RecaptchaHelper.php:207
34-
msgid "You need to set a private and public mail hide key. Please visit http://mailhide.recaptcha.net/apikey"
34+
msgid "You need to set a private and public mail hide key. Please visit https://www.google.com/recaptcha/mailhide/apikey"
3535
msgstr ""
3636

Locale/spa/LC_MESSAGES/recaptcha.po

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,6 @@ msgid "To use reCAPTCHA Mailhide, you need to have the mcrypt php module install
4141
msgstr "Para usar la función de oculatar emails de reCAPTCHA , debes tener el modulo mcrypt de php instalado."
4242

4343
#: View/Helper/RecaptchaHelper.php:207
44-
msgid "You need to set a private and public mail hide key. Please visit http://mailhide.recaptcha.net/apikey"
45-
msgstr "Debes configurar tus claves públicas y privadas de \"mail hide\". Por favor visita http://mailhide.recaptcha.net/apikey"
44+
msgid "You need to set a private and public mail hide key. Please visit https://www.google.com/recaptcha/mailhide/apikey"
45+
msgstr "Debes configurar tus claves públicas y privadas de \"mail hide\". Por favor visita https://www.google.com/recaptcha/mailhide/apikey"
4646

0 commit comments

Comments
 (0)