Add all files
This commit is contained in:
64
extensions/Others/Security/Middleware/SecurityCheck.php
Normal file
64
extensions/Others/Security/Middleware/SecurityCheck.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace Paymenter\Extensions\Others\Security\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Paymenter\Extensions\Others\Security\Models\SuspendedAccount;
|
||||
use Paymenter\Extensions\Others\Security\Models\BlockedIP;
|
||||
use Paymenter\Extensions\Others\Security\Models\LoginAttempt;
|
||||
|
||||
class SecurityCheck
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*/
|
||||
public function handle(Request $request, Closure $next): Response
|
||||
{
|
||||
$ipAddress = $request->ip();
|
||||
|
||||
// Check if IP is blocked
|
||||
if (BlockedIP::isIPBlocked($ipAddress)) {
|
||||
$block = BlockedIP::getActiveBlock($ipAddress);
|
||||
|
||||
// Log the blocked attempt
|
||||
LoginAttempt::recordAttempt(
|
||||
$ipAddress,
|
||||
$request->input('email'),
|
||||
false,
|
||||
$request->userAgent(),
|
||||
null,
|
||||
'Blocked IP attempted access'
|
||||
);
|
||||
|
||||
return response()->json([
|
||||
'error' => 'Access denied',
|
||||
'message' => 'Your IP address has been blocked. Reason: ' . $block->reason,
|
||||
'blocked_until' => $block->blocked_until ? $block->blocked_until->toISOString() : null
|
||||
], 403);
|
||||
}
|
||||
|
||||
// Check if user is suspended (only if authenticated)
|
||||
if (Auth::check()) {
|
||||
$userId = Auth::id();
|
||||
|
||||
if (SuspendedAccount::isUserSuspended($userId)) {
|
||||
$suspension = SuspendedAccount::getActiveSuspension($userId);
|
||||
|
||||
// Log out the user
|
||||
Auth::logout();
|
||||
|
||||
return response()->json([
|
||||
'error' => 'Account suspended',
|
||||
'message' => 'Your account has been suspended. Reason: ' . $suspension->reason,
|
||||
'suspended_until' => $suspension->suspended_until ? $suspension->suspended_until->toISOString() : null,
|
||||
'is_permanent' => $suspension->is_permanent
|
||||
], 403);
|
||||
}
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user