diff --git a/CHANGELOG.md b/CHANGELOG.md index 021bbb7..e5f33ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,15 @@ All notable changes to `simple-recaptcha-v3` will be documented in this file +## 1.1.0 - 2020-05-24 + +### Updates +- Update assets reference name [3b95223](https://github.com/torralbodavid/simple-recaptcha-v3/commit/3b952237460a44d1a5b2eb446f87b7eca70fd30c) +- Update readme instructions [888c067](https://github.com/torralbodavid/simple-recaptcha-v3/commit/888c06778eba315c1499cafd4b12fd393e21977d) + +### Deletions +- Delete package facade [624b036](https://github.com/torralbodavid/simple-recaptcha-v3/commit/624b03653defecc3e8ce706e0d2ba7bcadd39be7) + ## 1.0.6 - 2020-05-23 - Stable release diff --git a/README.md b/README.md index 999a263..3a0578d 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Simple reCAPTCHA v3 integration [![Latest Version on Packagist](https://img.shields.io/packagist/v/torralbodavid/simple-recaptcha-v3.svg?style=flat-square)](https://packagist.org/packages/torralbodavid/simple-recaptcha-v3) -[![Build Status](https://img.shields.io/travis/torralbodavid/simple-recaptcha-v3/master.svg?style=flat-square)](https://travis-ci.org/torralbodavid/simple-recaptcha-v3) +[![Build Status](https://travis-ci.org/torralbodavid/simple-recaptcha-v3.svg?branch=master)](https://travis-ci.org/torralbodavid/simple-recaptcha-v3) [![StyleCI](https://github.styleci.io/repos/263758912/shield)](https://github.styleci.io/repos/263758912) [![Quality Score](https://img.shields.io/scrutinizer/g/torralbodavid/simple-recaptcha-v3.svg?style=flat-square)](https://scrutinizer-ci.com/g/torralbodavid/simple-recaptcha-v3) [![Total Downloads](https://img.shields.io/packagist/dt/torralbodavid/simple-recaptcha-v3.svg?style=flat-square)](https://packagist.org/packages/torralbodavid/simple-recaptcha-v3) @@ -13,53 +13,98 @@ This repository contains simple reCAPTCHA v3 integration for your Laravel applic You can install the package via composer: ```bash -composer require torralbodavid/simple-recaptcha-v3 + composer require torralbodavid/simple-recaptcha-v3 ``` ## Usage -1. To get started, you must include at the very bottom of your head tag from the pages you want to protect with reCaptcha, the `@captcha_init` blade directive. This will start loading Google reCAPTCHA API. +1. Set the following variables in your .env + +Override xxxxx with your reCaptcha v3 keys. Get yours [here](https://www.google.com/recaptcha/admin) + +``` + CAPTCHA_SITE_KEY=xxxxx + CAPTCHA_SECRET_KEY=xxxxx +``` + +Optionally, you can publish the config file of the package. You will be able to customize advanced settings, such as: + +* Disabling reCaptcha v3 +* Minimum score you should get in order to validate your form +* Hostname validation +* Hide reCaptcha badge +* Prefer navigator language on reCaptcha badge + +``` + php artisan vendor:publish --provider="Torralbodavid\SimpleRecaptchaV3\SimpleRecaptchaV3ServiceProvider" --tag=config +``` + +2. To get started, you must include at the very bottom of your head tag from the pages you want to protect with reCaptcha, the `@captcha_init` blade directive. This will start loading Google reCAPTCHA API. ```html - - - ... - - @captcha_init - - + + + ... + + @captcha_init + + ``` -2. Include below your form initialization tag, the `@captcha('xxxx')` blade directive. Replace xxxx with your desired [action](https://developers.google.com/recaptcha/docs/v3#actions). +3. Include below your form initialization tag, the `@captcha('xxxx')` blade directive. Replace xxxx with your desired [action](https://developers.google.com/recaptcha/docs/v3#actions). ```html -
- @captcha('login') - ... -
+
+ @captcha('login') + ... +
``` -3. To sum up, add the following rule on your form validation: +4. To sum up, add the following rule on your form validation: -`'recaptcha_response' => new Captcha` +```php + 'recaptcha_response' => new Captcha +``` ```php -use Torralbodavid\SimpleRecaptchaV3\Rules\Captcha; + use Torralbodavid\SimpleRecaptchaV3\Rules\Captcha; + + ... + + $request->validate([ + ... + 'recaptcha_response' => new Captcha, + ]); +``` -... +### Customize error messages -$request->validate([ - ... - 'recaptcha_response' => new Captcha, -]); +You can customize reCaptcha v3 error messages by publishing the translations on your project. + +```bash + php artisan vendor:publish --provider="Torralbodavid\SimpleRecaptchaV3\SimpleRecaptchaV3ServiceProvider" --tag=lang ``` -Have fun! +### Customize snippets + +You can customize @captcha() and @captcha_init snippets by publishing the views on your project + +```bash + php artisan vendor:publish --provider="Torralbodavid\SimpleRecaptchaV3\SimpleRecaptchaV3ServiceProvider" --tag=views +``` + +### Disable reCaptcha v3 integration in tests + +You can easily disable reCaptcha v3 integration in your tests by adding the following configuration on them + +```php + config()->set('simple-recaptcha-v3.active', false); +``` ### Testing ``` bash -composer test + composer test ``` ### Changelog @@ -82,3 +127,5 @@ If you discover any security related issues, please email davidtorralboperez@gma ## License The MIT License (MIT). Please see [License File](LICENSE.md) for more information. + +Have fun! diff --git a/config/config.php b/config/config.php index 7add8bc..7904714 100644 --- a/config/config.php +++ b/config/config.php @@ -1,15 +1,35 @@ env('CAPTCHA_ENABLED', true), + + /* + * Set your captcha keys here. Get yours here https://www.google.com/recaptcha/admin + */ 'site_key' => env('CAPTCHA_SITE_KEY', ''), 'secret_key' => env('CAPTCHA_SECRET_KEY', ''), + + /* + * Minimum score you should get to get the form validated + */ 'minimum_score' => env('CAPTCHA_MINIMUM_SCORE', 0.5), + + /* + * Check if the hostname request is the same as the form validation one. + */ 'hostname_check' => env('CAPTCHA_HOSTNAME_CHECK', true), /* + * Turning this switch to true, will make captcha badge invisible. * Before hide badge, you may read https://developers.google.com/recaptcha/docs/faq#id-like-to-hide-the-recaptcha-badge.-what-is-allowed */ 'hide_badge' => env('CAPTCHA_HIDE_BADGE', false), + + /* + * By turning on this setting, captcha badge will prefer the navigator language. + */ 'prefer_navigator_language' => env('CAPTCHA_PREFER_NAVIGATOR_LANGUAGE', false), ]; diff --git a/src/SimpleRecaptchaV3Facade.php b/src/SimpleRecaptchaV3Facade.php deleted file mode 100644 index cd8deaf..0000000 --- a/src/SimpleRecaptchaV3Facade.php +++ /dev/null @@ -1,16 +0,0 @@ -app->runningInConsole()) { $this->publishes([ __DIR__.'/../config/config.php' => config_path('simple-recaptcha-v3.php'), - ], 'simple-recaptcha-v3-config'); + ], 'config'); $this->publishes([ __DIR__.'/../resources/views' => resource_path('views/vendor/simple-recaptcha-v3'), - ], 'simple-recaptcha-v3-views'); + ], 'views'); $this->publishes([ __DIR__.'/../resources/lang' => resource_path('lang/vendor/simple-recaptcha-v3'), - ], 'simple-recaptcha-v3-lang'); + ], 'lang'); } Blade::directive('captcha', function ($action) {