Skip to content

Commit 1b4a6e9

Browse files
committed
updated readme
1 parent 8a87a6a commit 1b4a6e9

File tree

1 file changed

+64
-89
lines changed

1 file changed

+64
-89
lines changed

readme.md

Lines changed: 64 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
[![StyleCI][ico-styleci]][link-styleci]
1616
[![Latest Unstable Version][ico-unstable]][link-unstable]
1717

18-
This is a package for Google reCAPTCHA v2
18+
This is a package for Google reCAPTCHA v2.
19+
20+
If you want to use v3, please go to: https://github.com/RyanDaDeng/laravel-google-recaptcha-v3
21+
1922
# DEMO
2023

2124
## Invisible
@@ -32,19 +35,12 @@ This is a package for Google reCAPTCHA v2
3235

3336
## Description
3437

35-
Google reCAPTCHA v2 is a new mechanism to verify whether the user is bot or not.
36-
37-
reCAPTCHA v2 is intended for power users, site owners that want more data about their traffic, and for use cases in which it is not appropriate to show a challenge to the user.
38-
39-
For example, a registration page might still use reCAPTCHA v2 for a higher-friction challenge, whereas more common actions like sign-in, searches, comments, or voting might use reCAPTCHA v2.
40-
41-
Please check Google site: https://developers.google.com/recaptcha/docs/faq
38+
If you want to make your own validation rules, you have full access to modify template file, so you can customise your own template by reading through Google official guide for either invisible or inline. https://developers.google.com/recaptcha/docs/display
4239

4340
## Features
4441

45-
- Score Comparision
4642
- Support invisible, global and inline badge style
47-
- Support multiple reCAPTCHA the same page for different forms
43+
- Support multiple reCAPTCHA on the same page for different forms
4844
- Support multiple actions to be placed on the same page
4945
- Support custom implementation on config interface
5046
- Support custom implementation on request method interface
@@ -77,48 +73,31 @@ If your Laravel framework version <= 5.4, please register the service provider i
7773
``` php
7874
'providers'=[
7975
....,
80-
TimeHunter\LaravelGoogleCaptchav2\Providers\GoogleReCaptchav2ServiceProvider::class
76+
TimeHunter\LaravelGoogleReCaptchaV2\Providers\GoogleReCaptchav2ServiceProvider::class
8177
]
8278
```
8379

8480
And also
8581
``` php
8682
'aliases'=[
8783
....,
88-
'GoogleReCaptchav2'=> TimeHunter\LaravelGoogleCaptchav2\Facades\GoogleReCaptchav2::class
84+
'GoogleReCaptchav2'=> TimeHunter\LaravelGoogleReCaptchaV2\Facades\GoogleReCaptchav2::class
8985
]
9086
```
9187

9288

9389
If your Laravel framework version is >= 5.5, just run the following command to publish views and config.
9490
```sh
95-
$ php artisan vendor:publish --provider="TimeHunter\LaravelGoogleCaptchav2\Providers\GoogleReCaptchav2ServiceProvider"
91+
$ php artisan vendor:publish --provider="TimeHunter\LaravelGoogleReCaptchaV2\Providers\GoogleReCaptchav2ServiceProvider"
9692
```
9793

98-
After installation, you should see a googlerecaptchav2/field.blade and header.blade file in your views folder and googlerecaptchav2.php in your app/config folder.
94+
After installation, you should see a googlerecaptchav2/template.blade under views folder and googlerecaptchav2.php in your app/config folder.
9995

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

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

105-
Specify your Score threshold and action in 'setting', e.g.
106-
``` php
107-
'setting' = [
108-
[
109-
'action' => 'contact_us', // Google reCAPTCHA required paramater
110-
'threshold' => 0.2, // score threshold
111-
'is_enabled' => false // if this is true, the system will do score comparsion against your threshold for the action
112-
]
113-
]
114-
```
115-
Note: if you want to enable Score Comparision, you also need to enable is_score_enabled to be true.
116-
``` php
117-
'is_score_enabled' = true
118-
```
119-
120-
For score comparision, all actions should be registered in googlerecaptchav2 config file under 'setting' section.
121-
122101
For more details please check comments in config file.
123102

