Skip to content

Commit

Permalink
Merge branch 'release/v1.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
torralbodavid committed May 24, 2020
2 parents 85e06e0 + 24478ab commit 333bc3d
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 44 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
97 changes: 72 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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
<html>
<head>
...

@captcha_init
</head>
</html>
<html>
<head>
...
@captcha_init
</head>
</html>
```

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
<form method="..." action="...">
@captcha('login')
...
</form>
<form method="..." action="...">
@captcha('login')
...
</form>
```

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
Expand All @@ -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!
20 changes: 20 additions & 0 deletions config/config.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,35 @@
<?php

return [
/*
* Set to false if you want to disable captcha.
*/
'active' => 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),
];
16 changes: 0 additions & 16 deletions src/SimpleRecaptchaV3Facade.php

This file was deleted.

6 changes: 3 additions & 3 deletions src/SimpleRecaptchaV3ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ public function boot()
if ($this->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) {
Expand Down

0 comments on commit 333bc3d

Please sign in to comment.