Skip to content

Commit 251594d

Browse files
committed
Fixed lang for url, and fixed typo and backward compitablity
1 parent 36a7b63 commit 251594d

File tree

5 files changed

+26
-20
lines changed

5 files changed

+26
-20
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ This package requires the following dependencies:
9797
Via Composer
9898

9999
``` sh
100-
$ composer require timehunter/laravel-google-recaptcha-v3 "~2.4.4" -vvv
100+
$ composer require timehunter/laravel-google-recaptcha-v3 "~2.5" -vvv
101101
```
102102

103103
If your Laravel framework version <= 5.4, please register the service provider under your config file: /config/app.php, otherwise please skip it.
@@ -156,12 +156,12 @@ Specify your Score threshold and action in 'setting', e.g.
156156
[
157157
'action' => 'contact_us', // Google reCAPTCHA required paramater
158158
'threshold' => 0.2, // score threshold
159-
'score_comparision' => false // if this is true, the system will do score comparsion against your threshold for the action
159+
'score_comparison' => false // if this is true, the system will do score comparsion against your threshold for the action
160160
],
161161
[
162162
'action' => 'signup',
163163
'threshold' => 0.2,
164-
'score_comparision' => true
164+
'score_comparison' => true
165165
],
166166
]
167167

config/googlerecaptchav3.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,13 @@
105105
| Define your score threshold, define your action
106106
| action: Google reCAPTCHA required parameter
107107
| threshold: score threshold
108-
| score_comparision: true/false, if this is true, the system will do score comparision against your threshold for the action
108+
| score_comparison: true/false, if this is true, the system will do score comparision against your threshold for the action
109109
*/
110110
'setting' => [
111111
[
112112
'action' => 'contact_us',
113113
'threshold' => 0,
114-
'score_comparision' => false,
114+
'score_comparison' => false,
115115
],
116116
],
117117

src/Services/GoogleReCaptchaV3Service.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function ifInSkippedIps($ip)
4444
*/
4545
public function verifyResponse($response, $ip = null)
4646
{
47-
if (! $this->config->isServiceEnabled() || ($ip && $this->ifInSkippedIps($ip)) === true) {
47+
if (!$this->config->isServiceEnabled() || ($ip && $this->ifInSkippedIps($ip)) === true) {
4848
$res = new GoogleReCaptchaV3Response([], $ip);
4949
$res->setSuccess(true);
5050

@@ -85,7 +85,7 @@ public function verifyResponse($response, $ip = null)
8585
return $rawResponse;
8686
}
8787

88-
if (! empty($this->config->getHostName()) && strcasecmp($this->config->getHostName(), $rawResponse->getHostname()) !== 0) {
88+
if (!empty($this->config->getHostName()) && strcasecmp($this->config->getHostName(), $rawResponse->getHostname()) !== 0) {
8989
$rawResponse->setMessage(Lang::get(GoogleReCaptchaV3Response::ERROR_HOSTNAME));
9090
$rawResponse->setSuccess(false);
9191

@@ -107,12 +107,18 @@ public function verifyResponse($response, $ip = null)
107107
} else {
108108
if ($this->getConfig()->isScoreEnabled()) {
109109
$count = collect($this->getConfig()->getSetting())
110+
->where('action', '=', $rawResponse->getAction())
111+
->where('score_comparison', '=', true)
112+
->where('threshold', '>', $rawResponse->getScore())
113+
->count();
114+
115+
$oldCount = collect($this->getConfig()->getSetting())
110116
->where('action', '=', $rawResponse->getAction())
111117
->where('score_comparision', '=', true)
112118
->where('threshold', '>', $rawResponse->getScore())
113119
->count();
114120

115-
if ($count > 0) {
121+
if ($count > 0 || $oldCount > 0) {
116122
$rawResponse->setSuccess(false);
117123
$rawResponse->setMessage(Lang::get(GoogleReCaptchaV3Response::ERROR_SCORE_THRESHOLD));
118124

tests/RequestTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function testCurlRequest()
2121

2222
$response = new GoogleReCaptchaV3Response(json_decode($response, 1), null, '');
2323
$this->assertEquals(false, $response->isSuccess());
24-
$this->assertEquals(2, count($response->getErrorCodes()));
24+
$this->assertEquals(1, count($response->getErrorCodes()));
2525
}
2626

2727
public function testCurlRequest2()
@@ -50,7 +50,7 @@ public function testGuzzleRequest()
5050

5151
$response = new GoogleReCaptchaV3Response(json_decode($response, 1), null, '');
5252
$this->assertEquals(false, $response->toArray()['success']);
53-
$this->assertEquals(2, count($response->getErrorCodes()));
53+
$this->assertEquals(1, count($response->getErrorCodes()));
5454
}
5555

5656
public function testGuzzleRequest2()

tests/ScoreTest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function testScore1()
2828
[
2929
'action' => 'contact_us',
3030
'threshold' => 1,
31-
'score_comparision' => true,
31+
'score_comparison' => true,
3232
],
3333
]);
3434

@@ -63,7 +63,7 @@ public function testScore2()
6363
[
6464
'action' => 'contact_us',
6565
'threshold' => 1,
66-
'score_comparision' => true,
66+
'score_comparison' => true,
6767
],
6868
]);
6969

@@ -97,7 +97,7 @@ public function testScore3()
9797
[
9898
'action' => 'contact_us',
9999
'threshold' => 1,
100-
'score_comparision' => false,
100+
'score_comparison' => false,
101101
],
102102
]);
103103

@@ -131,7 +131,7 @@ public function testScore4()
131131
[
132132
'action' => 'contact_us',
133133
'threshold' => 0.9,
134-
'score_comparision' => true,
134+
'score_comparison' => true,
135135
],
136136
]);
137137

@@ -165,7 +165,7 @@ public function testScore5()
165165
[
166166
'action' => 'contact_us',
167167
'threshold' => 0.91,
168-
'score_comparision' => true,
168+
'score_comparison' => true,
169169
],
170170
]);
171171

@@ -200,7 +200,7 @@ public function testScore6()
200200
[
201201
'action' => 'contact_us_test',
202202
'threshold' => 0.91,
203-
'score_comparision' => true,
203+
'score_comparison' => true,
204204
],
205205
]);
206206

@@ -234,7 +234,7 @@ public function testScore7()
234234
[
235235
'action' => 'contact_us_test',
236236
'threshold' => 0.91,
237-
'score_comparision' => true,
237+
'score_comparison' => true,
238238
],
239239
]);
240240

@@ -268,7 +268,7 @@ public function testScore11()
268268
[
269269
'action' => 'contact_us',
270270
'threshold' => 0.91,
271-
'score_comparision' => true,
271+
'score_comparison' => true,
272272
],
273273
]);
274274

@@ -302,7 +302,7 @@ public function testScore8()
302302
[
303303
'action' => 'contact_us',
304304
'threshold' => 0.91,
305-
'score_comparision' => true,
305+
'score_comparison' => true,
306306
],
307307
]);
308308

@@ -336,7 +336,7 @@ public function testScore12()
336336
[
337337
'action' => 'contact_us',
338338
'threshold' => 0.6,
339-
'score_comparision' => true,
339+
'score_comparison' => true,
340340
],
341341
]);
342342

0 commit comments

Comments
 (0)