39228168c8
API CI/CD / Validate (composer + pint) (push) Successful in 3m14s
API CI/CD / Test (PHPUnit) (push) Failing after 3m28s
API CI/CD / Build frontend assets (push) Successful in 1m2s
API CI/CD / Security audit (push) Failing after 56s
API CI/CD / Deploy to shared hosting (PHP) (push) Has been skipped
35 lines
965 B
PHP
35 lines
965 B
PHP
<?php
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
use App\Models\User;
|
|
use Closure;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
class EnsureAccountActive
|
|
{
|
|
public function handle(Request $request, Closure $next): Response
|
|
{
|
|
/** @var User|null $user */
|
|
$user = Auth::user() ?: $request->user();
|
|
|
|
if (! $user) {
|
|
return response()->json(['message' => 'Unauthorized.'], 401);
|
|
}
|
|
|
|
$status = strtolower(trim((string) ($user->status ?? '')));
|
|
$isVerified = filter_var($user->is_verified ?? false, FILTER_VALIDATE_BOOLEAN);
|
|
$isSuspended = filter_var($user->is_suspended ?? false, FILTER_VALIDATE_BOOLEAN);
|
|
|
|
if (! $isVerified || $status !== 'active' || $isSuspended) {
|
|
return response()->json([
|
|
'message' => 'Account unavailable.',
|
|
], 403);
|
|
}
|
|
|
|
return $next($request);
|
|
}
|
|
}
|