Add ForbiddenIE middleware
This commit is contained in:
parent
e6fc975796
commit
f8bba6b7b7
|
|
@ -31,6 +31,7 @@ class Kernel extends HttpKernel
|
|||
\Illuminate\Session\Middleware\StartSession::class,
|
||||
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
|
||||
\App\Http\Middleware\DetectLanguagePrefer::class,
|
||||
\App\Http\Middleware\ForbiddenIE::class,
|
||||
],
|
||||
|
||||
'static' => [],
|
||||
|
|
|
|||
19
app/Http/Middleware/ForbiddenIE.php
Normal file
19
app/Http/Middleware/ForbiddenIE.php
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Support\Str;
|
||||
use App\Exceptions\PrettyPageException;
|
||||
|
||||
class ForbiddenIE
|
||||
{
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
if (Str::contains($request->userAgent(), ['Trident', 'MSIE'])) {
|
||||
throw new PrettyPageException(trans('errors.http.ie'));
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
|
|
@ -5,6 +5,7 @@ http:
|
|||
msg-503: The application is now in maintenance mode.
|
||||
method-not-allowed: Method not allowed.
|
||||
csrf-token-mismatch: Token does not match, try reloading the page.
|
||||
ie: We don't support Internet Explorer. Please switch to other modern browsers, such as Firefox or Chrome.
|
||||
|
||||
general:
|
||||
title: Error occurred
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ http:
|
|||
msg-503: 网站维护中
|
||||
method-not-allowed: 不允许的 HTTP 请求方法
|
||||
csrf-token-mismatch: Token 不正确,请尝试刷新页面
|
||||
ie: 本站不支持 Internet Explorer,请使用其它现代浏览器(如 Firefox 或 Chrome)。
|
||||
|
||||
general:
|
||||
title: 出现错误
|
||||
|
|
|
|||
|
|
@ -214,4 +214,10 @@ class MiddlewareTest extends TestCase
|
|||
$this->get('/user')->assertViewIs('user.index');
|
||||
$this->get('/user/player/bind')->assertRedirect('/user');
|
||||
}
|
||||
|
||||
public function testForbiddenIE()
|
||||
{
|
||||
$this->get('/', ['user-agent' => 'MSIE'])->assertSee(trans('errors.http.ie'));
|
||||
$this->get('/', ['user-agent' => 'Trident'])->assertSee(trans('errors.http.ie'));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user