Skip to content

Commit

Permalink
added comments
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanDaDeng committed Nov 24, 2018
1 parent 64b06ec commit 8ba6ff2
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 29 deletions.
19 changes: 11 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@ This package requires the following dependencies:

Via Composer

``` bash
``` sh
$ composer require ryandeng/googlerecaptcha
```

If your Laravel framework version <= 5.4, please register the service provider in your config file: /config/app.php, otherwise please go to step 3.

```sh
```
Ryandadeng\Securepayframe\SecurePayFrameServiceProvider::class
```

If your Laravel framework version is >= 5.5, just run the following command to publish views and config.
```sh
php artisan vendor:publish --provider="RyanDeng\GoogleReCaptcha\GoogleReCaptchaServiceProvider"
$ php artisan vendor:publish --provider="RyanDeng\GoogleReCaptcha\GoogleReCaptchaServiceProvider"
```

After installation, you should see a googlerecaptcha/googlerecaptcha.blade file in your views folder and googlerecaptchav3.php in your app/config folder.
Expand All @@ -47,7 +47,7 @@ If you want to change the default template, please check Advanced Usage.


## Basic Usage
#### Setting up your Google reCAPTCHA details
#### Setting up your Google reCAPTCHA details in config file

Please register all details on host_name, site_key, secret_key and site_verify_url.

Expand All @@ -70,14 +70,14 @@ For more details please check comments in config file.

You can use provided Validation object to verify your reCAPTCHA.

``` php
```
use RyanDeng\GoogleReCaptcha\Validations\GoogleReCaptchaValidationRule
$rule = [
'g-recaptcha-response' => [new GoogleReCaptchaValidationRule('action_name',$ip)]
];
```

'g-recaptcha-response' is the name of your <input> field, which is currently hard-coded.
'g-recaptcha-response' is the name of your input field, which is currently hard-coded.

GoogleReCaptchaValidationRule($actionName, $ip) which accepts two optional parameters:
- $actionName: if its NULL, the package won't verify action with google response.
Expand All @@ -87,14 +87,17 @@ For more details please check comments in config file.

#### Facade Class


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

$action: Google reCAPTCHA definition

$response: which is a value comes from g-recaptcha-response

$ip: optional

GoogleReCaptcha::setAction($action)->verifyResponse($response, $ip);

## Advanced Usage

#### Custom implementation on Config
Expand Down
107 changes: 88 additions & 19 deletions config/googlerecaptcha.php
Original file line number Diff line number Diff line change
@@ -1,31 +1,100 @@
<?php

return [

/*
|--------------------------------------------------------------------------
| Enable/Disable Service
|--------------------------------------------------------------------------
| Type: bool
|
| This option is used to disable/enable the service
|
| Supported: true, false
|
*/
'is_service_enabled' => true,
/*
|--------------------------------------------------------------------------
| Host Name
|--------------------------------------------------------------------------
| Type: string
| Google reCAPTCHA host name, https://www.google.com/recaptcha/admin
|
*/
'host_name' => 'ryandeng.test',
'secret_key' => '6Lez2HcUAAAAAIvmnukbhNLUAighVP6AuPcOFXT2',
'curl_timeout' => 1,
'curl_verify' => false,
'template' => 'GoogleReCaptcha::googlerecaptcha.googlerecaptcha',
'site_key' => '6Lez2HcUAAAAAJPDe-qVi5H8G5FB049E5mrljqt4',
'options' => [
'curl_timeout' => 1,
'curl_verify' => 1,
],
/*
|--------------------------------------------------------------------------
| Secret Key
|--------------------------------------------------------------------------
| Type: string
| Google reCAPTCHA credentials, https://www.google.com/recaptcha/admin
|
*/
'secret_key' => '',
/*
|--------------------------------------------------------------------------
| Site Key
|--------------------------------------------------------------------------
| Type: string
| Google reCAPTCHA credentials, https://www.google.com/recaptcha/admin
|
*/
'site_key' => '',
/*
|--------------------------------------------------------------------------
| Template
|--------------------------------------------------------------------------
| Type: string
| Template path, if your template locate at resources/views/template/test.blade.php
| your value should be template.test
|
*/
'template' => 'googlerecaptcha.googlerecaptcha',
/*
|--------------------------------------------------------------------------
| Score Comparision
|--------------------------------------------------------------------------
| Type: bool
| If you enable it, the package will do score comparision from your score_setting
*/
'is_score_enabled' => true,
/*
|--------------------------------------------------------------------------
| Score Setting
|--------------------------------------------------------------------------
| Type: array
| Define your score threshold
| action: Google reCAPTCHA required paramater
| id: <input> id
| threshold: score threshold
| is_enabled: true/false, if this is true, the system will do score comparsion against your threshold for the action
*/
'score_setting' => [
[
'action' => 'a',
'id' => 'cccc',
'threshold' => 0.2,
'action' => 'contact_us',
'id' => 'contact_us_id',
'threshold' => 0,
'is_enabled' => false
],
[
'action' => 'c',
'id' => 'ddd',
'threshold' => 0.1,
'is_enabled' => true
],
]
],
/*
|--------------------------------------------------------------------------
| Options
|--------------------------------------------------------------------------
| Used for request
|
*/
'options' => [
'curl_timeout' => 1,
'curl_verify' => 1,
],
/*
|--------------------------------------------------------------------------
| Site Verify Url
|--------------------------------------------------------------------------
| Type: string
| Google reCAPTCHA API
*/
'site_verify_url' => 'https://www.google.com/recaptcha/api/siteverify',
];
12 changes: 12 additions & 0 deletions src/Configurations/ReCaptchaConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,33 @@

class ReCaptchaConfig implements ReCaptchaConfigInterface
{
/**
* @return string
*/
public function isServiceEnabled()
{
return config('googlerecaptcha.site_key');
}

/**
* @return string
*/
public function getSiteVerifyUrl()
{
return config('googlerecaptcha.site_verify_url');
}

/**
* @return string
*/
public function getHostName()
{
return config('googlerecaptcha.host_name');
}

/**
* @return bool
*/
public function isScoreEnabled()
{
return config('googlerecaptcha.is_score_enabled');
Expand Down
5 changes: 4 additions & 1 deletion src/Interfaces/ReCaptchaConfigInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
interface ReCaptchaConfigInterface
{

/**
* @return bool
*/
public function isServiceEnabled();

/**
* @return bool
*/
Expand Down Expand Up @@ -43,7 +47,6 @@ public function getTemplate();
*/
public function getSiteKey();


/**
* @return array
*/
Expand Down
7 changes: 6 additions & 1 deletion src/Interfaces/RequestClientInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@
interface RequestClientInterface
{


/**
* @param $url
* @param $body
* @param array $options
* @return mixed
*/
public function post($url, $body, $options = []);

}

0 comments on commit 8ba6ff2

Please sign in to comment.