124103
#### Display reCAPTCHA v2
@@ -127,18 +106,15 @@ For more details please check comments in config file.
127106
Include div with an ID inside your form, e.g.
128107

129108
``` html
130-
<div id="contact_us_id"></div>
109+
<div id="form_id_1"></div>
110+
<div id="form_id_2"></div>
131111
```
132112

133113
Include Template script in your bottom/header of your page, params should follow 'ID'=>'Action', e.g.
134114

135115
``` PHP
136-
{!! GoogleReCaptchav2::render(
137-
[
138-
'contact_us_id'=>'contact_us', // the div id=contact_us_id maps to action name contact_us
139-
'signin_id'=>'registration', // the div id=signin_id maps to action name registration
140-
'register_id'=>'registration' // the div id=register_id maps to action name registration
141-
]) !!}
116+
{!! GoogleReCaptchav2::render('form_id_1','form_id_2') !!}
117+
{!! GoogleReCaptchav2::render('form_id_1') !!}
142118
```
143119

144120
##### Example Usage
@@ -148,18 +124,9 @@ Include Template script in your bottom/header of your page, params should follow
148124
@csrf
149125
<div id="contact_us_id"></div>
150126
<input type="submit" value="submit">
151-
<div>
152-
<small>
153-
This site is protected by reCAPTCHA and the Google
154-
<a href="https://policies.google.com/privacy">Privacy Policy</a> and
155-
<a href="https://policies.google.com/terms">Terms of Service</a> apply.
156-
</small>
157-
</div>
158127
</form>
159128

160-
{!! GoogleReCaptchav2::render([
161-
'contact_us_id'=>'contact_us'
162-
]) !!}
129+
{!! GoogleReCaptchav2::render('contact_us_id'=>'contact_us') !!}
163130

164131
```
165132

@@ -173,7 +140,7 @@ Inline
173140
``` PHP
174141
[
175142
...
176-
'inline' => true
143+
'badge' => 'inline'
177144
...
178145
]
179146
```
@@ -182,7 +149,14 @@ Inline
182149

183150
Invisible
184151

185-
1. Set inline as true as well
152+
1. Set size as invisible
153+
``` PHP
154+
[
155+
...
156+
'size' => 'invisible'
157+
...
158+
]
159+
```
186160
2. Modify your div with style display:none
187161
3. Refer to Google official site: https://developers.google.com/recaptcha/docs/faq
188162
, you need to include the following text:
@@ -194,36 +168,41 @@ Invisible
194168

195169
Corner
196170

197-
1. Set inline as false
198-
2. Your badge will be shown in the bottom right side.
199-
200-
Custom
201-
202-
1. Set inline as true
203-
2. Do Styling/CSS on its div element
204-
171+
1. Set size as invisible
172+
``` PHP
173+
[
174+
...
175+
'size' => 'invisible'
176+
...
177+
]
178+
```
179+
2. Set badge as bottomright/bottomleft
180+
``` PHP
181+
[
182+
...
183+
'badge' => 'bottomright'
184+
...
185+
]
186+
```
205187

206188
## Validation Class (Only support Laravel >= 5.5)
207189

208190
You can use provided Validation object to verify your reCAPTCHA.
209191

210192
``` php
211-
use TimeHunter\LaravelGoogleCaptchav2\Validations\GoogleReCaptchaValidationRule
193+
use TimeHunter\LaravelGoogleReCaptchaV2\Validations\GoogleReCaptchaV2ValidationRule
212194
$rule = [
213-
'g-recaptcha-response' => [new GoogleReCaptchaValidationRule('action_name')]
195+
'g-recaptcha-response' => [new GoogleReCaptchaV2ValidationRule()]
214196
];
215197
```
216-
217-
- $actionName: if its NULL, the package won't verify action with google response.
218198

219199
## Facade Usage
220200

221201
You can also directly use registered service by calling the following method.
222-
- setAction() is optional only if you want to verify if the action is matched.
223202
- verifyResponse() which accepts the token value from your form. This return Google reCAPTCHA Response object.
224203

225204
``` php
226-
GoogleReCaptchav2::setAction($action)->verifyResponse($value);
205+
GoogleReCaptchav2::setAction($action)->verifyResponse($value, $ip=null);
227206
```
228207

229208
Example Usage
@@ -232,7 +211,6 @@ Example Usage
232211
GoogleReCaptchav2::verifyResponse($value,$ip)->getMessage();
233212
GoogleReCaptchav2::verifyResponse($value)->isSuccess();
234213
GoogleReCaptchav2::verifyResponse($value)->toArray();
235-
GoogleReCaptchav2::setAction($action)->verifyResponse($value)->isSuccess();
236214
```
237215

