Skip to content

Commit cd65b97

Browse files
committed
adding BotBlockedEvent
1 parent 99510fb commit cd65b97

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

src/Events/BotBlockedEvent.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace Potelo\LaravelBlockBots\Events;
4+
5+
use Carbon\Carbon;
6+
use Illuminate\Queue\SerializesModels;
7+
8+
class BotBlockedEvent
9+
{
10+
use SerializesModels;
11+
12+
public $ip;
13+
14+
/** @var integer */
15+
public $number_of_hits;
16+
17+
/** @var Carbon */
18+
public $block_date;
19+
20+
/**
21+
* Create a new event instance.
22+
*
23+
* @param $ip
24+
* @param integer $number_of_hits
25+
* @param Carbon $block_date
26+
*
27+
* @return void
28+
*/
29+
public function __construct($ip, $number_of_hits, $block_date)
30+
{
31+
$this->ip = $ip;
32+
$this->number_of_hits = $number_of_hits;
33+
$this->block_date = $block_date;
34+
}
35+
}

src/Middleware/BlockBots.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use Potelo\LaravelBlockBots\Events\UserBlockedEvent;
1111
use Potelo\LaravelBlockBots\Jobs\ProcessLogWithIpInfo;
1212
use Potelo\LaravelBlockBots\Abstracts\AbstractBlockBots;
13-
13+
use Potelo\LaravelBlockBots\Events\BotBlockedEvent;
1414

1515
class BlockBots extends AbstractBlockBots
1616
{
@@ -55,6 +55,9 @@ protected function notAllowed()
5555
event(new UserBlockedEvent(Auth::user(), $this->hits, Carbon::now()));
5656
}
5757

58+
if (Auth::guest() && $this->isTheFirstOverflow()) {
59+
event(new BotBlockedEvent($this->client->ip, $this->hits, Carbon::now()));
60+
}
5861

5962
if ($this->request->expectsJson()) {
6063
return response()->json($this->options->json_response, 429);

0 commit comments

Comments
 (0)