@@ -2,7 +2,7 @@ discard block |
||
| 2 | 2 | |
| 3 | 3 | use Intervention\Image\ImageManager; |
| 4 | 4 | |
| 5 | -if (!function_exists('captcha')) { |
|
| 5 | +if ( ! function_exists('captcha')) { |
|
| 6 | 6 | /** |
| 7 | 7 | * @param string $config |
| 8 | 8 | * @return array|ImageManager|mixed |
@@ -14,7 +14,7 @@ discard block |
||
| 14 | 14 | } |
| 15 | 15 | } |
| 16 | 16 | |
| 17 | -if (!function_exists('captcha_src')) { |
|
| 17 | +if ( ! function_exists('captcha_src')) { |
|
| 18 | 18 | /** |
| 19 | 19 | * @param string $config |
| 20 | 20 | * @return string |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | } |
| 26 | 26 | } |
| 27 | 27 | |
| 28 | -if (!function_exists('captcha_img')) { |
|
| 28 | +if ( ! function_exists('captcha_img')) { |
|
| 29 | 29 | |
| 30 | 30 | /** |
| 31 | 31 | * @param string $config |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | } |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | -if (!function_exists('captcha_check')) { |
|
| 40 | +if ( ! function_exists('captcha_check')) { |
|
| 41 | 41 | /** |
| 42 | 42 | * @param string $value |
| 43 | 43 | * @return bool |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | } |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | -if (!function_exists('captcha_api_check')) { |
|
| 51 | +if ( ! function_exists('captcha_api_check')) { |
|
| 52 | 52 | /** |
| 53 | 53 | * @param string $value |
| 54 | 54 | * @param string $key |
@@ -341,7 +341,9 @@ discard block |
||
| 341 | 341 | } |
| 342 | 342 | |
| 343 | 343 | $hash = $this->hasher->make($key); |
| 344 | - if($this->encrypt) $hash = Crypt::encrypt($hash); |
|
| 344 | + if($this->encrypt) { |
|
| 345 | + $hash = Crypt::encrypt($hash); |
|
| 346 | + } |
|
| 345 | 347 | |
| 346 | 348 | $this->session->put('captcha', [ |
| 347 | 349 | 'sensitive' => $this->sensitive, |
@@ -474,7 +476,9 @@ discard block |
||
| 474 | 476 | $value = $this->str->lower($value); |
| 475 | 477 | } |
| 476 | 478 | |
| 477 | - if($encrypt) $key = Crypt::decrypt($key); |
|
| 479 | + if($encrypt) { |
|
| 480 | + $key = Crypt::decrypt($key); |
|
| 481 | + } |
|
| 478 | 482 | $check = $this->hasher->check($value, $key); |
| 479 | 483 | // if verify pass,remove session |
| 480 | 484 | if ($check) { |
@@ -500,8 +504,12 @@ discard block |
||
| 500 | 504 | |
| 501 | 505 | $this->configure($config); |
| 502 | 506 | |
| 503 | - if(!$this->sensitive) $value = $this->str->lower($value); |
|
| 504 | - if($this->encrypt) $key = Crypt::decrypt($key); |
|
| 507 | + if(!$this->sensitive) { |
|
| 508 | + $value = $this->str->lower($value); |
|
| 509 | + } |
|
| 510 | + if($this->encrypt) { |
|
| 511 | + $key = Crypt::decrypt($key); |
|
| 512 | + } |
|
| 505 | 513 | return $this->hasher->check($value, $key); |
| 506 | 514 | } |
| 507 | 515 | |
@@ -221,7 +221,7 @@ discard block |
||
| 221 | 221 | $this->hasher = $hasher; |
| 222 | 222 | $this->str = $str; |
| 223 | 223 | $this->characters = config('captcha.characters', ['1', '2', '3', '4', '6', '7', '8', '9']); |
| 224 | - $this->fontsDirectory = config('captcha.fontsDirectory', dirname(__DIR__) . '/assets/fonts'); |
|
| 224 | + $this->fontsDirectory = config('captcha.fontsDirectory', dirname(__DIR__).'/assets/fonts'); |
|
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | /** |
@@ -230,8 +230,8 @@ discard block |
||
| 230 | 230 | */ |
| 231 | 231 | protected function configure($config) |
| 232 | 232 | { |
| 233 | - if ($this->config->has('captcha.' . $config)) { |
|
| 234 | - foreach ($this->config->get('captcha.' . $config) as $key => $val) { |
|
| 233 | + if ($this->config->has('captcha.'.$config)) { |
|
| 234 | + foreach ($this->config->get('captcha.'.$config) as $key => $val) { |
|
| 235 | 235 | $this->{$key} = $val; |
| 236 | 236 | } |
| 237 | 237 | } |
@@ -247,11 +247,11 @@ discard block |
||
| 247 | 247 | */ |
| 248 | 248 | public function create(string $config = 'default', bool $api = false) |
| 249 | 249 | { |
| 250 | - $this->backgrounds = $this->files->files(__DIR__ . '/../assets/backgrounds'); |
|
| 250 | + $this->backgrounds = $this->files->files(__DIR__.'/../assets/backgrounds'); |
|
| 251 | 251 | $this->fonts = $this->files->files($this->fontsDirectory); |
| 252 | 252 | |
| 253 | 253 | if (version_compare(app()->version(), '5.5.0', '>=')) { |
| 254 | - $this->fonts = array_map(function ($file) { |
|
| 254 | + $this->fonts = array_map(function($file) { |
|
| 255 | 255 | /* @var File $file */ |
| 256 | 256 | return $file->getPathName(); |
| 257 | 257 | }, $this->fonts); |
@@ -344,7 +344,7 @@ discard block |
||
| 344 | 344 | } |
| 345 | 345 | |
| 346 | 346 | $hash = $this->hasher->make($key); |
| 347 | - if($this->encrypt) $hash = Crypt::encrypt($hash); |
|
| 347 | + if ($this->encrypt) $hash = Crypt::encrypt($hash); |
|
| 348 | 348 | |
| 349 | 349 | $this->session->put('captcha', [ |
| 350 | 350 | 'sensitive' => $this->sensitive, |
@@ -379,7 +379,7 @@ discard block |
||
| 379 | 379 | foreach ($text as $key => $char) { |
| 380 | 380 | $marginLeft = $this->textLeftPadding + ($key * ($this->image->width() - $this->textLeftPadding) / $this->length); |
| 381 | 381 | |
| 382 | - $this->image->text($char, $marginLeft, $marginTop, function ($font) { |
|
| 382 | + $this->image->text($char, $marginLeft, $marginTop, function($font) { |
|
| 383 | 383 | /* @var Font $font */ |
| 384 | 384 | $font->file($this->font()); |
| 385 | 385 | $font->size($this->fontSize()); |
@@ -418,10 +418,10 @@ discard block |
||
| 418 | 418 | */ |
| 419 | 419 | protected function fontColor(): string |
| 420 | 420 | { |
| 421 | - if (!empty($this->fontColors)) { |
|
| 421 | + if ( ! empty($this->fontColors)) { |
|
| 422 | 422 | $color = $this->fontColors[rand(0, count($this->fontColors) - 1)]; |
| 423 | 423 | } else { |
| 424 | - $color = '#' . str_pad(dechex(mt_rand(0, 0xFFFFFF)), 6, '0', STR_PAD_LEFT); |
|
| 424 | + $color = '#'.str_pad(dechex(mt_rand(0, 0xFFFFFF)), 6, '0', STR_PAD_LEFT); |
|
| 425 | 425 | } |
| 426 | 426 | |
| 427 | 427 | return $color; |
@@ -450,7 +450,7 @@ discard block |
||
| 450 | 450 | rand(0, $this->image->height()), |
| 451 | 451 | rand(0, $this->image->width()), |
| 452 | 452 | rand(0, $this->image->height()), |
| 453 | - function ($draw) { |
|
| 453 | + function($draw) { |
|
| 454 | 454 | /* @var Font $draw */ |
| 455 | 455 | $draw->color($this->fontColor()); |
| 456 | 456 | } |
@@ -468,7 +468,7 @@ discard block |
||
| 468 | 468 | */ |
| 469 | 469 | public function check(string $value): bool |
| 470 | 470 | { |
| 471 | - if (!$this->session->has('captcha')) { |
|
| 471 | + if ( ! $this->session->has('captcha')) { |
|
| 472 | 472 | return false; |
| 473 | 473 | } |
| 474 | 474 | |
@@ -476,16 +476,16 @@ discard block |
||
| 476 | 476 | $sensitive = $this->session->get('captcha.sensitive'); |
| 477 | 477 | $encrypt = $this->session->get('captcha.encrypt'); |
| 478 | 478 | |
| 479 | - if (!Cache::pull($this->get_cache_key($key))) { |
|
| 479 | + if ( ! Cache::pull($this->get_cache_key($key))) { |
|
| 480 | 480 | $this->session->remove('captcha'); |
| 481 | 481 | return false; |
| 482 | 482 | } |
| 483 | 483 | |
| 484 | - if (!$sensitive) { |
|
| 484 | + if ( ! $sensitive) { |
|
| 485 | 485 | $value = $this->str->lower($value); |
| 486 | 486 | } |
| 487 | 487 | |
| 488 | - if($encrypt) $key = Crypt::decrypt($key); |
|
| 488 | + if ($encrypt) $key = Crypt::decrypt($key); |
|
| 489 | 489 | $check = $this->hasher->check($value, $key); |
| 490 | 490 | // if verify pass,remove session |
| 491 | 491 | if ($check) { |
@@ -502,7 +502,7 @@ discard block |
||
| 502 | 502 | * @return string |
| 503 | 503 | */ |
| 504 | 504 | protected function get_cache_key($key) { |
| 505 | - return 'captcha_' . md5($key); |
|
| 505 | + return 'captcha_'.md5($key); |
|
| 506 | 506 | } |
| 507 | 507 | |
| 508 | 508 | /** |
@@ -515,14 +515,14 @@ discard block |
||
| 515 | 515 | */ |
| 516 | 516 | public function check_api($value, $key, $config = 'default'): bool |
| 517 | 517 | { |
| 518 | - if (!Cache::pull($this->get_cache_key($key))) { |
|
| 518 | + if ( ! Cache::pull($this->get_cache_key($key))) { |
|
| 519 | 519 | return false; |
| 520 | 520 | } |
| 521 | 521 | |
| 522 | 522 | $this->configure($config); |
| 523 | 523 | |
| 524 | - if(!$this->sensitive) $value = $this->str->lower($value); |
|
| 525 | - if($this->encrypt) $key = Crypt::decrypt($key); |
|
| 524 | + if ( ! $this->sensitive) $value = $this->str->lower($value); |
|
| 525 | + if ($this->encrypt) $key = Crypt::decrypt($key); |
|
| 526 | 526 | return $this->hasher->check($value, $key); |
| 527 | 527 | } |
| 528 | 528 | |
@@ -534,7 +534,7 @@ discard block |
||
| 534 | 534 | */ |
| 535 | 535 | public function src(string $config = 'default'): string |
| 536 | 536 | { |
| 537 | - return url('captcha/' . $config) . '?' . $this->str->random(8); |
|
| 537 | + return url('captcha/'.$config).'?'.$this->str->random(8); |
|
| 538 | 538 | } |
| 539 | 539 | |
| 540 | 540 | /** |
@@ -554,8 +554,8 @@ discard block |
||
| 554 | 554 | continue; |
| 555 | 555 | } |
| 556 | 556 | |
| 557 | - $attrs_str .= $attr . '="' . $value . '" '; |
|
| 557 | + $attrs_str .= $attr.'="'.$value.'" '; |
|
| 558 | 558 | } |
| 559 | - return new HtmlString('<img src="' . $this->src($config) . '" ' . trim($attrs_str) . '>'); |
|
| 559 | + return new HtmlString('<img src="'.$this->src($config).'" '.trim($attrs_str).'>'); |
|
| 560 | 560 | } |
| 561 | 561 | } |
@@ -1,7 +1,7 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | return [ |
| 4 | - 'disable' => env('CAPTCHA_DISABLE', !str_contains(env('APP_ENV', 'local'), 'prod')), |
|
| 4 | + 'disable' => env('CAPTCHA_DISABLE', ! str_contains(env('APP_ENV', 'local'), 'prod')), |
|
| 5 | 5 | 'characters' => ['2', '3', '4', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'j', 'm', 'n', 'p', 'q', 'r', 't', 'u', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'M', 'N', 'P', 'Q', 'R', 'T', 'U', 'X', 'Y', 'Z'], |
| 6 | 6 | 'default' => [ |
| 7 | 7 | 'length' => 9, |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | { |
| 22 | 22 | // Publish configuration files |
| 23 | 23 | $this->publishes([ |
| 24 | - __DIR__ . '/../config/captcha.php' => config_path('captcha.php') |
|
| 24 | + __DIR__.'/../config/captcha.php' => config_path('captcha.php') |
|
| 25 | 25 | ], 'config'); |
| 26 | 26 | |
| 27 | 27 | // HTTP routing |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | } else { |
| 34 | 34 | /* @var Router $router */ |
| 35 | 35 | $router = $this->app['router']; |
| 36 | - if ((double)$this->app->version() >= 5.2) { |
|
| 36 | + if ((double) $this->app->version() >= 5.2) { |
|
| 37 | 37 | $router->get('captcha/api/{config?}', '\Mews\Captcha\CaptchaController@getCaptchaApi')->middleware('web'); |
| 38 | 38 | $router->get('captcha/{config?}', '\Mews\Captcha\CaptchaController@getCaptcha')->middleware('web'); |
| 39 | 39 | } else { |
@@ -46,12 +46,12 @@ discard block |
||
| 46 | 46 | $validator = $this->app['validator']; |
| 47 | 47 | |
| 48 | 48 | // Validator extensions |
| 49 | - $validator->extend('captcha', function ($attribute, $value, $parameters) { |
|
| 49 | + $validator->extend('captcha', function($attribute, $value, $parameters) { |
|
| 50 | 50 | return config('captcha.disable') || ($value && captcha_check($value)); |
| 51 | 51 | }); |
| 52 | 52 | |
| 53 | 53 | // Validator extensions |
| 54 | - $validator->extend('captcha_api', function ($attribute, $value, $parameters) { |
|
| 54 | + $validator->extend('captcha_api', function($attribute, $value, $parameters) { |
|
| 55 | 55 | return config('captcha.disable') || ($value && captcha_api_check($value, $parameters[0], $parameters[1] ?? 'default')); |
| 56 | 56 | }); |
| 57 | 57 | } |
@@ -65,12 +65,12 @@ discard block |
||
| 65 | 65 | { |
| 66 | 66 | // Merge configs |
| 67 | 67 | $this->mergeConfigFrom( |
| 68 | - __DIR__ . '/../config/captcha.php', |
|
| 68 | + __DIR__.'/../config/captcha.php', |
|
| 69 | 69 | 'captcha' |
| 70 | 70 | ); |
| 71 | 71 | |
| 72 | 72 | // Bind captcha |
| 73 | - $this->app->bind('captcha', function ($app) { |
|
| 73 | + $this->app->bind('captcha', function($app) { |
|
| 74 | 74 | return new Captcha( |
| 75 | 75 | $app['Illuminate\Filesystem\Filesystem'], |
| 76 | 76 | $app['Illuminate\Contracts\Config\Repository'], |