misc_pterodactyl-panel/app/Http/Middleware/Api/Application/AuthenticateApplicationUser.php
Matthew Penner cbcf62086f
Upgrade to Laravel 9 (#4413)
Co-authored-by: DaneEveritt <dane@daneeveritt.com>
2022-10-14 10:59:20 -06:00

25 lines
742 B
PHP

<?php
namespace Pterodactyl\Http\Middleware\Api\Application;
use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
class AuthenticateApplicationUser
{
/**
* Authenticate that the currently authenticated user is an administrator
* and should be allowed to proceed through the application API.
*/
public function handle(Request $request, Closure $next): mixed
{
/** @var \Pterodactyl\Models\User|null $user */
$user = $request->user();
if (!$user || !$user->root_admin) {
throw new AccessDeniedHttpException('This account does not have permission to access the API.');
}
return $next($request);
}
}