From cd65b977d572731671b05b45114691044b837947 Mon Sep 17 00:00:00 2001 From: AMoktar Date: Sun, 24 Sep 2023 16:20:01 +0300 Subject: [PATCH] adding BotBlockedEvent --- src/Events/BotBlockedEvent.php | 35 ++++++++++++++++++++++++++++++++++ src/Middleware/BlockBots.php | 5 ++++- 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 src/Events/BotBlockedEvent.php diff --git a/src/Events/BotBlockedEvent.php b/src/Events/BotBlockedEvent.php new file mode 100644 index 0000000..2a9a7f1 --- /dev/null +++ b/src/Events/BotBlockedEvent.php @@ -0,0 +1,35 @@ +ip = $ip; + $this->number_of_hits = $number_of_hits; + $this->block_date = $block_date; + } +} diff --git a/src/Middleware/BlockBots.php b/src/Middleware/BlockBots.php index 2191c3f..2fe0715 100644 --- a/src/Middleware/BlockBots.php +++ b/src/Middleware/BlockBots.php @@ -10,7 +10,7 @@ use Potelo\LaravelBlockBots\Events\UserBlockedEvent; use Potelo\LaravelBlockBots\Jobs\ProcessLogWithIpInfo; use Potelo\LaravelBlockBots\Abstracts\AbstractBlockBots; - +use Potelo\LaravelBlockBots\Events\BotBlockedEvent; class BlockBots extends AbstractBlockBots { @@ -55,6 +55,9 @@ protected function notAllowed() event(new UserBlockedEvent(Auth::user(), $this->hits, Carbon::now())); } + if (Auth::guest() && $this->isTheFirstOverflow()) { + event(new BotBlockedEvent($this->client->ip, $this->hits, Carbon::now())); + } if ($this->request->expectsJson()) { return response()->json($this->options->json_response, 429);