Add ForbiddenIE middleware

This commit is contained in:
Pig Fang 2019-04-22 21:09:36 +08:00
parent e6fc975796
commit f8bba6b7b7
5 changed files with 28 additions and 0 deletions

View File

@ -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' => [],

View 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);
}
}

View File

@ -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

View File

@ -5,6 +5,7 @@ http:
msg-503: 网站维护中
method-not-allowed: 不允许的 HTTP 请求方法
csrf-token-mismatch: Token 不正确,请尝试刷新页面
ie: 本站不支持 Internet Explorer请使用其它现代浏览器如 Firefox 或 Chrome
general:
title: 出现错误

View File

@ -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'));
}
}