-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 9a74ab6
Showing
16 changed files
with
430 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.DS_Store | ||
.idea | ||
/vendor | ||
/build | ||
.phpunit.result.cache | ||
composer.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
preset: laravel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
language: php | ||
|
||
php: | ||
- 5.6 | ||
- 7.1 | ||
- 7.2 | ||
- 7.3 | ||
|
||
env: | ||
matrix: | ||
- COMPOSER_FLAGS="--prefer-lowest" | ||
- COMPOSER_FLAGS="" | ||
|
||
before_script: | ||
- travis_retry composer update | ||
|
||
script: | ||
- vendor/bin/phpunit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Changelog | ||
All notable changes to this project will be documented in this file. | ||
|
||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), | ||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). | ||
|
||
## [1.0.0] - 2019-03-07 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2019 Binary Cabin | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# Recaptcha | ||
|
||
A laravel package for easy ReCAPTCHA integration | ||
|
||
## Installation | ||
|
||
``` | ||
composer require binarycabin/recaptcha | ||
``` | ||
|
||
Publish your configuration file | ||
|
||
``` | ||
php artisan vendor:publish --provider="BinaryCabin\Recaptcha\Providers\RecaptchaServiceProvider" --tag="config" | ||
``` | ||
|
||
Update your environment variables: | ||
|
||
``` | ||
RECAPTCHA_VERSION=3 | ||
RECAPTCHA_SITE_KEY="" | ||
RECAPTCHA_SECRET_KEY="" | ||
``` | ||
|
||
For local sites or test environments you can also disable recaptcha verification using: | ||
|
||
``` | ||
RECAPTCHA_ENABLE=false | ||
``` | ||
|
||
## Usage | ||
|
||
At the end of your page, add the scripts needed for Google Recaptcha: | ||
|
||
``` | ||
{!! Recaptcha::scripts() !!} | ||
``` | ||
|
||
And within your form, add the hidden input that will contain your recaptcha token: | ||
|
||
``` | ||
{!! Recaptcha::hiddenInput() !!} | ||
``` | ||
|
||
Finally, add the validation in your controller: | ||
|
||
```php | ||
$this->validate($request, [ | ||
'recaptcha-token' => 'recaptcha', | ||
]); | ||
``` | ||
|
||
## Contributing | ||
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. | ||
|
||
Please make sure to update tests as appropriate. | ||
|
||
## License | ||
[MIT](https://choosealicense.com/licenses/mit/) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{ | ||
"name": "binarycabin/recaptcha", | ||
"description": "A laravel package for easy ReCAPTCHA integration", | ||
"keywords": ["laravel"], | ||
"type": "library", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Jeff Kilroy", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"require": {}, | ||
"autoload":{ | ||
"psr-4": { | ||
"BinaryCabin\\Recaptcha\\": "src" | ||
} | ||
}, | ||
"autoload-dev":{ | ||
"psr-4": { | ||
"BinaryCabin\\Recaptcha\\Tests\\": "tests" | ||
} | ||
}, | ||
"extra": { | ||
"laravel": { | ||
"providers": [ | ||
"BinaryCabin\\Recaptcha\\Providers\\RecaptchaServiceProvider" | ||
], | ||
"aliases": { | ||
"Recaptcha": "BinaryCabin\\Recaptcha\\Facades\\RecaptchaFacade" | ||
} | ||
} | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": ">5.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit backupGlobals="false" | ||
backupStaticAttributes="false" | ||
bootstrap="vendor/autoload.php" | ||
colors="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
stopOnFailure="false" | ||
> | ||
<testsuites> | ||
<testsuite name="Package Test Suite"> | ||
<directory suffix=".php">./tests/</directory> | ||
</testsuite> | ||
</testsuites> | ||
<filter> | ||
<whitelist> | ||
<directory suffix=".php">src/</directory> | ||
</whitelist> | ||
</filter> | ||
<logging> | ||
<log type="coverage-text" target="build/coverage.txt" /> | ||
</logging> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace BinaryCabin\Recaptcha\Configuration; | ||
|
||
class RecaptchaConfig | ||
{ | ||
private $recaptchaEnabled = true; | ||
private $recaptchaVersion = '3'; | ||
private $recaptchaSiteKey = null; | ||
private $recaptchaSecretKey = null; | ||
|
||
public function __construct() { | ||
$configArray = app('config')->get('recaptcha'); | ||
if(isset($configArray['enable'])){ | ||
$this->recaptchaEnabled = $configArray['enable']; | ||
} | ||
if(isset($configArray['version'])){ | ||
$this->recaptchaVersion = $configArray['version']; | ||
} | ||
if(!empty($configArray['site_key'])){ | ||
$this->recaptchaSiteKey = $configArray['site_key']; | ||
} | ||
if(!empty($configArray['secret_key'])){ | ||
$this->recaptchaSecretKey = $configArray['secret_key']; | ||
} | ||
} | ||
public function getRecaptchaEnabled() | ||
{ | ||
return $this->recaptchaEnabled; | ||
} | ||
|
||
public function getRecaptchaVersion() | ||
{ | ||
return $this->recaptchaVersion; | ||
} | ||
|
||
public function getRecaptchaSiteKey() | ||
{ | ||
return $this->recaptchaSiteKey; | ||
} | ||
|
||
public function getRecaptchaSecretKey() | ||
{ | ||
return $this->recaptchaSecretKey; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
return [ | ||
|
||
'enable' => env('RECAPTCHA_ENABLE', true), | ||
|
||
'version' => env('RECAPTCHA_VERSION', 3), | ||
|
||
'site_key' => env('RECAPTCHA_SITE_KEY', null), | ||
|
||
'secret_key' => env('RECAPTCHA_SECRET_KEY', null), | ||
|
||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace BinaryCabin\Recaptcha\Facades; | ||
|
||
use Illuminate\Support\Facades\Facade; | ||
|
||
class RecaptchaFacade extends Facade | ||
{ | ||
|
||
protected static function getFacadeAccessor() | ||
{ | ||
return 'recaptcha'; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
namespace BinaryCabin\Recaptcha\Providers; | ||
|
||
use BinaryCabin\Recaptcha\Configuration\RecaptchaConfig; | ||
use BinaryCabin\Recaptcha\Recaptcha; | ||
use Illuminate\Support\ServiceProvider; | ||
|
||
class RecaptchaServiceProvider extends ServiceProvider | ||
{ | ||
/** | ||
* Bootstrap the application services. | ||
* | ||
* @return void | ||
*/ | ||
public function boot() | ||
{ | ||
$this->addValidator(); | ||
$this->publishes([ | ||
__DIR__.'/../Configuration/Templates/recaptcha.php' => config_path('recaptcha.php'), | ||
],'config'); | ||
$this->loadViewsFrom(__DIR__.'/../views', 'recaptcha'); | ||
} | ||
|
||
/** | ||
* Register the application services. | ||
* | ||
* @return void | ||
*/ | ||
public function register() | ||
{ | ||
$this->bindRecaptcha(); | ||
} | ||
|
||
protected function bindRecaptcha() | ||
{ | ||
$this->app->bind('recaptcha', function () { | ||
return new Recaptcha(new RecaptchaConfig()); | ||
}); | ||
} | ||
|
||
/** | ||
* Extends Validator to include a recaptcha type | ||
*/ | ||
public function addValidator() | ||
{ | ||
$this->app->validator->extendImplicit('recaptcha', function ($attribute, $value, $parameters) { | ||
$recaptcha = app('recaptcha'); | ||
$challenge = app('request')->input($recaptcha->getInputName()); | ||
return $recaptcha->check($challenge, $value); | ||
}, 'Please ensure that you are a human!'); | ||
} | ||
|
||
} |
Oops, something went wrong.