increase browser requirement

This commit is contained in:
Pig Fang 2020-03-18 10:48:13 +08:00
parent 60c628dd11
commit 9f8f1e786a
5 changed files with 31 additions and 22 deletions

View File

@ -32,7 +32,7 @@ class Kernel extends HttpKernel
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\Illuminate\Foundation\Http\Middleware\VerifyCsrfToken::class,
\App\Http\Middleware\ForbiddenIE::class,
\App\Http\Middleware\EnforceEverGreen::class,
\App\Http\Middleware\RedirectToSetup::class,
],

View File

@ -0,0 +1,25 @@
<?php
namespace App\Http\Middleware;
use App\Exceptions\PrettyPageException;
use Closure;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
class EnforceEverGreen
{
public function handle($request, Closure $next)
{
$userAgent = $request->userAgent();
preg_match('/Chrome\/(\d+)/', $userAgent, $matches);
$isOldChrome = Arr::has($matches, 1) && $matches[1] < 55;
if ($isOldChrome || Str::contains($userAgent, ['Trident', 'MSIE'])) {
throw new PrettyPageException(trans('errors.http.ie'));
}
return $next($request);
}
}

View File

@ -1,19 +0,0 @@
<?php
namespace App\Http\Middleware;
use App\Exceptions\PrettyPageException;
use Closure;
use Illuminate\Support\Str;
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,7 +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.
ie: Your browser isn't supported. Please switch to other modern browsers, such as Firefox or Chrome.
general:
title: Error occurred

View File

@ -2,7 +2,7 @@
namespace Tests;
class ForbiddenIETest extends TestCase
class EnforceEverGreenTest extends TestCase
{
public function testHandle()
{
@ -10,5 +10,8 @@ class ForbiddenIETest extends TestCase
->assertSee(trans('errors.http.ie'));
$this->get('/', ['user-agent' => 'Trident'])
->assertSee(trans('errors.http.ie'));
$this->get('/', [
'user-agent' => 'AppleWebKit/537.36 Chrome/54.0.2403.157 Safari/537.36',
])->assertSee(trans('errors.http.ie'));
}
}