Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

HDInnovations/UNIT3D-Community-Edition

2239 stars
2 code files
View HDInnovations/UNIT3D-Community-Edition on GitHub

app/Providers/EventServiceProvider.php

Open in GitHub
use Illuminate\Auth\Events\Failed;
use App\Listeners\FailedLoginListener;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
 
class EventServiceProvider extends ServiceProvider
{
protected $listen = [
//
Failed::class => [
FailedLoginListener::class,
],
//
];
//
}

app/Listeners/FailedLoginListener.php

Open in GitHub
use App\Models\FailedLoginAttempt;
use App\Models\Group;
use App\Notifications\FailedLogin;
 
class FailedLoginListener
{
public function handle($event)
{
$bannedGroup = \cache()->rememberForever('banned_group', fn () => Group::where('slug', '=', 'banned')->pluck('id'));
 
if (\property_exists($event, 'user') && $event->user !== null && $event->user instanceof \Illuminate\Database\Eloquent\Model
&& $event->user->group_id !== $bannedGroup[0]) {
FailedLoginAttempt::record(
$event->user,
\request()->input('username'),
\request()->ip()
);
 
$event->user->notify(new FailedLogin(
\request()->ip()
));
}
}
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.