Skip to content

Commit

Permalink
adding BotBlockedEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
AMoktar committed Sep 24, 2023
1 parent 99510fb commit cd65b97
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
35 changes: 35 additions & 0 deletions src/Events/BotBlockedEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Potelo\LaravelBlockBots\Events;

use Carbon\Carbon;
use Illuminate\Queue\SerializesModels;

class BotBlockedEvent
{
use SerializesModels;

public $ip;

/** @var integer */
public $number_of_hits;

/** @var Carbon */
public $block_date;

/**
* Create a new event instance.
*
* @param $ip
* @param integer $number_of_hits
* @param Carbon $block_date
*
* @return void
*/
public function __construct($ip, $number_of_hits, $block_date)
{
$this->ip = $ip;
$this->number_of_hits = $number_of_hits;
$this->block_date = $block_date;
}
}
5 changes: 4 additions & 1 deletion src/Middleware/BlockBots.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit cd65b97

Please sign in to comment.