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
55 lines
1.4 KiB
PHP
Executable File
55 lines
1.4 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
use App\Models\LegalDocument;
|
|
use Closure;
|
|
use Illuminate\Http\Request;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
/**
|
|
* Blocks access until the user accepted all current legal documents.
|
|
*
|
|
* Implements the LGPD requirement that the Terms of Use, Privacy Policy
|
|
* and Cookie Policy must be accepted on first access before the main
|
|
* platform features can be used.
|
|
*/
|
|
class EnsureTermsAccepted
|
|
{
|
|
/**
|
|
* Handle an incoming request.
|
|
*
|
|
* @param Closure(Request): (Response) $next
|
|
*/
|
|
public function handle(Request $request, Closure $next): Response
|
|
{
|
|
$user = $request->user();
|
|
|
|
if ($user === null) {
|
|
return $next($request);
|
|
}
|
|
|
|
$currentIds = LegalDocument::query()->where('is_current', true)->pluck('id');
|
|
|
|
if ($currentIds->isEmpty()) {
|
|
return $next($request);
|
|
}
|
|
|
|
$acceptedIds = $user->consents()->pluck('legal_document_id');
|
|
$pending = $currentIds->diff($acceptedIds);
|
|
|
|
if ($pending->isNotEmpty()) {
|
|
if ($request->expectsJson()) {
|
|
return response()->json([
|
|
'message' => __('legal.accept_required'),
|
|
'pending' => $pending->values(),
|
|
], 428);
|
|
}
|
|
|
|
return redirect()->route('terms.accept');
|
|
}
|
|
|
|
return $next($request);
|
|
}
|
|
}
|