2FAuth/app/Notifications/SignedInWithNewDeviceNotification.php

59 lines
1.5 KiB
PHP
Raw Normal View History

2024-04-15 00:44:18 +02:00
<?php
namespace App\Notifications;
use App\Models\AuthLog;
2024-04-15 00:44:18 +02:00
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
use Jenssegers\Agent\Agent;
class SignedInWithNewDeviceNotification extends Notification implements ShouldQueue
2024-04-15 00:44:18 +02:00
{
use Queueable;
2024-04-26 08:01:20 +02:00
/**
* The AuthLog model instance
*/
public AuthLog $authLog;
2024-04-15 00:44:18 +02:00
/**
* A user agent parser instance.
*
* @var mixed
*/
protected $agent;
/**
* Create a new SignedInWithNewDeviceNotification instance
*/
public function __construct(AuthLog $authLog)
2024-04-15 00:44:18 +02:00
{
$this->authLog = $authLog;
$this->agent = new Agent();
$this->agent->setUserAgent($authLog->user_agent);
2024-04-15 00:44:18 +02:00
}
2024-04-20 19:03:44 +02:00
public function via(mixed $notifiable) : array|string
2024-04-15 00:44:18 +02:00
{
return $notifiable->notifyAuthLogVia();
2024-04-15 00:44:18 +02:00
}
/**
* Wrap the notification to a mail envelop
*/
2024-04-20 19:03:44 +02:00
public function toMail(mixed $notifiable) : MailMessage
2024-04-15 00:44:18 +02:00
{
return (new MailMessage())
->subject(__('notifications.new_device.subject'))
->markdown('emails.signedInWithNewDevice', [
2024-04-15 00:44:18 +02:00
'account' => $notifiable,
'time' => $this->authLog->login_at,
'ipAddress' => $this->authLog->ip_address,
2024-04-15 00:44:18 +02:00
'browser' => $this->agent->browser(),
'platform' => $this->agent->platform(),
]);
}
}