first commit
This commit is contained in:
Vendored
+575
@@ -0,0 +1,575 @@
|
||||
<?php
|
||||
|
||||
namespace Mews\Captcha;
|
||||
|
||||
/**
|
||||
* Laravel 5 & 6 Captcha package
|
||||
*
|
||||
* @copyright Copyright (c) 2015 MeWebStudio
|
||||
* @version 2.x
|
||||
* @author Muharrem ERİN
|
||||
* @contact me@mewebstudio.com
|
||||
* @web http://www.mewebstudio.com
|
||||
* @date 2015-04-03
|
||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||
*/
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Contracts\Config\Repository;
|
||||
use Illuminate\Hashing\BcryptHasher as Hasher;
|
||||
use Illuminate\Filesystem\Filesystem;
|
||||
use Illuminate\Http\File;
|
||||
use Illuminate\Support\Str;
|
||||
use Intervention\Image\Gd\Font;
|
||||
use Intervention\Image\Geometry\Factories\LineFactory;
|
||||
use Intervention\Image\Image;
|
||||
use Intervention\Image\ImageManager;
|
||||
use Illuminate\Session\Store as Session;
|
||||
use Illuminate\Support\HtmlString;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Crypt;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
|
||||
/**
|
||||
* Class Captcha
|
||||
* @package Mews\Captcha
|
||||
*/
|
||||
class Captcha
|
||||
{
|
||||
/**
|
||||
* @var Filesystem
|
||||
*/
|
||||
protected $files;
|
||||
|
||||
/**
|
||||
* @var Repository
|
||||
*/
|
||||
protected $config;
|
||||
|
||||
/**
|
||||
* @var ImageManager
|
||||
*/
|
||||
protected $imageManager;
|
||||
|
||||
/**
|
||||
* @var Session
|
||||
*/
|
||||
protected $session;
|
||||
|
||||
/**
|
||||
* @var Hasher
|
||||
*/
|
||||
protected $hasher;
|
||||
|
||||
/**
|
||||
* @var Str
|
||||
*/
|
||||
protected $str;
|
||||
|
||||
/**
|
||||
* @var ImageManager->canvas
|
||||
*/
|
||||
protected $canvas;
|
||||
|
||||
/**
|
||||
* @var Image
|
||||
*/
|
||||
protected $image;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $backgrounds = [];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $fonts = [];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $fontColors = [];
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $length = 5;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $width = 120;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $height = 36;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $angle = 15;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $lines = 3;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $lineWidth = 2;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $lineColor = 'ff00ff';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $characters;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $text;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $contrast = 0;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $quality = 90;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $sharpen = 0;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $blur = 0;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $bgsDirectory;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $bgImage = true;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $bgColor = '#ffffff';
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $invert = false;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $sensitive = false;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $math = false;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $textLeftPadding = 4;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $fontsDirectory;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $expire = 60;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $encrypt = true;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $marginTop = 0;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Filesystem $files
|
||||
* @param Repository $config
|
||||
* @param ImageManager $imageManager
|
||||
* @param Session $session
|
||||
* @param Hasher $hasher
|
||||
* @param Str $str
|
||||
* @throws Exception
|
||||
* @internal param Validator $validator
|
||||
*/
|
||||
public function __construct(
|
||||
Filesystem $files,
|
||||
Repository $config,
|
||||
ImageManager $imageManager,
|
||||
Session $session,
|
||||
Hasher $hasher,
|
||||
Str $str
|
||||
) {
|
||||
$this->files = $files;
|
||||
$this->config = $config;
|
||||
$this->imageManager = $imageManager;
|
||||
$this->session = $session;
|
||||
$this->hasher = $hasher;
|
||||
$this->str = $str;
|
||||
$this->characters = config('captcha.characters', ['1', '2', '3', '4', '6', '7', '8', '9']);
|
||||
$this->fontsDirectory = config('captcha.fontsDirectory', dirname(__DIR__) . '/assets/fonts');
|
||||
$this->bgsDirectory = config('captcha.bgsDirectory', dirname(__DIR__) . '/assets/backgrounds');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $config
|
||||
* @return void
|
||||
*/
|
||||
protected function configure($config)
|
||||
{
|
||||
if ($this->config->has('captcha.' . $config)) {
|
||||
foreach ($this->config->get('captcha.' . $config) as $key => $val) {
|
||||
$this->{$key} = $val;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create captcha image
|
||||
*
|
||||
* @param string $config
|
||||
* @param bool $api
|
||||
* @return array|mixed
|
||||
* @throws Exception
|
||||
*/
|
||||
public function create(string $config = 'default', bool $api = false)
|
||||
{
|
||||
$this->backgrounds = $this->files->files($this->bgsDirectory);
|
||||
$this->fonts = $this->files->files($this->fontsDirectory);
|
||||
|
||||
if (version_compare(app()->version(), '5.5.0', '>=')) {
|
||||
$this->fonts = array_map(function ($file) {
|
||||
/* @var File $file */
|
||||
return $file->getPathName();
|
||||
}, $this->fonts);
|
||||
}
|
||||
|
||||
$this->fonts = array_values($this->fonts); //reset fonts array index
|
||||
|
||||
$this->configure($config);
|
||||
|
||||
$generator = $this->generate();
|
||||
$this->text = $generator['value'];
|
||||
|
||||
$this->canvas = $this->imageManager->create($this->width , $this->height)->fill($this->bgColor);
|
||||
|
||||
if ($this->bgImage) {
|
||||
$this->image = $this->imageManager->read($this->background())->resize(
|
||||
$this->width,
|
||||
$this->height
|
||||
);
|
||||
$this->canvas->place($this->image);
|
||||
} else {
|
||||
$this->image = $this->canvas;
|
||||
}
|
||||
|
||||
if ($this->contrast != 0) {
|
||||
$this->image->contrast($this->contrast);
|
||||
}
|
||||
|
||||
$this->text();
|
||||
|
||||
$this->lines();
|
||||
|
||||
if ($this->sharpen) {
|
||||
$this->image->sharpen($this->sharpen);
|
||||
}
|
||||
if ($this->invert) {
|
||||
$this->image->invert();
|
||||
}
|
||||
if ($this->blur) {
|
||||
$this->image->blur($this->blur);
|
||||
}
|
||||
|
||||
Cache::put($this->get_cache_key($generator['key']), $generator['value'], $this->expire);
|
||||
|
||||
return $api ? [
|
||||
'sensitive' => $generator['sensitive'],
|
||||
'key' => $generator['key'],
|
||||
'img' => $this->image->toJpg()->toDataUri()
|
||||
] : new Response($this->image->toJpg(), 200, [
|
||||
'Content-Type' => 'image/jpeg',
|
||||
'Content-Disposition' => 'inline; filename="image.jpg"',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Image backgrounds
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function background(): string
|
||||
{
|
||||
return $this->backgrounds[rand(0, count($this->backgrounds) - 1)];
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate captcha text
|
||||
*
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function generate(): array
|
||||
{
|
||||
$characters = is_string($this->characters) ? str_split($this->characters) : $this->characters;
|
||||
|
||||
$bag = [];
|
||||
|
||||
if ($this->math) {
|
||||
$x = random_int(10, 30);
|
||||
$y = random_int(1, 9);
|
||||
$bag = "$x + $y = ";
|
||||
$key = $x + $y;
|
||||
$key .= '';
|
||||
} else {
|
||||
for ($i = 0; $i < $this->length; $i++) {
|
||||
$char = $characters[rand(0, count($characters) - 1)];
|
||||
$bag[] = $this->sensitive ? $char : $this->str->lower($char);
|
||||
}
|
||||
$key = implode('', $bag);
|
||||
}
|
||||
|
||||
$hash = $this->hasher->make($key);
|
||||
if($this->encrypt) $hash = Crypt::encrypt($hash);
|
||||
|
||||
$this->session->put('captcha', [
|
||||
'sensitive' => $this->sensitive,
|
||||
'key' => $hash,
|
||||
'encrypt' => $this->encrypt
|
||||
]);
|
||||
|
||||
return [
|
||||
'value' => $bag,
|
||||
'sensitive' => $this->sensitive,
|
||||
'key' => $hash
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Writing captcha text
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function text(): void
|
||||
{
|
||||
$marginTop = $this->image->height() / $this->length;
|
||||
if ($this->marginTop !== 0) {
|
||||
$marginTop = $this->marginTop;
|
||||
}
|
||||
|
||||
$text = $this->text;
|
||||
if (is_string($text)) {
|
||||
$text = str_split($text);
|
||||
}
|
||||
|
||||
foreach ($text as $key => $char) {
|
||||
$marginLeft = $this->textLeftPadding + ($key * ($this->image->width() - $this->textLeftPadding) / $this->length);
|
||||
|
||||
$this->image->text($char, (int) $marginLeft, (int) $marginTop, function ($font) {
|
||||
/* @var Font $font */
|
||||
$font->file($this->font());
|
||||
$font->size($this->fontSize());
|
||||
$font->color($this->fontColor());
|
||||
$font->align('left');
|
||||
$font->valign('top');
|
||||
$font->angle($this->angle());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Image fonts
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function font(): string
|
||||
{
|
||||
return $this->fonts[rand(0, count($this->fonts) - 1)];
|
||||
}
|
||||
|
||||
/**
|
||||
* Random font size
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
protected function fontSize(): int
|
||||
{
|
||||
return rand($this->image->height() - 10, $this->image->height());
|
||||
}
|
||||
|
||||
/**
|
||||
* Random font color
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function fontColor(): string
|
||||
{
|
||||
if (!empty($this->fontColors)) {
|
||||
$color = $this->fontColors[rand(0, count($this->fontColors) - 1)];
|
||||
} else {
|
||||
$color = '#' . str_pad(dechex(mt_rand(0, 0xFFFFFF)), 6, '0', STR_PAD_LEFT);
|
||||
}
|
||||
|
||||
return $color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Angle
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
protected function angle(): int
|
||||
{
|
||||
return rand((-1 * $this->angle), $this->angle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Random image lines
|
||||
*
|
||||
* @return Image|ImageManager
|
||||
*/
|
||||
protected function lines()
|
||||
{
|
||||
for ($i = 0; $i <= $this->lines; $i++) {
|
||||
$this->image->drawLine(function (LineFactory $line) use ($i) {
|
||||
$line->from(rand(0, $this->image->width()) + $i * rand(0, $this->image->height()) , rand(0, $this->image->height()));
|
||||
$line->to( rand(0, $this->image->width()), rand(0, $this->image->height()));
|
||||
$line->color($this->lineColor); // color of line
|
||||
$line->width($this->lineWidth); // line width in pixels
|
||||
});
|
||||
}
|
||||
|
||||
return $this->image;
|
||||
}
|
||||
|
||||
/**
|
||||
* Captcha check
|
||||
*
|
||||
* @param string $value
|
||||
* @return bool
|
||||
*/
|
||||
public function check(string $value): bool
|
||||
{
|
||||
if (!$this->session->has('captcha')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$key = $this->session->get('captcha.key');
|
||||
$sensitive = $this->session->get('captcha.sensitive');
|
||||
$encrypt = $this->session->get('captcha.encrypt');
|
||||
|
||||
if (!Cache::pull($this->get_cache_key($key))) {
|
||||
$this->session->remove('captcha');
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!$sensitive) {
|
||||
$value = $this->str->lower($value);
|
||||
}
|
||||
|
||||
if($encrypt) $key = Crypt::decrypt($key);
|
||||
$check = $this->hasher->check($value, $key);
|
||||
// if verify pass,remove session
|
||||
if ($check) {
|
||||
$this->session->remove('captcha');
|
||||
}
|
||||
|
||||
return $check;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the md5 short version of the key for cache
|
||||
*
|
||||
* @param string $key
|
||||
* @return string
|
||||
*/
|
||||
protected function get_cache_key($key) {
|
||||
return 'captcha_' . md5($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Captcha check
|
||||
*
|
||||
* @param string $value
|
||||
* @param string $key
|
||||
* @param string $config
|
||||
* @return bool
|
||||
*/
|
||||
public function check_api($value, $key, $config = 'default'): bool
|
||||
{
|
||||
if (!Cache::pull($this->get_cache_key($key))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->configure($config);
|
||||
|
||||
if(!$this->sensitive) $value = $this->str->lower($value);
|
||||
if($this->encrypt) $key = Crypt::decrypt($key);
|
||||
return $this->hasher->check($value, $key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate captcha image source
|
||||
*
|
||||
* @param string $config
|
||||
* @return string
|
||||
*/
|
||||
public function src(string $config = 'default'): string
|
||||
{
|
||||
return url('captcha/' . $config) . '?' . $this->str->random(8);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate captcha image html tag
|
||||
*
|
||||
* @param string $config
|
||||
* @param array $attrs
|
||||
* $attrs -> HTML attributes supplied to the image tag where key is the attribute and the value is the attribute value
|
||||
* @return string
|
||||
*/
|
||||
public function img(string $config = 'default', array $attrs = []): string
|
||||
{
|
||||
$attrs_str = '';
|
||||
foreach ($attrs as $attr => $value) {
|
||||
if ($attr == 'src') {
|
||||
//Neglect src attribute
|
||||
continue;
|
||||
}
|
||||
|
||||
$attrs_str .= $attr . '="' . $value . '" ';
|
||||
}
|
||||
return new HtmlString('<img src="' . $this->src($config) . '" ' . trim($attrs_str) . '>');
|
||||
}
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace Mews\Captcha;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Routing\Controller;
|
||||
|
||||
/**
|
||||
* Class CaptchaController
|
||||
* @package Mews\Captcha
|
||||
*/
|
||||
class CaptchaController extends Controller
|
||||
{
|
||||
/**
|
||||
* get CAPTCHA
|
||||
*
|
||||
* @param Captcha $captcha
|
||||
* @param string $config
|
||||
* @return array|mixed
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getCaptcha(Captcha $captcha, string $config = 'default')
|
||||
{
|
||||
if (ob_get_contents()) {
|
||||
ob_clean();
|
||||
}
|
||||
|
||||
return $captcha->create($config);
|
||||
}
|
||||
|
||||
/**
|
||||
* get CAPTCHA api
|
||||
*
|
||||
* @param Captcha $captcha
|
||||
* @param string $config
|
||||
* @return array|mixed
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getCaptchaApi(Captcha $captcha, string $config = 'default')
|
||||
{
|
||||
return $captcha->create($config, true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
namespace Mews\Captcha;
|
||||
|
||||
use Illuminate\Routing\Router;
|
||||
use Illuminate\Validation\Factory;
|
||||
use Intervention\Image\ImageManager;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Intervention\Image\Drivers\Gd\Driver as GdDriver;
|
||||
use Intervention\Image\Drivers\Imagick\Driver as ImagickDriver;
|
||||
|
||||
/**
|
||||
* Class CaptchaServiceProvider
|
||||
* @package Mews\Captcha
|
||||
*/
|
||||
class CaptchaServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Boot the service provider.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
// Publish configuration files
|
||||
$this->publishes([
|
||||
__DIR__ . '/../config/captcha.php' => config_path('captcha.php')
|
||||
], 'config');
|
||||
|
||||
// HTTP routing
|
||||
if(!config('captcha.disable')){
|
||||
if (strpos($this->app->version(), 'Lumen') !== false) {
|
||||
/* @var Router $router */
|
||||
$router = $this->app;
|
||||
$router->get('captcha[/api/{config}]', 'Mews\Captcha\LumenCaptchaController@getCaptchaApi');
|
||||
$router->get('captcha[/{config}]', 'Mews\Captcha\LumenCaptchaController@getCaptcha');
|
||||
} else {
|
||||
/* @var Router $router */
|
||||
$router = $this->app['router'];
|
||||
if ((double)$this->app->version() >= 5.2) {
|
||||
$router->get('captcha/api/{config?}', '\Mews\Captcha\CaptchaController@getCaptchaApi')->middleware('web');
|
||||
$router->get('captcha/{config?}', '\Mews\Captcha\CaptchaController@getCaptcha')->middleware('web');
|
||||
} else {
|
||||
$router->get('captcha/api/{config?}', '\Mews\Captcha\CaptchaController@getCaptchaApi');
|
||||
$router->get('captcha/{config?}', '\Mews\Captcha\CaptchaController@getCaptcha');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* @var Factory $validator */
|
||||
$validator = $this->app['validator'];
|
||||
|
||||
// Validator extensions
|
||||
$validator->extend('captcha', function ($attribute, $value, $parameters) {
|
||||
return config('captcha.disable') || ($value && captcha_check($value));
|
||||
});
|
||||
|
||||
// Validator extensions
|
||||
$validator->extend('captcha_api', function ($attribute, $value, $parameters) {
|
||||
return config('captcha.disable') || ($value && captcha_api_check($value, $parameters[0], $parameters[1] ?? 'default'));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the service provider.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register(): void
|
||||
{
|
||||
// Merge configs
|
||||
$this->mergeConfigFrom(
|
||||
__DIR__ . '/../config/captcha.php',
|
||||
'captcha'
|
||||
);
|
||||
|
||||
// Bind the ImageManager with an explicit driver
|
||||
if (!$this->app->bound('Intervention\Image\ImageManager')) {
|
||||
$this->app->singleton('Intervention\Image\ImageManager', function ($app) {
|
||||
// Determine which driver to use, defaulting to 'gd'
|
||||
$driver = config('captcha.driver', 'gd') === 'imagick' ? new ImagickDriver() : new GdDriver();
|
||||
|
||||
return new ImageManager($driver);
|
||||
});
|
||||
}
|
||||
|
||||
// Bind captcha
|
||||
$this->app->bind('captcha', function ($app) {
|
||||
return new Captcha(
|
||||
$app['Illuminate\Filesystem\Filesystem'],
|
||||
$app['Illuminate\Contracts\Config\Repository'],
|
||||
$app['Intervention\Image\ImageManager'],
|
||||
$app['Illuminate\Session\Store'],
|
||||
$app['Illuminate\Hashing\BcryptHasher'],
|
||||
$app['Illuminate\Support\Str']
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Mews\Captcha\Facades;
|
||||
|
||||
use Illuminate\Support\Facades\Facade;
|
||||
|
||||
/**
|
||||
* @see \Mews\Captcha\Captcha
|
||||
*/
|
||||
class Captcha extends Facade
|
||||
{
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected static function getFacadeAccessor()
|
||||
{
|
||||
return 'captcha';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace Mews\Captcha;
|
||||
|
||||
use Exception;
|
||||
use Laravel\Lumen\Routing\Controller;
|
||||
|
||||
/**
|
||||
* Class CaptchaController
|
||||
* @package Mews\Captcha
|
||||
*/
|
||||
class LumenCaptchaController extends Controller
|
||||
{
|
||||
/**
|
||||
* get CAPTCHA
|
||||
*
|
||||
* @param Captcha $captcha
|
||||
* @param string $config
|
||||
* @return array|mixed
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getCaptcha(Captcha $captcha, $config = 'default')
|
||||
{
|
||||
return $captcha->create($config);
|
||||
}
|
||||
}
|
||||
Vendored
+63
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
use Intervention\Image\ImageManager;
|
||||
|
||||
if (!function_exists('captcha')) {
|
||||
/**
|
||||
* @param string $config
|
||||
* @return array|ImageManager|mixed
|
||||
* @throws Exception
|
||||
*/
|
||||
function captcha(string $config = 'default')
|
||||
{
|
||||
return app('captcha')->create($config);
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('captcha_src')) {
|
||||
/**
|
||||
* @param string $config
|
||||
* @return string
|
||||
*/
|
||||
function captcha_src(string $config = 'default'): string
|
||||
{
|
||||
return app('captcha')->src($config);
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('captcha_img')) {
|
||||
|
||||
/**
|
||||
* @param string $config
|
||||
* @param array $attrs
|
||||
* @return string
|
||||
*/
|
||||
function captcha_img(string $config = 'default', array $attrs = []): string
|
||||
{
|
||||
return app('captcha')->img($config, $attrs);
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('captcha_check')) {
|
||||
/**
|
||||
* @param string $value
|
||||
* @return bool
|
||||
*/
|
||||
function captcha_check(string $value): bool
|
||||
{
|
||||
return app('captcha')->check($value);
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('captcha_api_check')) {
|
||||
/**
|
||||
* @param string $value
|
||||
* @param string $key
|
||||
* @param string $config
|
||||
* @return bool
|
||||
*/
|
||||
function captcha_api_check(string $value, string $key, string $config = 'default'): bool
|
||||
{
|
||||
return app('captcha')->check_api($value, $key, $config);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user