Skip to content

Commit

Permalink
UPDATED
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanDaDeng committed Nov 24, 2018
1 parent 990435e commit 02d0e70
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 35 deletions.
48 changes: 16 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
[![Latest Version on Packagist][ico-version]][link-packagist]
[![Total Downloads][ico-downloads]][link-downloads]

STILL UNDER IMPLEMENTATION !!!


Google reCAPTCHA v3 is a new mechanism to verify whether the user is bot or not.

Expand Down Expand Up @@ -58,7 +56,7 @@ If your Laravel framework version is >= 5.5, just run the following command to p
$ php artisan vendor:publish --provider="RyanDeng\GoogleReCaptcha\Providers\GoogleReCaptchaV3ServiceProvider"
```

After installation, you should see a googlerecaptcha/googlerecaptchav3.blade file in your views folder and googlerecaptchav3.php in your app/config folder.
After installation, you should see a googlerecaptchav3/field.blade and header.blade file in your views folder and googlerecaptchav3.php in your app/config folder.

## Basic Usage
#### Setting up your Google reCAPTCHA details in config file
Expand All @@ -69,7 +67,6 @@ Specify your Score threshold and action in 'setting', e.g.
``` php
'setting' = [
'action' => 'contact_us', // Google reCAPTCHA required paramater
'id' => 'contactus_id', // your HTML input field id
'threshold' => 0.2, // score threshold
'is_enabled' => false // if this is true, the system will do score comparsion against your threshold for the action
]
Expand All @@ -83,41 +80,34 @@ For more details please check comments in config file.

#### Display reCAPTCHA v3

Include Google API in header

``` html
{!! app('captcha')->render($$action1,$action2...) !!}
{!! GoogleReCaptchaV3::requireJs() !!}
```

Or use Facade
Include input field

``` html
{!! GoogleReCaptchaV3::render($action1,$action2) !!}
{!! GoogleReCaptchaV3::render('contact_us') !!}
```

Example Usage

``` html
{!! GoogleReCaptchaV3::render($action1,$action2) !!}
{!! GoogleReCaptchaV3::requireJs() !!}

<form method="POST" action="/verify1">
<form method="POST" action="/verify">
@csrf
<input type="hidden" id="your_id_1" name="g-recaptcha-response">
<input type="hidden" id="contactus_id" name="g-recaptcha-response">
{!! GoogleReCaptchaV3::render('contact_us') !!}

<input type="submit" class="g-recaptcha" value="submit">
</form>

<form method="POST" action="/verify2">
@csrf
<input type="hidden" id="your_id_2" name="g-recaptcha-response">
<input type="submit" class="g-recaptcha" value="submit">
</form>
```

- You can pass multiple $action in render(...)function
- Each action should have its own mapped id which you have specified in setting file.
- Please specify your id for the input below:

``` html
<input type="hidden" id="your_id" name="g-recaptcha-response">
```
Note: all values should be registered in googlerecaptchav3 config file in 'setting' section.
Note: all actions should be registered in googlerecaptchav3 config file in 'setting' section.


#### Validation Class (Only support Laravel >= 5.5)
Expand All @@ -127,7 +117,7 @@ Note: all values should be registered in googlerecaptchav3 config file in 'setti
``` php
use RyanDeng\GoogleReCaptcha\Validations\GoogleReCaptchaValidationRule
$rule = [
'g-recaptcha-response' => [new GoogleReCaptchaValidationRule('action_name',$ip)]
'g-recaptcha-response' => [new GoogleReCaptchaValidationRule('action_name')]
];
```

Expand All @@ -136,14 +126,11 @@ Note: all values should be registered in googlerecaptchav3 config file in 'setti
GoogleReCaptchaValidationRule($actionName, $ip) which accepts two optional parameters:
- $actionName: if its NULL, the package won't verify action with google response.

- $ip: request remote ip, this is Google reCAPTCHA parameter.


#### Facade Class


``` php
GoogleReCaptchaV3::setAction($action)->verifyResponse($response, $ip);
GoogleReCaptchaV3::setAction($action)->verifyResponse($response);
```

$action: Google reCAPTCHA definition
Expand Down Expand Up @@ -173,7 +160,7 @@ Remember to register your implementation, e.g.

#### Custom implementation on Request method

The package uses Curl to verify, if you want to use your own request method, You can create your own class and implement
The package uses Guzzle\Http to verify, if you want to use your own request method, You can create your own class and implement
```
RyanDeng\GoogleReCaptcha\Interfaces\RequestClientInterface
```
Expand All @@ -186,9 +173,6 @@ Remember to register your implementation.
);
```

## Limitations
One action can only map to one input field id, so you cannot declare multiple id to the same action.

## Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Expand Down
2 changes: 1 addition & 1 deletion src/GoogleReCaptchaV3.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function render($action, $name = 'g-recaptcha-response')
return app('view')->make($view, $data);
}

public function init()
public function requireJs()
{
return app('view')->make(
$this->defaultHeaderView,
Expand Down
4 changes: 2 additions & 2 deletions src/Validations/GoogleReCaptchaValidationRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class GoogleReCaptchaValidationRule implements ImplicitRule
protected $ip;
protected $message;

public function __construct($action = null, $ip = null)
public function __construct($action = null)
{
$this->action = $action;
}
Expand All @@ -30,7 +30,7 @@ public function __construct($action = null, $ip = null)
*/
public function passes($attribute, $value)
{
$response = GoogleReCaptchaV3::setAction($this->action)->verifyResponse($value, $this->ip);
$response = GoogleReCaptchaV3::setAction($this->action)->verifyResponse($value);
$this->message = $response->getMessage();
return $response->isSuccess();
}
Expand Down

0 comments on commit 02d0e70

Please sign in to comment.