mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-14 12:30:49 +08:00
add platform
This commit is contained in:
@@ -42,6 +42,7 @@ class Kernel extends HttpKernel
|
||||
'api' => [
|
||||
'throttle:api',
|
||||
\Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||
\App\Http\Middleware\Platform::class,
|
||||
],
|
||||
];
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ class Permission
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = $request->user();
|
||||
if (!$user || !$user->canAccessAdmin()) {
|
||||
if (!$user || (IS_PLATFORM_ADMIN && !$user->canAccessAdmin())) {
|
||||
do_log("denied!");
|
||||
throw new UnauthorizedException('Unauthorized!');
|
||||
}
|
||||
|
||||
27
app/Http/Middleware/Platform.php
Normal file
27
app/Http/Middleware/Platform.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class Platform
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle(Request $request, Closure $next)
|
||||
{
|
||||
if (empty(CURRENT_PLATFORM)) {
|
||||
throw new \InvalidArgumentException("Require platform header.");
|
||||
}
|
||||
if (!in_array(CURRENT_PLATFORM, PLATFORMS)) {
|
||||
throw new \InvalidArgumentException("Invalid platform: " . CURRENT_PLATFORM);
|
||||
}
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user