Skip to content

Commit

Permalink
Merge pull request ARCANEDEV#79 from ARCANEDEV/update-recaptcha_v3
Browse files Browse the repository at this point in the history
Updating the ReCaptcha to V3
  • Loading branch information
arcanedev-maroc authored Jan 30, 2019
2 parents d20546a + a5ad19c commit 0b3f53c
Show file tree
Hide file tree
Showing 55 changed files with 2,466 additions and 1,087 deletions.
2 changes: 1 addition & 1 deletion .scrutinizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ checks:
tools:
external_code_coverage:
timeout: 600
runs: 3
runs: 4
php_code_sniffer:
enabled: true
config:
Expand Down
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ php:
- 7.1.3
- 7.1
- 7.2
- 7.3
- nightly

matrix:
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2015-2018 | ARCANEDEV <arcanedev.maroc@gmail.com> - noCaptcha
Copyright (c) 2015-2019 | ARCANEDEV <arcanedev.maroc@gmail.com> - noCaptcha

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ reCAPTCHA comes in the form of a widget that you can easily add to your blog, fo
### Features

* Framework agnostic package.
* Invisible reCaptcha supported.
* `v2` (+ Invisible) & `v3` reCaptcha are supported.
* Easy setup &amp; configuration.
* Well documented &amp; IDE Friendly.
* Well tested with maximum code quality.
Expand Down
2 changes: 1 addition & 1 deletion _docs/0-Home.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ reCAPTCHA comes in the form of a widget that you can easily add to your blog, fo
### Features

