minor syntax tweaks
This commit is contained in:
parent
0f89376fa8
commit
c7577ea492
15
README.md
15
README.md
@ -206,21 +206,6 @@ rateLimit(int $maxAttempts = 60, int $decayMinutes = 1): callable
|
||||
verifyCsrf(): callable
|
||||
```
|
||||
|
||||
## Features
|
||||
|
||||
- **High Performance**: Tree-based router with O(1) lookup complexity
|
||||
- **Minimal Overhead**: Lightweight design with essential features only
|
||||
- **Method Chaining**: Fluent API for response building
|
||||
- **Middleware Support**: Pre/post request processing
|
||||
- **Route Groups**: Organize routes with shared prefixes and middleware
|
||||
- **Input Validation**: Comprehensive validation with built-in rules
|
||||
- **Authentication**: Session-based auth with remember tokens
|
||||
- **Error Handling**: Custom error pages with debug support
|
||||
- **CSRF Protection**: Built-in CSRF token generation and validation
|
||||
- **Flash Messages**: One-time notifications between requests
|
||||
- **Rate Limiting**: Configurable rate limiting per user/IP
|
||||
- **Content Negotiation**: Automatic JSON/HTML response selection
|
||||
|
||||
## Documentation
|
||||
|
||||
- **[EXAMPLES.md](EXAMPLES.md)** - Comprehensive examples and usage patterns
|
||||
|
||||
@ -12,9 +12,9 @@ class Auth
|
||||
private ?User $user = null;
|
||||
private array $config;
|
||||
|
||||
const SESSION_KEY = 'auth_user_data';
|
||||
const REMEMBER_COOKIE = 'remember_token';
|
||||
const REMEMBER_DURATION = 2592000; // 30 days in seconds
|
||||
public const string SESSION_KEY = 'auth_user_data';
|
||||
public const string REMEMBER_COOKIE = 'remember_token';
|
||||
public const int REMEMBER_DURATION = 2592000; // 30 days in seconds
|
||||
|
||||
public function __construct(Session $session, ?Cookies $cookie = null, array $config = [])
|
||||
{
|
||||
|
||||
@ -111,20 +111,16 @@ class AuthMiddleware
|
||||
public function rateLimit(int $maxAttempts = 60, int $decayMinutes = 1): callable
|
||||
{
|
||||
return function(Context $context, callable $next) use ($maxAttempts, $decayMinutes) {
|
||||
if ($this->auth->guest()) {
|
||||
$identifier = $context->request->ip();
|
||||
} else {
|
||||
$identifier = 'user:' . $this->auth->id();
|
||||
}
|
||||
$identifier = $this->auth->guest() ? $context->request->ip() : 'user:' . $this->auth->id();
|
||||
|
||||
$key = 'rate_limit:' . $identifier . ':' . $context->request->path;
|
||||
$attempts = $context->session->get($key, 0);
|
||||
$resetTime = $context->session->get($key . ':reset', 0);
|
||||
$resetTime = $context->session->get("$key:reset", 0);
|
||||
|
||||
// Reset counter if decay time has passed
|
||||
if (time() > $resetTime) {
|
||||
$attempts = 0;
|
||||
$context->session->set($key . ':reset', time() + ($decayMinutes * 60));
|
||||
$context->session->set("$key:reset", time() + $decayMinutes * 60);
|
||||
}
|
||||
|
||||
if ($attempts >= $maxAttempts) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user