238216
``` php
@@ -241,41 +219,27 @@ Example Usage
241219

242220
## Sample Use Case
243221

244-
Register your action in config, also enable score and set up your own site key and secret key:
245-
``` php
246-
'setting' => [
247-
[
248-
'action' => 'contact_us',
249-
'threshold' => 2,
250-
'score_comparision' => true
251-
],
252-
[
253-
'action' => 'signup',
254-
'threshold' => 0.2,
255-
'score_comparision' => true
256-
],
257-
]
258-
```
222+
1. Register your action in config, also enable score and set up your own site key and secret key:
259223

260-
Register two routes in web.php
224+
2. Register two routes in web.php
261225
``` php
262226
Route::get('/index', 'ReCaptchaController@index');
263227
Route::post('/verify', 'ReCaptchaController@verify');
264228
```
265229

266-
Create two functions in controller:
230+
3. Create two functions in controller:
267231
``` php
268232
public function verify(Request $request)
269233
{
270-
dd(GoogleReCaptchav2::verifyResponse($request->input('g-recaptcha-response'))->getMessage());
234+
dd(GoogleReCaptchaV2::verifyResponse($request->input('g-recaptcha-response'))->getMessage());
271235
}
272236
public function index(Request $request)
273237
{
274238
return view('index');
275239
}
276240
```
277241

278-
Create your form in index.blade.php:
242+
4. Create your form in index.blade.php:
279243
``` html
280244
<form method="POST" action="/verify">
281245
@csrf
@@ -290,26 +254,37 @@ Create your form in index.blade.php:
290254
<input type="submit" value="submit">
291255
</form>
292256

293-
{!! GoogleReCaptchav2::render(['contact_us_id'=>'contact_us', 'signup_id'=>'signup']) !!}
257+
{!! GoogleReCaptchav2::render('contact_us_id') !!}
294258
```
295259

296-
Go to /index and click submit button on contact us form and you should see an error message that 'Score does not meet the treshhold' because the threshold >2. You can play around the controller to see all outcomes. Importantly, you need to wait the script to load and render the token before clicking the submit button.
297260

298261
## Advanced Usage
299262

263+
#### Custom implementation on Template
264+
265+
After publish views, a blade file created under googlerecaptchav2, you can customise it and change template value in config file, e.g. if your template is saved in resources/views/test/template, you should put values as below:
266+
``` PHP
267+
[
268+
...
269+
'template' => 'test.template'
270+
...
271+
]
272+
```
273+
274+
300275
#### Custom implementation on Config
301276

302277
For some users, they might store the config details in their own storage e.g database. You can create your own class and implement:
303278

304279
```
305-
TimeHunter\LaravelGoogleCaptchav2\Interfaces\ReCaptchaConfigv2Interface
280+
TimeHunter\LaravelGoogleReCaptchaV2\Interfaces\ReCaptchaConfigv2Interface
306281
```
307282

308283
Remember to register it in your own service provider
309284

310285
``` php
311286
$this->app->bind(
312-
ReCaptchaConfigv2Interface::class,
287+
ReCaptchaConfigV2Interface::class,
313288
YourOwnCustomImplementation::class
314289
);
315290
```
@@ -318,7 +293,7 @@ Remember to register it in your own service provider
318293

319294
The package has two default options to verify: Guzzle and Curl, if you want to use your own request method, You can create your own class and implement
320295
```
321-
TimeHunter\LaravelGoogleCaptchav2\Interfaces\RequestClientInterface
296+
TimeHunter\LaravelGoogleReCaptchaV2\Interfaces\RequestClientInterface
322297
```
323298

324299
Remember to register it in your own service provider

0 commit comments

Comments
 (0)