Initial commit of the complete City10 virtual city simulation platform. Backend (Laravel 13): - REST API with Sanctum tokens and session-based web authentication - Role-based access control (admin/user) with middleware protection - AI agent CRUD with OpenRouter.ai integration restricted to free models - Store management with 3D coordinates and AI shopkeeper assignment - Versioned legal documents (Terms, Privacy, Cookies) with LGPD audit trail - Math CAPTCHA on public forms and multi-language support (pt_BR, en, es) Frontend: - Responsive Blade templates with Tailwind CSS v4 - Three.js 3D city viewer with SSE chat streaming to AI agents - Admin panel for store and user administration Infrastructure: - MariaDB/MySQL database with comprehensive migrations - Database seeders for demo content and test accounts - PHPUnit test suite and Laravel Pint code styling - Vite build configuration with hot reload
37 lines
865 B
PHP
Executable File
37 lines
865 B
PHP
Executable File
<?php
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
use Closure;
|
|
use Illuminate\Http\Request;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
/**
|
|
* Restricts access to platform administrators.
|
|
*
|
|
* Returns 403 for non-admin users, protecting the admin-only endpoints
|
|
* (user management, agent registry, store registry administration).
|
|
*/
|
|
class EnsureUserIsAdmin
|
|
{
|
|
/**
|
|
* Handle an incoming request.
|
|
*
|
|
* @param Closure(Request): (Response) $next
|
|
*/
|
|
public function handle(Request $request, Closure $next): Response
|
|
{
|
|
$user = $request->user();
|
|
|
|
if ($user === null || ! $user->isAdmin()) {
|
|
if ($request->expectsJson()) {
|
|
return response()->json(['message' => __('auth.forbidden')], 403);
|
|
}
|
|
|
|
abort(403, __('auth.forbidden'));
|
|
}
|
|
|
|
return $next($request);
|
|
}
|
|
}
|