Skip to content

Commit

Permalink
Fixed lang for url, and fixed typo and backward compitablity
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanDaDeng committed Aug 29, 2021
1 parent 36a7b63 commit 251594d
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 20 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ This package requires the following dependencies:
Via Composer

``` sh
$ composer require timehunter/laravel-google-recaptcha-v3 "~2.4.4" -vvv
$ composer require timehunter/laravel-google-recaptcha-v3 "~2.5" -vvv
```

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

Expand Down
4 changes: 2 additions & 2 deletions config/googlerecaptchav3.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,13 @@
| Define your score threshold, define your action
| action: Google reCAPTCHA required parameter
| threshold: score threshold
| score_comparision: true/false, if this is true, the system will do score comparision against your threshold for the action
| score_comparison: true/false, if this is true, the system will do score comparision against your threshold for the action
*/
'setting' => [
[
'action' => 'contact_us',
'threshold' => 0,
'score_comparision' => false,
'score_comparison' => false,
],
],

Expand Down
12 changes: 9 additions & 3 deletions src/Services/GoogleReCaptchaV3Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function ifInSkippedIps($ip)
*/
public function verifyResponse($response, $ip = null)
{
if (! $this->config->isServiceEnabled() || ($ip && $this->ifInSkippedIps($ip)) === true) {
if (!$this->config->isServiceEnabled() || ($ip && $this->ifInSkippedIps($ip)) === true) {
$res = new GoogleReCaptchaV3Response([], $ip);
$res->setSuccess(true);

Expand Down Expand Up @@ -85,7 +85,7 @@ public function verifyResponse($response, $ip = null)
return $rawResponse;
}

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

Expand All @@ -107,12 +107,18 @@ public function verifyResponse($response, $ip = null)
} else {
if ($this->getConfig()->isScoreEnabled()) {
$count = collect($this->getConfig()->getSetting())
->where('action', '=', $rawResponse->getAction())
->where('score_comparison', '=', true)
->where('threshold', '>', $rawResponse->getScore())
->count();

$oldCount = collect($this->getConfig()->getSetting())
->where('action', '=', $rawResponse->getAction())
->where('score_comparision', '=', true)
->where('threshold', '>', $rawResponse->getScore())
->count();

if ($count > 0) {
if ($count > 0 || $oldCount > 0) {
$rawResponse->setSuccess(false);
$rawResponse->setMessage(Lang::get(GoogleReCaptchaV3Response::ERROR_SCORE_THRESHOLD));

Expand Down
4 changes: 2 additions & 2 deletions tests/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function testCurlRequest()

$response = new GoogleReCaptchaV3Response(json_decode($response, 1), null, '');
$this->assertEquals(false, $response->isSuccess());
$this->assertEquals(2, count($response->getErrorCodes()));
$this->assertEquals(1, count($response->getErrorCodes()));
}

public function testCurlRequest2()
Expand Down Expand Up @@ -50,7 +50,7 @@ public function testGuzzleRequest()

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

public function testGuzzleRequest2()
Expand Down
20 changes: 10 additions & 10 deletions tests/ScoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function testScore1()
[
'action' => 'contact_us',
'threshold' => 1,
'score_comparision' => true,
'score_comparison' => true,
],
]);

Expand Down Expand Up @@ -63,7 +63,7 @@ public function testScore2()
[
'action' => 'contact_us',
'threshold' => 1,
'score_comparision' => true,
'score_comparison' => true,
],
]);

Expand Down Expand Up @@ -97,7 +97,7 @@ public function testScore3()
[
'action' => 'contact_us',
'threshold' => 1,
'score_comparision' => false,
'score_comparison' => false,
],
]);

Expand Down Expand Up @@ -131,7 +131,7 @@ public function testScore4()
[
'action' => 'contact_us',
'threshold' => 0.9,
'score_comparision' => true,
'score_comparison' => true,
],
]);

Expand Down Expand Up @@ -165,7 +165,7 @@ public function testScore5()
[
'action' => 'contact_us',
'threshold' => 0.91,
'score_comparision' => true,
'score_comparison' => true,
],
]);

Expand Down Expand Up @@ -200,7 +200,7 @@ public function testScore6()
[
'action' => 'contact_us_test',
'threshold' => 0.91,
'score_comparision' => true,
'score_comparison' => true,
],
]);

Expand Down Expand Up @@ -234,7 +234,7 @@ public function testScore7()
[
'action' => 'contact_us_test',
'threshold' => 0.91,
'score_comparision' => true,
'score_comparison' => true,
],
]);

Expand Down Expand Up @@ -268,7 +268,7 @@ public function testScore11()
[
'action' => 'contact_us',
'threshold' => 0.91,
'score_comparision' => true,
'score_comparison' => true,
],
]);

Expand Down Expand Up @@ -302,7 +302,7 @@ public function testScore8()
[
'action' => 'contact_us',
'threshold' => 0.91,
'score_comparision' => true,
'score_comparison' => true,
],
]);

Expand Down Expand Up @@ -336,7 +336,7 @@ public function testScore12()
[
'action' => 'contact_us',
'threshold' => 0.6,
'score_comparision' => true,
'score_comparison' => true,
],
]);

Expand Down

0 comments on commit 251594d

Please sign in to comment.