|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace KeyShang\AuthenticationLog\Notifications; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Bus\Queueable; |
|
6
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue; |
|
7
|
|
|
use Illuminate\Notifications\Messages\MailMessage; |
|
8
|
|
|
use Illuminate\Notifications\Notification; |
|
9
|
|
|
use Illuminate\Support\Carbon; |
|
10
|
|
|
use KeyShang\AuthenticationLog\AuthenticationLog; |
|
11
|
|
|
|
|
12
|
|
|
class NewDevice extends Notification implements ShouldQueue |
|
13
|
|
|
{ |
|
14
|
|
|
use Queueable; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* The authentication log. |
|
18
|
|
|
*/ |
|
19
|
|
|
public AuthenticationLog $authenticationLog; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Create a new notification instance. |
|
23
|
|
|
* |
|
24
|
|
|
* @param AuthenticationLog $authenticationLog |
|
25
|
|
|
* @return void |
|
26
|
|
|
*/ |
|
27
|
|
|
public function __construct(AuthenticationLog $authenticationLog) |
|
28
|
|
|
{ |
|
29
|
|
|
$this->authenticationLog = $authenticationLog; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Get the notification's delivery channels. |
|
34
|
|
|
* |
|
35
|
|
|
* @param mixed $notifiable |
|
36
|
|
|
*/ |
|
37
|
|
|
public function via($notifiable): array |
|
38
|
|
|
{ |
|
39
|
|
|
return $notifiable->notifyAuthenticationLogVia(); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Get the mail representation of the notification. |
|
44
|
|
|
* |
|
45
|
|
|
* @param mixed $notifiable |
|
46
|
|
|
*/ |
|
47
|
|
|
public function toMail($notifiable): MailMessage |
|
48
|
|
|
{ |
|
49
|
|
|
/** @var Carbon $loginAt */ |
|
50
|
|
|
$loginAt = $this->authenticationLog->login_at; |
|
51
|
|
|
$loginAt = $loginAt->setTimezone('UTC'); |
|
52
|
|
|
|
|
53
|
|
|
return (new MailMessage) |
|
54
|
|
|
->subject(trans('authentication-log::new_device.subject', ['app' => config('app.name')])) |
|
|
|
|
|
|
55
|
|
|
->markdown('authentication-log::emails.new_device', [ |
|
56
|
|
|
'account' => $notifiable, |
|
57
|
|
|
'loginAt' => $loginAt.' UTC', |
|
58
|
|
|
'ipAddress' => $this->authenticationLog->ip_address, |
|
59
|
|
|
'browser' => $this->authenticationLog->user_agent, |
|
60
|
|
|
]); |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|