27 lines
689 B
PHP
27 lines
689 B
PHP
<?php
|
|
|
|
namespace App\Domains\Captcha\Http\Middleware;
|
|
|
|
use Closure;
|
|
use Illuminate\Http\Request;
|
|
use App\Exceptions\AuthException;
|
|
use App\Exceptions\NotAllowedException;
|
|
use App\Domains\Captcha\Services\CaptchaService;
|
|
use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;
|
|
|
|
class CaptchaAuthenticate
|
|
{
|
|
public function handle(Request $request, Closure $next)
|
|
{
|
|
$captchaKey = $request->get('captcha_key', '');
|
|
|
|
$captcha = $request->get('captcha', '');
|
|
|
|
if (!app(CaptchaService::class)->check($captcha, $captchaKey)) {
|
|
throw new NotAllowedException('验证码不正确');
|
|
}
|
|
|
|
return $next($request);
|
|
}
|
|
}
|