From 513543d1340485aff2970adb3b8317567380d8c0 Mon Sep 17 00:00:00 2001 From: TechTailor Date: Thu, 25 Feb 2021 21:07:54 +0530 Subject: [PATCH 1/3] Added Device Icons & Block Btn to Mail --- resources/lang/en/messages.php | 1 + .../views/emails/new-device-alert.blade.php | 34 +++++++++++++++---- src/Notifications/NewDeviceAlert.php | 33 ++++++++++++++++++ 3 files changed, 62 insertions(+), 6 deletions(-) diff --git a/resources/lang/en/messages.php b/resources/lang/en/messages.php index 755c278..e504bec 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.' ]; \ No newline at end of file diff --git a/resources/views/emails/new-device-alert.blade.php b/resources/views/emails/new-device-alert.blade.php index 845f2d9..951cd54 100644 --- a/resources/views/emails/new-device-alert.blade.php +++ b/resources/views/emails/new-device-alert.blade.php @@ -1,13 +1,35 @@ @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 + @if($isDeviceBlockingEnabled) + Block Device + @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 6be0b1e..13783e1 100644 --- a/src/Notifications/NewDeviceAlert.php +++ b/src/Notifications/NewDeviceAlert.php @@ -41,6 +41,24 @@ 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 = ''; + + /** + * Whether device blocking is enabled. + * + */ + public $isDeviceBlockingEnabled = true; + /** * Create a new notification instance. * @@ -56,6 +74,18 @@ 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'; + } } /** @@ -87,6 +117,9 @@ 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, + 'isDeviceBlockingEnabled' => $this->isDeviceBlockingEnabled ]); } From ece469daa61f3eca35a18eb9a0a0566cc1bc4d91 Mon Sep 17 00:00:00 2001 From: TechTailor Date: Sat, 6 Mar 2021 00:20:58 +0530 Subject: [PATCH 2/3] ui fix --- resources/views/emails/new-device-alert.blade.php | 7 ++----- src/Notifications/NewDeviceAlert.php | 9 +-------- 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/resources/views/emails/new-device-alert.blade.php b/resources/views/emails/new-device-alert.blade.php index 951cd54..cfac804 100644 --- a/resources/views/emails/new-device-alert.blade.php +++ b/resources/views/emails/new-device-alert.blade.php @@ -13,16 +13,13 @@ @elseif($deviceType == 'tablet') @endif - @if($isDeviceBlockingEnabled) - Block Device - @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 }})
+ @lang('auth-logger::messages.browser'): {{ $browser }} {{ $browserVersion ?? '' }}
+ @lang('auth-logger::messages.platform'): {{ $platform }} {{ $platformVersion ?? '' }}
@if($deviceName) @lang('auth-logger::messages.device'): {{ $deviceName }} @endif diff --git a/src/Notifications/NewDeviceAlert.php b/src/Notifications/NewDeviceAlert.php index 13783e1..b95ec7c 100644 --- a/src/Notifications/NewDeviceAlert.php +++ b/src/Notifications/NewDeviceAlert.php @@ -53,12 +53,6 @@ class NewDeviceAlert extends Notification implements ShouldQueue */ public $deviceName = ''; - /** - * Whether device blocking is enabled. - * - */ - public $isDeviceBlockingEnabled = true; - /** * Create a new notification instance. * @@ -118,8 +112,7 @@ public function toMail($notifiable) 'platform' => $this->platform, 'platformVersion' => $this->agent->version($this->platform), 'deviceType' => $this->deviceType, - 'deviceName' => $this->deviceName, - 'isDeviceBlockingEnabled' => $this->isDeviceBlockingEnabled + 'deviceName' => $this->deviceName ]); } From 4b2162f582b5aca54ee4e3c3f34f23edb2e529d1 Mon Sep 17 00:00:00 2001 From: TechTailor Date: Sat, 6 Mar 2021 00:28:29 +0530 Subject: [PATCH 3/3] styleci fixes --- resources/lang/en/messages.php | 2 +- src/Notifications/NewDeviceAlert.php | 10 +++------- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/resources/lang/en/messages.php b/resources/lang/en/messages.php index e504bec..8a467ca 100644 --- a/resources/lang/en/messages.php +++ b/resources/lang/en/messages.php @@ -23,5 +23,5 @@ '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.' + 'ignore' => 'If this was you, you can ignore this alert. If you suspect any suspicious activity on your account, please change your password.', ]; \ No newline at end of file diff --git a/src/Notifications/NewDeviceAlert.php b/src/Notifications/NewDeviceAlert.php index b95ec7c..1e213fb 100644 --- a/src/Notifications/NewDeviceAlert.php +++ b/src/Notifications/NewDeviceAlert.php @@ -43,13 +43,11 @@ class NewDeviceAlert extends Notification implements ShouldQueue /** * User's device type retrived from the user agent. - * */ public $deviceType; /** * User's device name (only for mobile devices). - * */ public $deviceName = ''; @@ -73,11 +71,9 @@ public function __construct(AuthLogger $authLogger) if ($this->agent->isMobile()) { $this->deviceType = 'mobile'; $this->deviceName = $this->agent->device(); - } - elseif ($this->agent->isTablet()) { + } elseif ($this->agent->isTablet()) { $this->deviceType = 'tablet'; - } - elseif ($this->agent->isDesktop()) { + } elseif ($this->agent->isDesktop()) { $this->deviceType = 'desktop'; } } @@ -112,7 +108,7 @@ public function toMail($notifiable) 'platform' => $this->platform, 'platformVersion' => $this->agent->version($this->platform), 'deviceType' => $this->deviceType, - 'deviceName' => $this->deviceName + 'deviceName' => $this->deviceName, ]); }