diff options
author | floppydiskette <git@diskfloppy.me> | 2024-08-08 22:22:38 +0100 |
---|---|---|
committer | floppydiskette <git@diskfloppy.me> | 2024-08-08 22:22:38 +0100 |
commit | 04fc009874db2d539ad881b649f7ebb512f05312 (patch) | |
tree | 9934681b96c15ceffbc9ce8d682621ff875f1b4f /app/Http/Middleware/RateLimiter.php | |
parent | fc5cd70e729f639aaf1c6ff6a4bf3d5d52664de9 (diff) |
Init rails apprails
Diffstat (limited to 'app/Http/Middleware/RateLimiter.php')
-rw-r--r-- | app/Http/Middleware/RateLimiter.php | 35 |
1 files changed, 0 insertions, 35 deletions
diff --git a/app/Http/Middleware/RateLimiter.php b/app/Http/Middleware/RateLimiter.php deleted file mode 100644 index 821868f..0000000 --- a/app/Http/Middleware/RateLimiter.php +++ /dev/null @@ -1,35 +0,0 @@ -<?php - -namespace App\Http\Middleware; - -use Closure; -use Illuminate\Http\Request; -use Illuminate\Support\Facades\Cache; -use Symfony\Component\HttpFoundation\Response; - -class RateLimiter -{ - /** - * Handle an incoming request. - * - * @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next - */ - public function handle(Request $request, Closure $next): Response - { - if (auth()->check()) { - return $next($request); - } - $ipAddress = $request->ip(); - $cacheKey = 'rate_limit_'.$ipAddress; - - if (Cache::has($cacheKey)) { - // If the cache key exists, the IP has submitted an entry within the last hour. - return response()->view('errors.guestbook-ratelimit', [], 429); - } - - // Add the IP address to the cache and set the expiration time to one hour. - Cache::put($cacheKey, true, 3600); - - return $next($request); - } -} |