2024-04-15 00:44:18 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Notifications;
|
|
|
|
|
|
|
|
use Illuminate\Bus\Queueable;
|
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
|
|
use Illuminate\Notifications\Messages\MailMessage;
|
|
|
|
use Illuminate\Notifications\Notification;
|
|
|
|
use Jenssegers\Agent\Agent;
|
2024-04-20 18:10:30 +02:00
|
|
|
use Bubka\LaravelAuthenticationLog\Models\AuthenticationLog;
|
2024-04-15 00:44:18 +02:00
|
|
|
|
|
|
|
class SignedInWithNewDevice extends Notification implements ShouldQueue
|
|
|
|
{
|
|
|
|
use Queueable;
|
|
|
|
|
|
|
|
public AuthenticationLog $authenticationLog;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A user agent parser instance.
|
|
|
|
*
|
|
|
|
* @var mixed
|
|
|
|
*/
|
|
|
|
protected $agent;
|
|
|
|
|
2024-04-20 18:10:30 +02:00
|
|
|
/**
|
|
|
|
* Create a new SignedInWithNewDevice instance
|
|
|
|
*/
|
2024-04-15 00:44:18 +02:00
|
|
|
public function __construct(AuthenticationLog $authenticationLog)
|
|
|
|
{
|
|
|
|
$this->authenticationLog = $authenticationLog;
|
|
|
|
$this->agent = new Agent();
|
|
|
|
$this->agent->setUserAgent($authenticationLog->user_agent);
|
|
|
|
}
|
|
|
|
|
2024-04-20 18:10:30 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2024-04-15 00:44:18 +02:00
|
|
|
public function via($notifiable)
|
|
|
|
{
|
|
|
|
return $notifiable->notifyAuthenticationLogVia();
|
|
|
|
}
|
|
|
|
|
2024-04-20 18:10:30 +02:00
|
|
|
/**
|
|
|
|
* Wrap the notification to a mail envelop
|
|
|
|
*/
|
2024-04-15 00:44:18 +02:00
|
|
|
public function toMail($notifiable)
|
|
|
|
{
|
|
|
|
return (new MailMessage())
|
|
|
|
->subject(__('notifications.new_device.subject'))
|
|
|
|
->markdown('emails.newDevice', [
|
|
|
|
'account' => $notifiable,
|
|
|
|
'time' => $this->authenticationLog->login_at,
|
|
|
|
'ipAddress' => $this->authenticationLog->ip_address,
|
|
|
|
'browser' => $this->agent->browser(),
|
|
|
|
'platform' => $this->agent->platform(),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|