Add all files
This commit is contained in:
69
extensions/Others/Security/Models/LoginAttempt.php
Normal file
69
extensions/Others/Security/Models/LoginAttempt.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace Paymenter\Extensions\Others\Security\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class LoginAttempt extends Model
|
||||
{
|
||||
protected $table = 'ext_security_login_attempts';
|
||||
|
||||
protected $fillable = [
|
||||
'ip_address',
|
||||
'email',
|
||||
'successful',
|
||||
'user_agent',
|
||||
'country',
|
||||
'notes',
|
||||
'attempted_at',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'successful' => 'boolean',
|
||||
'attempted_at' => 'datetime',
|
||||
];
|
||||
|
||||
/**
|
||||
* Record a login attempt
|
||||
*/
|
||||
public static function recordAttempt(
|
||||
string $ipAddress,
|
||||
?string $email = null,
|
||||
bool $successful = false,
|
||||
?string $userAgent = null,
|
||||
?string $country = null,
|
||||
?string $notes = null
|
||||
): self {
|
||||
return static::create([
|
||||
'ip_address' => $ipAddress,
|
||||
'email' => $email,
|
||||
'successful' => $successful,
|
||||
'user_agent' => $userAgent,
|
||||
'country' => $country,
|
||||
'notes' => $notes,
|
||||
'attempted_at' => now(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get recent failed attempts for an IP
|
||||
*/
|
||||
public static function getRecentFailedAttempts(string $ipAddress, int $minutes = 60): int
|
||||
{
|
||||
return static::where('ip_address', $ipAddress)
|
||||
->where('successful', false)
|
||||
->where('attempted_at', '>', now()->subMinutes($minutes))
|
||||
->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get recent failed attempts for an email
|
||||
*/
|
||||
public static function getRecentFailedAttemptsForEmail(string $email, int $minutes = 60): int
|
||||
{
|
||||
return static::where('email', $email)
|
||||
->where('successful', false)
|
||||
->where('attempted_at', '>', now()->subMinutes($minutes))
|
||||
->count();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user