@@ -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,42 +419,42 @@ 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 | - } |
|
| 434 | - |
|
| 435 | - $key = $this->session->get('captcha.key'); |
|
| 436 | - $sensitive = $this->session->get('captcha.sensitive'); |
|
| 437 | - |
|
| 438 | - if ( ! $sensitive) |
|
| 439 | - { |
|
| 440 | - $value = $this->str->lower($value); |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - $this->session->remove('captcha'); |
|
| 444 | - |
|
| 445 | - return $this->hasher->check($value, $key); |
|
| 446 | - } |
|
| 447 | - |
|
| 448 | - /** |
|
| 449 | - * Captcha check |
|
| 450 | - * |
|
| 451 | - * @param $value |
|
| 452 | - * @return bool |
|
| 453 | - */ |
|
| 454 | - public function check_api($value, $key) |
|
| 455 | - { |
|
| 456 | - return $this->hasher->check($value, $key); |
|
| 457 | - } |
|
| 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 | + |
|
| 435 | + $key = $this->session->get('captcha.key'); |
|
| 436 | + $sensitive = $this->session->get('captcha.sensitive'); |
|
| 437 | + |
|
| 438 | + if ( ! $sensitive) |
|
| 439 | + { |
|
| 440 | + $value = $this->str->lower($value); |
|
| 441 | + } |
|
| 442 | + |
|
| 443 | + $this->session->remove('captcha'); |
|
| 444 | + |
|
| 445 | + return $this->hasher->check($value, $key); |
|
| 446 | + } |
|
| 447 | + |
|
| 448 | + /** |
|
| 449 | + * Captcha check |
|
| 450 | + * |
|
| 451 | + * @param $value |
|
| 452 | + * @return bool |
|
| 453 | + */ |
|
| 454 | + public function check_api($value, $key) |
|
| 455 | + { |
|
| 456 | + return $this->hasher->check($value, $key); |
|
| 457 | + } |
|
| 458 | 458 | |
| 459 | 459 | /** |
| 460 | 460 | * Generate captcha image source |
@@ -192,7 +192,7 @@ discard block |
||
| 192 | 192 | $this->session = $session; |
| 193 | 193 | $this->hasher = $hasher; |
| 194 | 194 | $this->str = $str; |
| 195 | - $this->characters = config('captcha.characters','2346789abcdefghjmnpqrtuxyzABCDEFGHJMNPQRTUXYZ'); |
|
| 195 | + $this->characters = config('captcha.characters', '2346789abcdefghjmnpqrtuxyzABCDEFGHJMNPQRTUXYZ'); |
|
| 196 | 196 | } |
| 197 | 197 | |
| 198 | 198 | /** |
@@ -201,9 +201,9 @@ discard block |
||
| 201 | 201 | */ |
| 202 | 202 | protected function configure($config) |
| 203 | 203 | { |
| 204 | - if ($this->config->has('captcha.' . $config)) |
|
| 204 | + if ($this->config->has('captcha.'.$config)) |
|
| 205 | 205 | { |
| 206 | - foreach($this->config->get('captcha.' . $config) as $key => $val) |
|
| 206 | + foreach ($this->config->get('captcha.'.$config) as $key => $val) |
|
| 207 | 207 | { |
| 208 | 208 | $this->{$key} = $val; |
| 209 | 209 | } |
@@ -219,10 +219,10 @@ discard block |
||
| 219 | 219 | */ |
| 220 | 220 | public function create($config = 'default', $api = false) |
| 221 | 221 | { |
| 222 | - $this->backgrounds = $this->files->files(__DIR__ . '/../assets/backgrounds'); |
|
| 223 | - $this->fonts = $this->files->files(__DIR__ . '/../assets/fonts'); |
|
| 222 | + $this->backgrounds = $this->files->files(__DIR__.'/../assets/backgrounds'); |
|
| 223 | + $this->fonts = $this->files->files(__DIR__.'/../assets/fonts'); |
|
| 224 | 224 | |
| 225 | - if (app()->version() >= 5.5){ |
|
| 225 | + if (app()->version() >= 5.5) { |
|
| 226 | 226 | $this->fonts = array_map(function($file) { |
| 227 | 227 | return $file->getPathName(); |
| 228 | 228 | }, $this->fonts); |
@@ -303,7 +303,7 @@ discard block |
||
| 303 | 303 | $characters = str_split($this->characters); |
| 304 | 304 | |
| 305 | 305 | $bag = ''; |
| 306 | - for($i = 0; $i < $this->length; $i++) |
|
| 306 | + for ($i = 0; $i < $this->length; $i++) |
|
| 307 | 307 | { |
| 308 | 308 | $bag .= $characters[rand(0, count($characters) - 1)]; |
| 309 | 309 | } |
@@ -331,9 +331,9 @@ discard block |
||
| 331 | 331 | $marginTop = $this->image->height() / $this->length; |
| 332 | 332 | |
| 333 | 333 | $i = 0; |
| 334 | - foreach(str_split($this->text) as $char) |
|
| 334 | + foreach (str_split($this->text) as $char) |
|
| 335 | 335 | { |
| 336 | - $marginLeft = $this->textLeftPadding + ($i * ($this->image->width() - $this->textLeftPadding) / $this->length); |
|
| 336 | + $marginLeft = $this->textLeftPadding + ($i * ($this->image->width() - $this->textLeftPadding) / $this->length); |
|
| 337 | 337 | |
| 338 | 338 | $this->image->text($char, $marginLeft, $marginTop, function($font) { |
| 339 | 339 | $font->file($this->font()); |
@@ -404,14 +404,14 @@ discard block |
||
| 404 | 404 | */ |
| 405 | 405 | protected function lines() |
| 406 | 406 | { |
| 407 | - for($i = 0; $i <= $this->lines; $i++) |
|
| 407 | + for ($i = 0; $i <= $this->lines; $i++) |
|
| 408 | 408 | { |
| 409 | 409 | $this->image->line( |
| 410 | 410 | rand(0, $this->image->width()) + $i * rand(0, $this->image->height()), |
| 411 | 411 | rand(0, $this->image->height()), |
| 412 | 412 | rand(0, $this->image->width()), |
| 413 | 413 | rand(0, $this->image->height()), |
| 414 | - function ($draw) { |
|
| 414 | + function($draw) { |
|
| 415 | 415 | $draw->color($this->fontColor()); |
| 416 | 416 | } |
| 417 | 417 | ); |
@@ -464,7 +464,7 @@ discard block |
||
| 464 | 464 | */ |
| 465 | 465 | public function src($config = null) |
| 466 | 466 | { |
| 467 | - return url('captcha' . ($config ? '/' . $config : '/default')) . '?' . $this->str->random(8); |
|
| 467 | + return url('captcha'.($config ? '/'.$config : '/default')).'?'.$this->str->random(8); |
|
| 468 | 468 | } |
| 469 | 469 | |
| 470 | 470 | /** |
@@ -478,14 +478,14 @@ discard block |
||
| 478 | 478 | public function img($config = null, $attrs = []) |
| 479 | 479 | { |
| 480 | 480 | $attrs_str = ''; |
| 481 | - foreach($attrs as $attr => $value){ |
|
| 482 | - if ($attr == 'src'){ |
|
| 481 | + foreach ($attrs as $attr => $value) { |
|
| 482 | + if ($attr == 'src') { |
|
| 483 | 483 | //Neglect src attribute |
| 484 | 484 | continue; |
| 485 | 485 | } |
| 486 | 486 | $attrs_str .= $attr.'="'.$value.'" '; |
| 487 | 487 | } |
| 488 | - return '<img src="' . $this->src($config) . '" '. trim($attrs_str).'>'; |
|
| 488 | + return '<img src="'.$this->src($config).'" '.trim($attrs_str).'>'; |
|
| 489 | 489 | } |
| 490 | 490 | |
| 491 | 491 | } |