diff --git a/resources/lang/en/messages.php b/resources/lang/en/messages.php index 9cfdfe5..995d698 100644 --- a/resources/lang/en/messages.php +++ b/resources/lang/en/messages.php @@ -22,5 +22,6 @@ 'ip_address' => 'IP Address', 'browser' => 'Browser', 'platform' => 'Platform', + 'device' => 'Device', 'ignore' => 'If this was you, you can ignore this alert. If you suspect any suspicious activity on your account, please change your password.', ]; diff --git a/resources/views/emails/new-device-alert.blade.php b/resources/views/emails/new-device-alert.blade.php index 845f2d9..cfac804 100644 --- a/resources/views/emails/new-device-alert.blade.php +++ b/resources/views/emails/new-device-alert.blade.php @@ -1,13 +1,32 @@ @component('mail::message') # @lang('auth-logger::messages.hello')! - + {{ Lang::get('auth-logger::messages.content', ['app' => config('app.name')]) }} -> **@lang('auth-logger::messages.account'):** {{ $account->email }}
-> **@lang('auth-logger::messages.time'):** {{ $time->toCookieString() }}
-> **@lang('auth-logger::messages.ip_address'):** {{ $ipAddress }}
-> **@lang('auth-logger::messages.browser'):** {{ $browser }} ({{ $browserVersion }})
-> **@lang('auth-logger::messages.platform'):** {{ $platform }} ({{ $platformVersion }}) + + + + + +
+ @if($deviceType == 'mobile') + + @elseif($deviceType == 'desktop') + + @elseif($deviceType == 'tablet') + + @endif + + @lang('auth-logger::messages.account'): {{ $account->email }}
+ @lang('auth-logger::messages.time'): {{ $time->toCookieString() }}
+ @lang('auth-logger::messages.ip_address'): {{ $ipAddress }}
+ @lang('auth-logger::messages.browser'): {{ $browser }} {{ $browserVersion ?? '' }}
+ @lang('auth-logger::messages.platform'): {{ $platform }} {{ $platformVersion ?? '' }}
+ @if($deviceName) + @lang('auth-logger::messages.device'): {{ $deviceName }} + @endif +
+
@lang('auth-logger::messages.ignore') diff --git a/src/Notifications/NewDeviceAlert.php b/src/Notifications/NewDeviceAlert.php index e09fb43..0c72b77 100644 --- a/src/Notifications/NewDeviceAlert.php +++ b/src/Notifications/NewDeviceAlert.php @@ -39,6 +39,16 @@ class NewDeviceAlert extends Notification implements ShouldQueue */ public $platform; + /** + * User's device type retrived from the user agent. + */ + public $deviceType; + + /** + * User's device name (only for mobile devices). + */ + public $deviceName = ''; + /** * Create a new notification instance. * @@ -54,6 +64,16 @@ public function __construct(AuthLogger $authLogger) $this->agent->setUserAgent($authLogger->user_agent); $this->browser = $this->agent->browser(); $this->platform = $this->agent->platform(); + + // Check device type and fetch device name for mobile. + if ($this->agent->isMobile()) { + $this->deviceType = 'mobile'; + $this->deviceName = $this->agent->device(); + } elseif ($this->agent->isTablet()) { + $this->deviceType = 'tablet'; + } elseif ($this->agent->isDesktop()) { + $this->deviceType = 'desktop'; + } } /** @@ -85,6 +105,8 @@ public function toMail($notifiable) 'browserVersion' => $this->agent->version($this->browser), 'platform' => $this->platform, 'platformVersion' => $this->agent->version($this->platform), + 'deviceType' => $this->deviceType, + 'deviceName' => $this->deviceName, ]); }