10
10
11
11
use Carbon \Carbon ;
12
12
use Potelo \LaravelBlockBots \CheckIfBotIsReal ;
13
+ use Potelo \LaravelBlockBots \Events \UserBlockedEvent ;
13
14
14
15
15
16
class BlockBots
@@ -71,7 +72,8 @@ public function blocked($request, $dailyLimit)
71
72
72
73
$ full_url = substr ($ request ->fullUrl (), strlen ($ request ->getScheme (). ":// " )); # Get the URL without scheme
73
74
74
- $ key_access_count = "block_bot: {$ ip }" ;
75
+ $ key_identifier = Auth::check () ? Auth::id () : $ ip ;
76
+ $ key_access_count = "block_bot: {$ key_identifier }" ;
75
77
76
78
$ number_of_hits = 1 ;
77
79
@@ -95,23 +97,22 @@ public function blocked($request, $dailyLimit)
95
97
return false ;
96
98
}
97
99
else {
98
- if ($ log_blocked_requests ){
100
+ if ($ log_blocked_requests ){
99
101
$ key_notified = "block_bot:notified: {$ ip }" ;
100
- if (!Redis::exists ($ key_notified ))
101
- {
102
+ if (!Redis::exists ($ key_notified )) {
102
103
$ end_of_day_unix_timestamp = Carbon::tomorrow ()->startOfDay ()->timestamp ;
103
104
Redis::set ($ key_notified , 1 );
104
105
Redis::expireat ($ key_notified , $ end_of_day_unix_timestamp );
105
- \ Potelo \ LaravelBlockBots \ Jobs \ProcessLogWithIpInfo:: dispatch ( $ ip , $ user_agent , ' BLOCKED ' , $ full_url );
106
-
107
- }
106
+ if (Auth:: guest ()) {
107
+ \ Potelo \ LaravelBlockBots \ Jobs \ProcessLogWithIpInfo:: dispatch ( $ ip , $ user_agent , ' BLOCKED ' , $ full_url );
108
+ }
108
109
}
110
+ }
109
111
110
- if ($ fake_mode )
111
- {
112
+ if ($ fake_mode ) {
112
113
return false ;
113
- }
114
- else {
114
+ } else {
115
+ event ( new UserBlockedEvent (Auth:: user (), $ number_of_hits , Carbon:: now ()));
115
116
return true ;
116
117
}
117
118
}
0 commit comments