feat: add City10 platform with Laravel 13, AI agents, 3D viewer, and LGPD compliance
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
This commit is contained in:
Executable
+60
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
/**
|
||||
* Validates creation and update payloads for AI agents.
|
||||
*
|
||||
* Enforces the allow-list of free OpenRouter models defined in
|
||||
* config/ai.php so that no paid model can ever be activated.
|
||||
*/
|
||||
class AiAgentRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
// Authorization is enforced by admin role middleware in routes.
|
||||
return $this->user()?->isAdmin() ?? false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
$allowed = config('ai.allowed_models', []);
|
||||
|
||||
return [
|
||||
'name' => ['required', 'string', 'max:120'],
|
||||
'type' => ['required', 'string', 'max:40'],
|
||||
'model' => ['required', 'string', Rule::in($allowed)],
|
||||
'system_prompt' => ['nullable', 'string', 'max:8000'],
|
||||
'current_goal' => ['nullable', 'string', 'max:2000'],
|
||||
'status' => ['nullable', Rule::in(['active', 'paused', 'thinking', 'error'])],
|
||||
'pos_x' => ['nullable', 'numeric', 'between:-100000,100000'],
|
||||
'pos_y' => ['nullable', 'numeric', 'between:-100000,100000'],
|
||||
'pos_z' => ['nullable', 'numeric', 'between:-100000,100000'],
|
||||
'rotation_y' => ['nullable', 'numeric', 'between:-6.2832,6.2832'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get custom messages for validation errors.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public function messages(): array
|
||||
{
|
||||
return [
|
||||
'model.in' => __('validation.model_not_allowed'),
|
||||
];
|
||||
}
|
||||
}
|
||||
Executable
+48
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
/**
|
||||
* Validates the submission of legal document acceptances (LGPD consent).
|
||||
*/
|
||||
class ConsentRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return $this->user() !== null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'accepted_terms' => ['accepted'],
|
||||
'accepted_privacy' => ['accepted'],
|
||||
'accepted_cookies' => ['accepted'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get custom messages for validation errors.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public function messages(): array
|
||||
{
|
||||
return [
|
||||
'accepted_terms.accepted' => __('legal.must_accept_terms'),
|
||||
'accepted_privacy.accepted' => __('legal.must_accept_privacy'),
|
||||
'accepted_cookies.accepted' => __('legal.must_accept_cookies'),
|
||||
];
|
||||
}
|
||||
}
|
||||
Executable
+66
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use App\Http\Requests\Traits\ValidatesMathCaptcha;
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Validator;
|
||||
|
||||
/**
|
||||
* Validates credentials submitted through the login form.
|
||||
*/
|
||||
class LoginRequest extends FormRequest
|
||||
{
|
||||
use ValidatesMathCaptcha;
|
||||
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'email' => ['required', 'email', 'max:255'],
|
||||
'password' => ['required', 'string'],
|
||||
'remember' => ['nullable', 'boolean'],
|
||||
'captcha' => ['required', 'integer'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get custom messages for validation errors.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public function messages(): array
|
||||
{
|
||||
return [
|
||||
'captcha.required' => __('validation.captcha_required'),
|
||||
'captcha.integer' => __('validation.captcha_required'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure the validator instance.
|
||||
*
|
||||
* @param Validator $validator
|
||||
*/
|
||||
public function withValidator($validator): void
|
||||
{
|
||||
$validator->after(function ($validator): void {
|
||||
if (! $this->validateMathCaptcha()) {
|
||||
$validator->errors()->add('captcha', __('validation.captcha_failed'));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Executable
+56
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use App\Http\Requests\Traits\ValidatesMathCaptcha;
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Illuminate\Validation\Rules\Password;
|
||||
use Illuminate\Validation\Validator;
|
||||
|
||||
/**
|
||||
* Validates new account registrations submitted through the public form.
|
||||
*/
|
||||
class RegisterRequest extends FormRequest
|
||||
{
|
||||
use ValidatesMathCaptcha;
|
||||
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'name' => ['required', 'string', 'max:120'],
|
||||
'email' => ['required', 'string', 'email', 'max:255', Rule::unique('users', 'email')],
|
||||
'password' => ['required', 'confirmed', Password::min(8)],
|
||||
'locale' => ['nullable', Rule::in(['pt_BR', 'en', 'es'])],
|
||||
'captcha' => ['required', 'integer'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure the validator instance.
|
||||
*
|
||||
* @param Validator $validator
|
||||
*/
|
||||
public function withValidator($validator): void
|
||||
{
|
||||
$validator->after(function ($validator): void {
|
||||
if (! $this->validateMathCaptcha()) {
|
||||
$validator->errors()->add('captcha', __('validation.captcha_failed'));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Executable
+47
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
/**
|
||||
* Validates creation and update payloads for city stores.
|
||||
*/
|
||||
class StoreRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
// Authorization is enforced by role middleware in the route file.
|
||||
return $this->user() !== null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
$storeId = $this->route('store')?->id ?? $this->route('store');
|
||||
|
||||
return [
|
||||
'name' => ['required', 'string', 'max:160'],
|
||||
'description' => ['nullable', 'string', 'max:2000'],
|
||||
'type' => ['required', 'string', 'max:60'],
|
||||
'owner_id' => ['nullable', 'integer', Rule::exists('users', 'id')],
|
||||
'agent_id' => ['nullable', 'integer', Rule::exists('ai_agents', 'id')],
|
||||
'pos_x' => ['required', 'numeric', 'between:-100000,100000'],
|
||||
'pos_y' => ['required', 'numeric', 'between:-100000,100000'],
|
||||
'pos_z' => ['required', 'numeric', 'between:-100000,100000'],
|
||||
'width' => ['nullable', 'numeric', 'min:0.1', 'max:1000'],
|
||||
'height' => ['nullable', 'numeric', 'min:0.1', 'max:1000'],
|
||||
'depth' => ['nullable', 'numeric', 'min:0.1', 'max:1000'],
|
||||
'is_open' => ['nullable', 'boolean'],
|
||||
];
|
||||
}
|
||||
}
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Traits;
|
||||
|
||||
use Illuminate\Support\Facades\Session;
|
||||
|
||||
/**
|
||||
* Simple arithmetic CAPTCHA implemented with pure Laravel primitives.
|
||||
*
|
||||
* Generates a sum of two random integers, stores the expected result in
|
||||
* the session and validates the user answer. It introduces no external
|
||||
* dependency and is therefore safe from third-party licensing concerns.
|
||||
*/
|
||||
trait ValidatesMathCaptcha
|
||||
{
|
||||
/**
|
||||
* Generate a new math challenge and persist it in the session.
|
||||
*
|
||||
* @return array{a: int, b: int, question: string}
|
||||
*/
|
||||
protected static function generateMathCaptcha(): array
|
||||
{
|
||||
$a = random_int(1, 9);
|
||||
$b = random_int(1, 9);
|
||||
|
||||
Session::put('captcha_result', $a + $b);
|
||||
// Sliding expiry: challenge is valid for 10 minutes.
|
||||
Session::put('captcha_expires_at', now()->addMinutes(10)->getTimestamp());
|
||||
|
||||
return [
|
||||
'a' => $a,
|
||||
'b' => $b,
|
||||
'question' => sprintf('%d + %d = ?', $a, $b),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate the submitted CAPTCHA answer against the session value.
|
||||
*/
|
||||
protected function validateMathCaptcha(): bool
|
||||
{
|
||||
$expected = Session::get('captcha_result');
|
||||
$expiresAt = Session::get('captcha_expires_at');
|
||||
|
||||
// Invalidate the challenge after it is consumed.
|
||||
Session::forget(['captcha_result', 'captcha_expires_at']);
|
||||
|
||||
if ($expected === null || $expiresAt === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (now()->getTimestamp() > (int) $expiresAt) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (int) $this->input('captcha') === (int) $expected;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user