Skip to content

Commit c5f370f

Browse files
author
Moinuddin S. Khaja
authored
Merge pull request #7 from Spargon/dev
Adds svg icons for desktop, mobile or tablet devices to the alert email.
2 parents f82edbb + 7a9ed39 commit c5f370f

File tree

3 files changed

+48
-6
lines changed

3 files changed

+48
-6
lines changed

resources/lang/en/messages.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,6 @@
2222
'ip_address' => 'IP Address',
2323
'browser' => 'Browser',
2424
'platform' => 'Platform',
25+
'device' => 'Device',
2526
'ignore' => 'If this was you, you can ignore this alert. If you suspect any suspicious activity on your account, please change your password.',
2627
];

resources/views/emails/new-device-alert.blade.php

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,32 @@
11
@component('mail::message')
22
# @lang('auth-logger::messages.hello')!
3-
3+
44
{{ Lang::get('auth-logger::messages.content', ['app' => config('app.name')]) }}
55

6-
> **@lang('auth-logger::messages.account'):** {{ $account->email }}<br>
7-
> **@lang('auth-logger::messages.time'):** {{ $time->toCookieString() }}<br>
8-
> **@lang('auth-logger::messages.ip_address'):** {{ $ipAddress }}<br>
9-
> **@lang('auth-logger::messages.browser'):** {{ $browser }} ({{ $browserVersion }})<br>
10-
> **@lang('auth-logger::messages.platform'):** {{ $platform }} ({{ $platformVersion }})
6+
<table>
7+
<tr>
8+
<td align="center">
9+
@if($deviceType == 'mobile')
10+
<svg height="120px" width="120px" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 18h.01M8 21h8a2 2 0 002-2V5a2 2 0 00-2-2H8a2 2 0 00-2 2v14a2 2 0 002 2z"></path></svg>
11+
@elseif($deviceType == 'desktop')
12+
<svg height="120px" width="120px" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9.75 17L9 20l-1 1h8l-1-1-.75-3M3 13h18M5 17h14a2 2 0 002-2V5a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"></path></svg>
13+
@elseif($deviceType == 'tablet')
14+
<svg height="120px" width="120px" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 18h.01M7 21h10a2 2 0 002-2V5a2 2 0 00-2-2H7a2 2 0 00-2 2v14a2 2 0 002 2z"></path></svg>
15+
@endif
16+
</td>
17+
<td width="75%">
18+
<b>@lang('auth-logger::messages.account'):</b> {{ $account->email }}<br>
19+
<b>@lang('auth-logger::messages.time'):</b> {{ $time->toCookieString() }}<br>
20+
<b>@lang('auth-logger::messages.ip_address'):</b> {{ $ipAddress }}<br>
21+
<b>@lang('auth-logger::messages.browser'):</b> {{ $browser }} <small>{{ $browserVersion ?? '' }}</small><br>
22+
<b>@lang('auth-logger::messages.platform'):</b> {{ $platform }} <small>{{ $platformVersion ?? '' }}</small><br>
23+
@if($deviceName)
24+
<b>@lang('auth-logger::messages.device'):</b> {{ $deviceName }}
25+
@endif
26+
</td>
27+
</tr>
28+
</table>
29+
<br>
1130

1231
@lang('auth-logger::messages.ignore')
1332

src/Notifications/NewDeviceAlert.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,16 @@ class NewDeviceAlert extends Notification implements ShouldQueue
3939
*/
4040
public $platform;
4141

42+
/**
43+
* User's device type retrived from the user agent.
44+
*/
45+
public $deviceType;
46+
47+
/**
48+
* User's device name (only for mobile devices).
49+
*/
50+
public $deviceName = '';
51+
4252
/**
4353
* Create a new notification instance.
4454
*
@@ -54,6 +64,16 @@ public function __construct(AuthLogger $authLogger)
5464
$this->agent->setUserAgent($authLogger->user_agent);
5565
$this->browser = $this->agent->browser();
5666
$this->platform = $this->agent->platform();
67+
68+
// Check device type and fetch device name for mobile.
69+
if ($this->agent->isMobile()) {
70+
$this->deviceType = 'mobile';
71+
$this->deviceName = $this->agent->device();
72+
} elseif ($this->agent->isTablet()) {
73+
$this->deviceType = 'tablet';
74+
} elseif ($this->agent->isDesktop()) {
75+
$this->deviceType = 'desktop';
76+
}
5777
}
5878

5979
/**
@@ -85,6 +105,8 @@ public function toMail($notifiable)
85105
'browserVersion' => $this->agent->version($this->browser),
86106
'platform' => $this->platform,
87107
'platformVersion' => $this->agent->version($this->platform),
108+
'deviceType' => $this->deviceType,
109+
'deviceName' => $this->deviceName,
88110
]);
89111
}
90112

0 commit comments

Comments
 (0)