├── .styleci.yml ├── .gitignore ├── resources └── images │ └── arcaptcha-logo.png ├── src ├── helpers.php ├── Facade │ └── ArCaptcha.php └── ArCaptchaServiceProvider.php ├── tests └── TestCase.php ├── .travis.yml ├── phpunit.xml ├── config └── arcaptcha.php ├── LICENSE ├── composer.json └── README.md /.styleci.yml: -------------------------------------------------------------------------------- 1 | preset: laravel -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /vendor/ 2 | .phpunit.result.cache 3 | .idea 4 | composer.lock 5 | -------------------------------------------------------------------------------- /resources/images/arcaptcha-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arcaptcha/arcaptcha-laravel/HEAD/resources/images/arcaptcha-logo.png -------------------------------------------------------------------------------- /src/helpers.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | ./tests/ 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/Facade/ArCaptcha.php: -------------------------------------------------------------------------------- 1 | env('ARCAPTCHA_SITE_KEY', ''), 9 | 10 | /** 11 | * The secret key 12 | * get secret key @ arcaptcha.ir/dashboard. 13 | */ 14 | 'secret_key' => env('ARCAPTCHA_SECRET_KEY', ''), 15 | 16 | 17 | /** 18 | * Default returned value from verify function 19 | * when there is an Network or any other unexpected issue. 20 | */ 21 | 'verify_exception_value' => env('ARCAPTCHA_VERIFY_EXCEPTION_VALUE', 'false'), 22 | 23 | ]; 24 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Mohammad Abbasi 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "arcaptcha/arcaptcha-laravel", 3 | "description": "Laravel Package for the ArCaptcha", 4 | "homepage": "https://github.com/arcaptcha/arcaptcha-laravel", 5 | "keywords": [ 6 | "laravel", 7 | "arcaptcha", 8 | "captcha", 9 | "php captcha", 10 | "laravel captcha", 11 | "laravel package", 12 | "persian-captcha" 13 | ], 14 | "authors": [ 15 | { 16 | "name": "Mohammad Abbasi", 17 | "email": "mohammad.v184@gmail.com" 18 | } 19 | ], 20 | "require": { 21 | "php": ">=7.3", 22 | "arcaptcha/arcaptcha-php": "^1.0", 23 | "laravel/framework": ">=5.0" 24 | }, 25 | "require-dev": { 26 | "squizlabs/php_codesniffer": "^3.6", 27 | "orchestra/testbench": "^6.19" 28 | }, 29 | "autoload": { 30 | "psr-4": { 31 | "Mohammadv184\\ArCaptcha\\Laravel\\": "src" 32 | }, 33 | "files": [ 34 | "src/helpers.php" 35 | ] 36 | }, 37 | "autoload-dev": { 38 | "psr-4": { 39 | "Mohammadv184\\ArCaptcha\\Laravel\\Tests\\": "tests" 40 | } 41 | }, 42 | "license": "MIT", 43 | "scripts": { 44 | "test": "phpunit", 45 | "check-style": "phpcs -p --standard=PSR2 --runtime-set ignore_errors_on_exit 1 --runtime-set ignore_warnings_on_exit 1 src tests", 46 | "fix-style": "phpcbf -p --standard=PSR2 --runtime-set ignore_errors_on_exit 1 --runtime-set ignore_warnings_on_exit 1 src tests" 47 | }, 48 | "suggest": { 49 | "mohammadv184/arcaptcha": "PHP library for ArCaptcha" 50 | }, 51 | "extra": { 52 | "laravel": { 53 | "providers": [ 54 | "Mohammadv184\\ArCaptcha\\Laravel\\ArCaptchaServiceProvider" 55 | ], 56 | "aliases": { 57 | "ArCaptcha": "Mohammadv184\\ArCaptcha\\Laravel\\Facade\\ArCaptcha" 58 | } 59 | } 60 | }, 61 | "config": { 62 | "sort-packages": true 63 | } 64 | } -------------------------------------------------------------------------------- /src/ArCaptchaServiceProvider.php: -------------------------------------------------------------------------------- 1 | mergeConfigFrom( 18 | __DIR__ . '/../config/arcaptcha.php', 19 | 'arcaptcha' 20 | ); 21 | 22 | $this->app->singleton('arcaptcha', function () { 23 | $config = config('arcaptcha'); 24 | 25 | return new ArCaptcha( 26 | $config['site_key'], 27 | $config['secret_key'], 28 | ['verify_exception_value' => $config['verify_exception_value']] 29 | ); 30 | }); 31 | } 32 | 33 | /** 34 | *service provider boot method. 35 | */ 36 | public function boot() 37 | { 38 | $this->publishes([ 39 | __DIR__ . '/../config/arcaptcha.php' => config_path('arcaptcha.php') 40 | ], 'config'); 41 | 42 | $this->addValidationRule(); 43 | 44 | $this->addBladeDirective(); 45 | } 46 | 47 | /** 48 | * Add Validation Rule. 49 | */ 50 | protected function addValidationRule(): void 51 | { 52 | Validator::extendImplicit('arcaptcha', function ($attribute, $value, $parameters) { 53 | if (is_null($value)) { 54 | return false; 55 | } 56 | return app('arcaptcha')->verify($value); 57 | }, trans('validation.arcaptcha')); 58 | } 59 | 60 | /** 61 | * add blade Directive. 62 | */ 63 | protected function addBladeDirective(): void 64 | { 65 | Blade::directive('arcaptchaScript', function () { 66 | return ''; 67 | }); 68 | Blade::directive('arcaptchaWidget', function ($options) { 69 | return ""; 70 | }); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

ArCaptcha

2 | 3 | # Laravel ArCaptcha Package 4 | 5 | [![Latest Stable Version](http://poser.pugx.org/arcaptcha/arcaptcha-laravel/v)](https://packagist.org/packages/arcaptcha/arcaptcha-laravel) 6 | [![Total Downloads](http://poser.pugx.org/arcaptcha/arcaptcha-laravel/downloads)](https://packagist.org/packages/arcaptcha/arcaptcha-laravel) [![Latest Unstable Version](http://poser.pugx.org/arcaptcha/arcaptcha-laravel/v/unstable)](https://packagist.org/packages/arcaptcha/arcaptcha-laravel) 7 | [![License](http://poser.pugx.org/arcaptcha/arcaptcha-laravel/license)](https://packagist.org/packages/arcaptcha/arcaptcha-laravel) 8 | [![PHP Version Require](http://poser.pugx.org/arcaptcha/arcaptcha-laravel/require/php)](https://packagist.org/packages/arcaptcha/arcaptcha-laravel) 9 | 10 | Laravel Package for the ArCaptcha 11 | This package supports `PHP 7.3+`. 12 | 13 | For **PHP** integration you can use [mohammadv184/arcaptcha](https://github.com/mohammadv184/arcaptcha) package. 14 | 15 | # List of contents 16 | 17 | - [PHP ArCaptcha Library](#PHP-ArCaptcha-Library) 18 | - [List of contents](#list-of-contents) 19 | - [Installation](#Installation) 20 | - [Configuration](#Configuration) 21 | - [Publish package](#publish-package) 22 | - [Set the environment](#set-the-environment) 23 | - [Customize error message](#customize-error-message) 24 | - [How to use](#how-to-use) 25 | - [Embed Script in Blade](#Embed-Script-in-Blade) 26 | - [Form setup](#Form-setup) 27 | - [Verify submitted data](#Verify-submitted-data) 28 | - [Credits](#credits) 29 | - [License](#license) 30 | 31 | ## Installation 32 | 33 | You can install the package via composer: 34 | 35 | ```bash 36 | composer require arcaptcha/arcaptcha-laravel 37 | ``` 38 | 39 | Laravel 5.5 (or greater) uses package auto-discovery, so doesn't require you to manually add the Service Provider, but if you 40 | don't use auto-discovery ArCaptchaServiceProvider must be registered in config/app.php: 41 | 42 | ```php 43 | 'providers' => [ 44 | ... 45 | Mohammadv184\ArCaptcha\Laravel\ArCaptchaServiceProvider::class, 46 | ]; 47 | ``` 48 | 49 | You can use the facade for shorter code. Add ArCaptcha to your aliases: 50 | 51 | ```php 52 | 'aliases' => [ 53 | ... 54 | 'ArCaptcha' => Mohammadv184\ArCaptcha\Laravel\Facade\ArCaptcha::class, 55 | ]; 56 | ``` 57 | 58 | ## Configuration 59 | 60 | ### Publish package 61 | 62 | Create config/arcaptcha.php configuration file using the following artisan command: 63 | 64 | ```php 65 | php artisan vendor:publish --provider="Mohammadv184\ArCaptcha\Laravel\ArCaptchaServiceProvider" 66 | ``` 67 | 68 | ### Set the environment 69 | 70 | Open .env file and set `ARCAPTCHA_SITE_KEY` and `ARCAPTCHA_SECRET_KEY`: 71 | 72 | ```dotenv 73 | # in your .env file 74 | ARCAPTCHA_SITE_KEY=YOUR_API_SITE_KEY 75 | ARCAPTCHA_SECRET_KEY=YOUR_API_SECRET_KEY 76 | 77 | # Optional: Default returned value from verify function 78 | # when there is an Network or any other unexpected issue. 79 | ARCAPTCHA_VERIFY_EXCEPTION_VALUE=true 80 | ``` 81 | 82 | ### Customize error message 83 | 84 | Before starting please add the validation message to `resources/lang/[LANG]/validation.php` file 85 | 86 | ```php 87 | return [ 88 | ... 89 | 'arcaptcha' => 'Hey!!! :attribute is wrong!', 90 | ]; 91 | ``` 92 | 93 | ## How to use 94 | 95 | How to use ArCaptcha in Laravel. 96 | 97 | ### Embed Script in Blade 98 | 99 | Insert `@arcaptchaScript` blade directive before closing `` tag. 100 | 101 | You can also use `ArCaptcha::getScript()`. 102 | 103 | ```html 104 | 105 | 106 | 107 | ... @arcaptchaScript 108 | 109 | 110 | ``` 111 | 112 | ### Form setup 113 | 114 | After you have to insert `@arcaptchaWidget` blade directive inside the form where you want to use the field `arcaptcha-token`. 115 | 116 | You can also use `ArCaptcha::getWidget()`. 117 | 118 | _Note : You can pass widget options into getWidget function or arcaptchaWidget directive like this : @arcaptchaWidget(['lang'=>'en'])_ 119 | 120 | _To see available options on widget see [here](https://docs.arcaptcha.ir/docs/configuration#arcaptcha-container-configuration)_ 121 | 122 | ```html 123 |
124 | @csrf ... @arcaptchaWidget 125 | 126 | {!! ArCaptcha::getWidget() !!} 127 | 128 |
129 | ``` 130 | 131 | ### Verify submitted data 132 | 133 | Add `arcaptcha` to your rules 134 | 135 | ```php 136 | $validator = Validator::make(request()->all(), [ 137 | ... 138 | 'arcaptcha-token' => 'arcaptcha', 139 | ]); 140 | 141 | // check if validator fails 142 | if($validator->fails()) { 143 | ... 144 | $errors = $validator->errors(); 145 | } 146 | ``` 147 | 148 | ## Invisible mode example 149 | 150 | Just try to pass `size` and `callback` option to getWidget function. Make sure to define callback function in global scope: 151 | 152 | ```html 153 |
154 | {!! ArCaptcha::getWidget([ 'size'=>'invisible','callback'=>'callback']) !!} 155 | 156 | 157 | 162 |
163 | ``` 164 | 165 | ## Credits 166 | 167 | - [Mohammad Abbasi](https://github.com/mohammadv184) 168 | - [All Contributors](../../contributors) 169 | 170 | ## License 171 | 172 | The MIT License (MIT). Please see [License File](LICENSE) for more information. 173 | --------------------------------------------------------------------------------