Files
City10/app/Http/Middleware/EnsureUserIsActive.php
marcocosta10000 79ce2a1825 feat(world): add persistent citizen simulation with needs, jobs, and social features
- Adds Character model with survival needs (hunger, thirst, energy) and state machine
- Implements city:tick world ticker for offline progression every minute
- Adds city territory expansion and building construction system
- Introduces job economy, inventory, and transaction audit trail
- Adds social graph (friends, marriage, children) and character chat
- Implements admin approval workflow for new registrations
- Adds hospital admission system for traffic accidents
- Includes comprehensive feature tests and world seeders
2026-10-17 21:46:23 -03:00

56 lines
1.6 KiB
PHP
Executable File

<?php
namespace App\Http\Middleware;
use App\Models\User;
use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
/**
* Ensures the authenticated account is still active and approved.
*
* Blocks banned/disabled accounts and routes pending registrations to the
* approval wait screen, even when a previously issued token or session remains.
*/
class EnsureUserIsActive
{
/**
* Handle an incoming request.
*
* @param Closure(Request): (Response) $next
*/
public function handle(Request $request, Closure $next): Response
{
$user = $request->user();
if ($user !== null && $user->status !== User::STATUS_ACTIVE) {
if ($request->expectsJson()) {
return response()->json([
'message' => $user->status === User::STATUS_PENDING
? __('auth.pending')
: __('auth.disabled'),
], 403);
}
if ($user->status === User::STATUS_PENDING) {
if ($request->routeIs('account.pending', 'terms.accept', 'terms.accept.store', 'logout')) {
return $next($request);
}
return redirect()->route('account.pending');
}
auth()->guard('web')->logout();
$request->session()->invalidate();
$request->session()->regenerateToken();
return redirect()->route('login')->withErrors([
'email' => __('auth.disabled'),
]);
}
return $next($request);
}
}