Add all files
This commit is contained in:
64
extensions/Others/Security/Traits/HasSecurityChecks.php
Normal file
64
extensions/Others/Security/Traits/HasSecurityChecks.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace Paymenter\Extensions\Others\Security\Traits;
|
||||
|
||||
use Paymenter\Extensions\Others\Security\Models\BlockedIP;
|
||||
use Paymenter\Extensions\Others\Security\Models\SuspendedAccount;
|
||||
use Paymenter\Extensions\Others\Security\Services\VPNDetectionService;
|
||||
|
||||
trait HasSecurityChecks
|
||||
{
|
||||
protected function checkSecurityRestrictions(string $email, string $ipAddress = null): ?string
|
||||
{
|
||||
$ipAddress = $ipAddress ?? request()->ip();
|
||||
|
||||
if (BlockedIP::isIPBlocked($ipAddress)) {
|
||||
$block = BlockedIP::getActiveBlock($ipAddress);
|
||||
return 'Your IP address has been blocked. Reason: ' . $block->reason;
|
||||
}
|
||||
|
||||
if (VPNDetectionService::isVPNBlocked($ipAddress)) {
|
||||
VPNDetectionService::checkAndBlockVPN($ipAddress, $email);
|
||||
return 'Access denied. VPN/Proxy connections are not allowed.';
|
||||
}
|
||||
|
||||
$user = \App\Models\User::where('email', $email)->first();
|
||||
if ($user && SuspendedAccount::isUserSuspended($user->id)) {
|
||||
$suspension = SuspendedAccount::getActiveSuspension($user->id);
|
||||
return 'Your account has been suspended. Reason: ' . $suspension->reason;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected function attemptSecureLogin(array $credentials, bool $remember = false): bool
|
||||
{
|
||||
$email = $credentials['email'] ?? '';
|
||||
$ipAddress = request()->ip();
|
||||
|
||||
$securityError = $this->checkSecurityRestrictions($email, $ipAddress);
|
||||
if ($securityError) {
|
||||
$this->addError('email', $securityError);
|
||||
return false;
|
||||
}
|
||||
|
||||
return \Illuminate\Support\Facades\Auth::attempt($credentials, $remember);
|
||||
}
|
||||
|
||||
protected function checkRegistrationSecurity(string $email, string $ipAddress = null): ?string
|
||||
{
|
||||
$ipAddress = $ipAddress ?? request()->ip();
|
||||
|
||||
if (BlockedIP::isIPBlocked($ipAddress)) {
|
||||
$block = BlockedIP::getActiveBlock($ipAddress);
|
||||
return 'Your IP address has been blocked. Reason: ' . $block->reason;
|
||||
}
|
||||
|
||||
if (VPNDetectionService::isVPNBlocked($ipAddress)) {
|
||||
VPNDetectionService::checkAndBlockVPN($ipAddress, $email, 'registration');
|
||||
return 'Access denied. VPN/Proxy connections are not allowed for registration.';
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user