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/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()
));
}
}
}

app/Notifications/FailedLogin.php

Open in GitHub
use Carbon\Carbon;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
 
class FailedLogin extends Notification
{
 
public function __construct(public $ip)
{
}
 
public function via($notifiable)
{
return ['mail'];
}
 
public function toArray($notifiable)
{
return ['ip' => $this->ip, 'time' => Carbon::now()];
}
 
public function toMail($notifiable)
{
return (new MailMessage())->error()->subject(\trans('email.fail-login-subject'))->greeting(\trans('email.fail-login-greeting'))->line(\trans('email.fail-login-line1'))->line(\trans('email.fail-login-line2', ['ip' => $this->ip, 'host' => \gethostbyaddr($this->ip), 'time' => Carbon::now()]));
}
}

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.