@@ -232,8 +232,7 @@ discard block |
||
| 232 | 232 | $this->height |
| 233 | 233 | ); |
| 234 | 234 | $this->canvas->insert($this->image); |
| 235 | - } |
|
| 236 | - else |
|
| 235 | + } else |
|
| 237 | 236 | { |
| 238 | 237 | $this->image = $this->canvas; |
| 239 | 238 | } |
@@ -351,8 +350,7 @@ discard block |
||
| 351 | 350 | if ( ! empty($this->fontColors)) |
| 352 | 351 | { |
| 353 | 352 | $color = $this->fontColors[rand(0, count($this->fontColors) - 1)]; |
| 354 | - } |
|
| 355 | - else |
|
| 353 | + } else |
|
| 356 | 354 | { |
| 357 | 355 | $color = [rand(0, 255), rand(0, 255), rand(0, 255)]; |
| 358 | 356 | } |
@@ -18,7 +18,6 @@ |
||
| 18 | 18 | use Illuminate\Config\Repository; |
| 19 | 19 | use Illuminate\Hashing\BcryptHasher as Hasher; |
| 20 | 20 | use Illuminate\Filesystem\Filesystem; |
| 21 | -use Illuminate\Support\Facades\Crypt; |
|
| 22 | 21 | use Illuminate\Support\Str; |
| 23 | 22 | use Intervention\Image\ImageManager; |
| 24 | 23 | use Illuminate\Session\Store as Session; |
@@ -277,9 +277,9 @@ discard block |
||
| 277 | 277 | } |
| 278 | 278 | |
| 279 | 279 | return $api ? [ |
| 280 | - 'sensitive' => $generator['sensitive'], |
|
| 281 | - 'key' => $generator['key'], |
|
| 282 | - 'img' => $this->image->encode('data-url')->encoded |
|
| 280 | + 'sensitive' => $generator['sensitive'], |
|
| 281 | + 'key' => $generator['key'], |
|
| 282 | + 'img' => $this->image->encode('data-url')->encoded |
|
| 283 | 283 | ] : $this->image->response('png', $this->quality); |
| 284 | 284 | } |
| 285 | 285 | |
@@ -317,9 +317,9 @@ discard block |
||
| 317 | 317 | ]); |
| 318 | 318 | |
| 319 | 319 | return [ |
| 320 | - 'value' => $bag, |
|
| 321 | - 'sensitive' => $this->sensitive, |
|
| 322 | - 'key' => $hash |
|
| 320 | + 'value' => $bag, |
|
| 321 | + 'sensitive' => $this->sensitive, |
|
| 322 | + 'key' => $hash |
|
| 323 | 323 | ]; |
| 324 | 324 | } |
| 325 | 325 | |
@@ -419,26 +419,26 @@ discard block |
||
| 419 | 419 | return $this->image; |
| 420 | 420 | } |
| 421 | 421 | |
| 422 | - /** |
|
| 423 | - * Captcha check |
|
| 424 | - * |
|
| 425 | - * @param $value |
|
| 426 | - * @return bool |
|
| 427 | - */ |
|
| 428 | - public function check($value) |
|
| 429 | - { |
|
| 430 | - if ( ! $this->session->has('captcha')) |
|
| 431 | - { |
|
| 432 | - return false; |
|
| 433 | - } |
|
| 422 | + /** |
|
| 423 | + * Captcha check |
|
| 424 | + * |
|
| 425 | + * @param $value |
|
| 426 | + * @return bool |
|
| 427 | + */ |
|
| 428 | + public function check($value) |
|
| 429 | + { |
|
| 430 | + if ( ! $this->session->has('captcha')) |
|
| 431 | + { |
|
| 432 | + return false; |
|
| 433 | + } |
|
| 434 | 434 | |
| 435 | - $key = $this->session->get('captcha.key'); |
|
| 436 | - $sensitive = $this->session->get('captcha.sensitive'); |
|
| 435 | + $key = $this->session->get('captcha.key'); |
|
| 436 | + $sensitive = $this->session->get('captcha.sensitive'); |
|
| 437 | 437 | |
| 438 | - if ( ! $sensitive) |
|
| 439 | - { |
|
| 440 | - $value = $this->str->lower($value); |
|
| 441 | - } |
|
| 438 | + if ( ! $sensitive) |
|
| 439 | + { |
|
| 440 | + $value = $this->str->lower($value); |
|
| 441 | + } |
|
| 442 | 442 | |
| 443 | 443 | |
| 444 | 444 | $res = $this->hasher->check($value, $key); |
@@ -448,18 +448,18 @@ discard block |
||
| 448 | 448 | } |
| 449 | 449 | |
| 450 | 450 | return $res; |
| 451 | - } |
|
| 452 | - |
|
| 453 | - /** |
|
| 454 | - * Captcha check |
|
| 455 | - * |
|
| 456 | - * @param $value |
|
| 457 | - * @return bool |
|
| 458 | - */ |
|
| 459 | - public function check_api($value, $key) |
|
| 460 | - { |
|
| 461 | - return $this->hasher->check($value, $key); |
|
| 462 | - } |
|
| 451 | + } |
|
| 452 | + |
|
| 453 | + /** |
|
| 454 | + * Captcha check |
|
| 455 | + * |
|
| 456 | + * @param $value |
|
| 457 | + * @return bool |
|
| 458 | + */ |
|
| 459 | + public function check_api($value, $key) |
|
| 460 | + { |
|
| 461 | + return $this->hasher->check($value, $key); |
|
| 462 | + } |
|
| 463 | 463 | |
| 464 | 464 | /** |
| 465 | 465 | * Generate captcha image source |
@@ -197,7 +197,7 @@ discard block |
||
| 197 | 197 | $this->session = $session; |
| 198 | 198 | $this->hasher = $hasher; |
| 199 | 199 | $this->str = $str; |
| 200 | - $this->characters = config('captcha.characters','2346789abcdefghjmnpqrtuxyzABCDEFGHJMNPQRTUXYZ'); |
|
| 200 | + $this->characters = config('captcha.characters', '2346789abcdefghjmnpqrtuxyzABCDEFGHJMNPQRTUXYZ'); |
|
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | /** |
@@ -206,9 +206,9 @@ discard block |
||
| 206 | 206 | */ |
| 207 | 207 | protected function configure($config) |
| 208 | 208 | { |
| 209 | - if ($this->config->has('captcha.' . $config)) |
|
| 209 | + if ($this->config->has('captcha.'.$config)) |
|
| 210 | 210 | { |
| 211 | - foreach($this->config->get('captcha.' . $config) as $key => $val) |
|
| 211 | + foreach ($this->config->get('captcha.'.$config) as $key => $val) |
|
| 212 | 212 | { |
| 213 | 213 | $this->{$key} = $val; |
| 214 | 214 | } |
@@ -224,10 +224,10 @@ discard block |
||
| 224 | 224 | */ |
| 225 | 225 | public function create($config = 'default', $api = false) |
| 226 | 226 | { |
| 227 | - $this->backgrounds = $this->files->files(__DIR__ . '/../assets/backgrounds'); |
|
| 228 | - $this->fonts = $this->files->files(__DIR__ . '/../assets/fonts'); |
|
| 227 | + $this->backgrounds = $this->files->files(__DIR__.'/../assets/backgrounds'); |
|
| 228 | + $this->fonts = $this->files->files(__DIR__.'/../assets/fonts'); |
|
| 229 | 229 | |
| 230 | - if (app()->version() >= 5.5){ |
|
| 230 | + if (app()->version() >= 5.5) { |
|
| 231 | 231 | $this->fonts = array_map(function($file) { |
| 232 | 232 | return $file->getPathName(); |
| 233 | 233 | }, $this->fonts); |
@@ -346,9 +346,9 @@ discard block |
||
| 346 | 346 | $marginTop = $this->image->height() / $this->length; |
| 347 | 347 | |
| 348 | 348 | $i = 0; |
| 349 | - foreach(str_split($this->text) as $char) |
|
| 349 | + foreach (str_split($this->text) as $char) |
|
| 350 | 350 | { |
| 351 | - $marginLeft = $this->textLeftPadding + ($i * ($this->image->width() - $this->textLeftPadding) / $this->length); |
|
| 351 | + $marginLeft = $this->textLeftPadding + ($i * ($this->image->width() - $this->textLeftPadding) / $this->length); |
|
| 352 | 352 | |
| 353 | 353 | $this->image->text($char, $marginLeft, $marginTop, function($font) { |
| 354 | 354 | $font->file($this->font()); |
@@ -419,14 +419,14 @@ discard block |
||
| 419 | 419 | */ |
| 420 | 420 | protected function lines() |
| 421 | 421 | { |
| 422 | - for($i = 0; $i <= $this->lines; $i++) |
|
| 422 | + for ($i = 0; $i <= $this->lines; $i++) |
|
| 423 | 423 | { |
| 424 | 424 | $this->image->line( |
| 425 | 425 | rand(0, $this->image->width()) + $i * rand(0, $this->image->height()), |
| 426 | 426 | rand(0, $this->image->height()), |
| 427 | 427 | rand(0, $this->image->width()), |
| 428 | 428 | rand(0, $this->image->height()), |
| 429 | - function ($draw) { |
|
| 429 | + function($draw) { |
|
| 430 | 430 | $draw->color($this->fontColor()); |
| 431 | 431 | } |
| 432 | 432 | ); |
@@ -479,7 +479,7 @@ discard block |
||
| 479 | 479 | */ |
| 480 | 480 | public function src($config = null) |
| 481 | 481 | { |
| 482 | - return url('captcha' . ($config ? '/' . $config : '/default')) . '?' . $this->str->random(8); |
|
| 482 | + return url('captcha'.($config ? '/'.$config : '/default')).'?'.$this->str->random(8); |
|
| 483 | 483 | } |
| 484 | 484 | |
| 485 | 485 | /** |
@@ -493,14 +493,14 @@ discard block |
||
| 493 | 493 | public function img($config = null, $attrs = []) |
| 494 | 494 | { |
| 495 | 495 | $attrs_str = ''; |
| 496 | - foreach($attrs as $attr => $value){ |
|
| 497 | - if ($attr == 'src'){ |
|
| 496 | + foreach ($attrs as $attr => $value) { |
|
| 497 | + if ($attr == 'src') { |
|
| 498 | 498 | //Neglect src attribute |
| 499 | 499 | continue; |
| 500 | 500 | } |
| 501 | 501 | $attrs_str .= $attr.'="'.$value.'" '; |
| 502 | 502 | } |
| 503 | - return '<img src="' . $this->src($config) . '" '. trim($attrs_str).'>'; |
|
| 503 | + return '<img src="'.$this->src($config).'" '.trim($attrs_str).'>'; |
|
| 504 | 504 | } |
| 505 | 505 | |
| 506 | 506 | } |
@@ -36,23 +36,23 @@ |
||
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | if ( ! function_exists('captcha_check')) { |
| 39 | - /** |
|
| 40 | - * @param $value |
|
| 41 | - * @return bool |
|
| 42 | - */ |
|
| 43 | - function captcha_check($value) |
|
| 44 | - { |
|
| 45 | - return app('captcha')->check($value); |
|
| 46 | - } |
|
| 39 | + /** |
|
| 40 | + * @param $value |
|
| 41 | + * @return bool |
|
| 42 | + */ |
|
| 43 | + function captcha_check($value) |
|
| 44 | + { |
|
| 45 | + return app('captcha')->check($value); |
|
| 46 | + } |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | if ( ! function_exists('captcha_api_check')) { |
| 50 | - /** |
|
| 51 | - * @param $value |
|
| 52 | - * @return bool |
|
| 53 | - */ |
|
| 54 | - function captcha_api_check($value, $key) |
|
| 55 | - { |
|
| 56 | - return app('captcha')->check_api($value, $key); |
|
| 57 | - } |
|
| 50 | + /** |
|
| 51 | + * @param $value |
|
| 52 | + * @return bool |
|
| 53 | + */ |
|
| 54 | + function captcha_api_check($value, $key) |
|
| 55 | + { |
|
| 56 | + return app('captcha')->check_api($value, $key); |
|
| 57 | + } |
|
| 58 | 58 | } |
@@ -24,29 +24,29 @@ |
||
| 24 | 24 | |
| 25 | 25 | // HTTP routing |
| 26 | 26 | if (strpos($this->app->version(), 'Lumen') !== false) { |
| 27 | - $this->app->get('captcha[/api/{config}]', 'Mews\Captcha\LumenCaptchaController@getCaptchaApi'); |
|
| 28 | - $this->app->get('captcha[/{config}]', 'Mews\Captcha\LumenCaptchaController@getCaptcha'); |
|
| 27 | + $this->app->get('captcha[/api/{config}]', 'Mews\Captcha\LumenCaptchaController@getCaptchaApi'); |
|
| 28 | + $this->app->get('captcha[/{config}]', 'Mews\Captcha\LumenCaptchaController@getCaptcha'); |
|
| 29 | 29 | } else { |
| 30 | 30 | if ((double) $this->app->version() >= 5.2) { |
| 31 | - $this->app['router']->get('captcha/api/{config?}', '\Mews\Captcha\CaptchaController@getCaptchaApi')->middleware('web'); |
|
| 32 | - $this->app['router']->get('captcha/{config?}', '\Mews\Captcha\CaptchaController@getCaptcha')->middleware('web'); |
|
| 31 | + $this->app['router']->get('captcha/api/{config?}', '\Mews\Captcha\CaptchaController@getCaptchaApi')->middleware('web'); |
|
| 32 | + $this->app['router']->get('captcha/{config?}', '\Mews\Captcha\CaptchaController@getCaptcha')->middleware('web'); |
|
| 33 | 33 | } else { |
| 34 | - $this->app['router']->get('captcha/api/{config?}', '\Mews\Captcha\CaptchaController@getCaptchaApi'); |
|
| 35 | - $this->app['router']->get('captcha/{config?}', '\Mews\Captcha\CaptchaController@getCaptcha'); |
|
| 34 | + $this->app['router']->get('captcha/api/{config?}', '\Mews\Captcha\CaptchaController@getCaptchaApi'); |
|
| 35 | + $this->app['router']->get('captcha/{config?}', '\Mews\Captcha\CaptchaController@getCaptcha'); |
|
| 36 | 36 | } |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | - // Validator extensions |
|
| 40 | - $this->app['validator']->extend('captcha', function($attribute, $value, $parameters) |
|
| 41 | - { |
|
| 42 | - return captcha_check($value); |
|
| 43 | - }); |
|
| 39 | + // Validator extensions |
|
| 40 | + $this->app['validator']->extend('captcha', function($attribute, $value, $parameters) |
|
| 41 | + { |
|
| 42 | + return captcha_check($value); |
|
| 43 | + }); |
|
| 44 | 44 | |
| 45 | - // Validator extensions |
|
| 46 | - $this->app['validator']->extend('captcha_api', function($attribute, $value, $parameters) |
|
| 47 | - { |
|
| 48 | - return captcha_api_check($value, $parameters[0]); |
|
| 49 | - }); |
|
| 45 | + // Validator extensions |
|
| 46 | + $this->app['validator']->extend('captcha_api', function($attribute, $value, $parameters) |
|
| 47 | + { |
|
| 48 | + return captcha_api_check($value, $parameters[0]); |
|
| 49 | + }); |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | /** |
@@ -11,32 +11,32 @@ |
||
| 11 | 11 | class CaptchaController extends Controller |
| 12 | 12 | { |
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * get CAPTCHA |
|
| 16 | - * |
|
| 17 | - * @param \Mews\Captcha\Captcha $captcha |
|
| 18 | - * @param string $config |
|
| 19 | - * @return \Intervention\Image\ImageManager->response |
|
| 20 | - */ |
|
| 21 | - public function getCaptcha(Captcha $captcha, $config = 'default') |
|
| 22 | - { |
|
| 23 | - if (ob_get_contents()) |
|
| 24 | - { |
|
| 25 | - ob_clean(); |
|
| 26 | - } |
|
| 27 | - return $captcha->create($config); |
|
| 28 | - } |
|
| 14 | + /** |
|
| 15 | + * get CAPTCHA |
|
| 16 | + * |
|
| 17 | + * @param \Mews\Captcha\Captcha $captcha |
|
| 18 | + * @param string $config |
|
| 19 | + * @return \Intervention\Image\ImageManager->response |
|
| 20 | + */ |
|
| 21 | + public function getCaptcha(Captcha $captcha, $config = 'default') |
|
| 22 | + { |
|
| 23 | + if (ob_get_contents()) |
|
| 24 | + { |
|
| 25 | + ob_clean(); |
|
| 26 | + } |
|
| 27 | + return $captcha->create($config); |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * get CAPTCHA api |
|
| 32 | - * |
|
| 33 | - * @param \Mews\Captcha\Captcha $captcha |
|
| 34 | - * @param string $config |
|
| 35 | - * @return \Intervention\Image\ImageManager->response |
|
| 36 | - */ |
|
| 37 | - public function getCaptchaApi(Captcha $captcha, $config = 'default') |
|
| 38 | - { |
|
| 39 | - return $captcha->create($config, true); |
|
| 40 | - } |
|
| 30 | + /** |
|
| 31 | + * get CAPTCHA api |
|
| 32 | + * |
|
| 33 | + * @param \Mews\Captcha\Captcha $captcha |
|
| 34 | + * @param string $config |
|
| 35 | + * @return \Intervention\Image\ImageManager->response |
|
| 36 | + */ |
|
| 37 | + public function getCaptchaApi(Captcha $captcha, $config = 'default') |
|
| 38 | + { |
|
| 39 | + return $captcha->create($config, true); |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | 42 | } |