65 lines
2.3 KiB
PHP
65 lines
2.3 KiB
PHP
<?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;
|
|
}
|
|
}
|