* Framework agnostic package.
* Invisible reCaptcha supported.
* `v2` (+ Invisible) & `v3` reCaptcha are supported.
* Easy setup &amp; configuration.
* Well documented &amp; IDE Friendly.
* Well tested with maximum code quality.
Expand Down
35 changes: 9 additions & 26 deletions _docs/1-Installation-and-Setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ For more details, check the [official documentation](https://developers.google.c

## Version Compatibility

| noCaptcha | Laravel |
|:----------------------------------|:--------------------------------------------------------------------------------------------------------------------|
| ![noCaptcha v1.x][no_captcha_1_x] | ![Laravel v4.2][laravel_4_2] |
| ![noCaptcha v3.x][no_captcha_3_x] | ![Laravel v5.0][laravel_5_0] ![Laravel v5.1][laravel_5_1] ![Laravel v5.2][laravel_5_2] ![Laravel v5.3][laravel_5_3] |
| ![noCaptcha v4.x][no_captcha_4_x] | ![Laravel v5.4][laravel_5_4] |
| ![noCaptcha v5.x][no_captcha_5_x] | ![Laravel v5.5][laravel_5_5] |
| ![noCaptcha v6.x][no_captcha_6_x] | ![Laravel v5.6][laravel_5_6] |
| ![noCaptcha v7.x][no_captcha_7_x] | ![Laravel v5.7][laravel_5_7] |
| noCaptcha | Laravel |
|:--------------------------------------------------------------------|:--------------------------------------------------------------------------------------------------------------------|
| ![noCaptcha v1.x][no_captcha_1_x] | ![Laravel v4.2][laravel_4_2] |
| ![noCaptcha v3.x][no_captcha_3_x] | ![Laravel v5.0][laravel_5_0] ![Laravel v5.1][laravel_5_1] ![Laravel v5.2][laravel_5_2] ![Laravel v5.3][laravel_5_3] |
| ![noCaptcha v4.x][no_captcha_4_x] | ![Laravel v5.4][laravel_5_4] |
| ![noCaptcha v5.x][no_captcha_5_x] | ![Laravel v5.5][laravel_5_5] |
| ![noCaptcha v6.x][no_captcha_6_x] | ![Laravel v5.6][laravel_5_6] |
| ![noCaptcha v7.x][no_captcha_7_x] ![noCaptcha v8.x][no_captcha_8_x] | ![Laravel v5.7][laravel_5_7] |

> **Note :** This is a framework-agnostic package, so you can use any version of this package in your PHP project.
Expand All @@ -49,6 +49,7 @@ For more details, check the [official documentation](https://developers.google.c
[no_captcha_5_x]: https://img.shields.io/badge/version-5.*-blue.svg?style=flat-square "noCaptcha v5.*"
[no_captcha_6_x]: https://img.shields.io/badge/version-6.*-blue.svg?style=flat-square "noCaptcha v6.*"
[no_captcha_7_x]: https://img.shields.io/badge/version-7.*-blue.svg?style=flat-square "noCaptcha v7.*"
[no_captcha_8_x]: https://img.shields.io/badge/version-8.*-blue.svg?style=flat-square "noCaptcha v8.*"

## Composer

Expand All @@ -69,15 +70,6 @@ Once the package is installed, you can register the service provider in `config/
],
```

**Optional:** And the facade in the `aliases` array:

```php
'aliases' => [
...
'Captcha' => Arcanedev\NoCaptcha\Facades\NoCaptcha::class,
],
```

> For Laravel 4.2 (PHP 5.4), the config file is located in `app/config/app.php`
In the `providers` array:
Expand All @@ -88,12 +80,3 @@ In the `providers` array:
'Arcanedev\NoCaptcha\Laravel\ServiceProvider',
],
```

And the facade in the `aliases` array:

```php
'aliases' => [
...
'Captcha' => 'Arcanedev\NoCaptcha\Laravel\Facade',
],
```
22 changes: 0 additions & 22 deletions _docs/2-Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,25 +56,3 @@ return [
// ...
];
```

## Additional configs

You can customize your captchas by setting-up a global `attributes` in your config file.

```
<?php
return [
// ...
/* ------------------------------------------------------------------------------------------------
| Attributes
| ------------------------------------------------------------------------------------------------
*/
'attributes' => [
'data-theme' => null, // 'light', 'dark'
'data-type' => null, // 'image', 'audio'
'data-size' => null, // 'normal', 'compact'
],
];
```
73 changes: 60 additions & 13 deletions _docs/3-Usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,25 @@ Checkout example below:
```php
<?php

require_once('vendor/autoload.php');
require_once(__DIR__.'/vendor/autoload.php');

use Arcanedev\NoCaptcha\NoCaptcha;
use Arcanedev\NoCaptcha\NoCaptchaV2;

$secret = 'your-secret-key';
$sitekey = 'your-site-key';
$captcha = new NoCaptcha($secret, $sitekey);
$captcha = new NoCaptchaV2($secret, $sitekey);

if ( ! empty($_POST)) {
if ($_POST) {
// You need to check also if the $_POST['g-recaptcha-response'] is not empty.
$response = $_POST['g-recaptcha-response'];
$result = $captcha->verify($response);
$response = $captcha->verify($_POST['g-recaptcha-response'] ?? null);

echo $result === true
echo $response->isSuccess()
? 'Yay ! You are a human.'
: 'No ! You are a robot.';

exit();
}

?>

<form action="?" method="POST">
Expand Down Expand Up @@ -67,20 +67,23 @@ The code below explains how to enable and customize the invisible reCAPTCHA on y
```php
require_once(__DIR__ . '/../vendor/autoload.php');

use Arcanedev\NoCaptcha\NoCaptcha;
use Arcanedev\NoCaptcha\NoCaptchaV2;

$secret = 'your-secret-key';
$sitekey = 'your-site-key';
$captcha = new NoCaptcha($secret, $sitekey);
$captcha = new NoCaptchaV2($secret, $sitekey);

if ( ! empty($_POST)) {
$response = $_POST[NoCaptcha::CAPTCHA_NAME];
$result = $captcha->verify($response);
if ($_POST) {
// You need to check also if the $_POST['g-recaptcha-response'] is not empty.
$response = $captcha->verify($_POST['g-recaptcha-response'] ?? null);

echo $result === true ? 'Yay ! You are a human.' : 'No ! You are a robot.';
echo $response->isSuccess()
? 'Yay ! You are a human.'
: 'No ! You are a robot.';

exit();
}

?>

<form method="POST" id="demo-form">
Expand All @@ -98,6 +101,50 @@ if ( ! empty($_POST)) {

**NOTE :** You need to specify the invisible version in your captcha admin page. Check this page for more details: https://developers.google.com/recaptcha/docs/versions

#### Version 3

The code below shows you how to use the ReCaptcha V3:

```php
<?php

require_once(__DIR__.'/vendor/autoload.php');

use Arcanedev\NoCaptcha\NoCaptchaV3;

$captcha = new NoCaptchaV3(
'SECRET-KEY',
'SITE-KEY'
);

if ($_POST) {
$response = $captcha->verify($_POST['g-recaptcha-response'] ?? null);

echo $response->isSuccess()
? 'Yay ! You are a human.'
: 'No ! You are a robot.';

exit();
}

?>

<form method="POST">
<input type="email" name="email"><br>
<button type="submit">Submit</button>

<?php echo $captcha->input('g-recaptcha-response'); ?>
</form>

<?php echo $captcha->script(); ?>

<script>
grecaptcha.ready(function() {
grecaptcha.execute('SITE-KEY', {action: 'homepage'});
});
</script>
```

### Laravel

#### Views
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"autoload": {
"psr-4": {
"Arcanedev\\NoCaptcha\\": "src/"
}
},
"files": ["helpers.php"]
},
"autoload-dev": {
"psr-4": {
Expand Down
16 changes: 11 additions & 5 deletions config/no-captcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@
'secret' => env('NOCAPTCHA_SECRET', 'no-captcha-secret'),
'sitekey' => env('NOCAPTCHA_SITEKEY', 'no-captcha-sitekey'),

/* -----------------------------------------------------------------
| Version
| -----------------------------------------------------------------
| Supported: v3, v2
*/

'version' => 'v3',

/* -----------------------------------------------------------------
| Localization
| -----------------------------------------------------------------
Expand All @@ -18,14 +26,12 @@
'lang' => 'en',

/* -----------------------------------------------------------------
| Attributes
| Skip IPs
| -----------------------------------------------------------------
*/

'attributes' => [
'data-theme' => null, // 'light', 'dark'
'data-type' => null, // 'image', 'audio'
'data-size' => null, // 'normal', 'compact'
'skip-ips' => [
// 127.0.0.1
],

];
29 changes: 0 additions & 29 deletions examples/audio-captcha.php

This file was deleted.

27 changes: 0 additions & 27 deletions examples/compact-captcha.php

This file was deleted.

29 changes: 0 additions & 29 deletions examples/image-captcha.php

This file was deleted.

Loading

0 comments on commit 0b3f53c

Please sign in to comment.