Skip to content

Commit

Permalink
Merge pull request #233 from dotkernel/issue-232
Browse files Browse the repository at this point in the history
Issue #232: Removed user-agent-sniffer
  • Loading branch information
arhimede committed Apr 11, 2024
2 parents ec8143b + 756b180 commit c83fa8b
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 43 deletions.
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
"dotkernel/dot-rbac-guard": "^3.4.2",
"dotkernel/dot-session": "^5.4.2",
"dotkernel/dot-twigrenderer": "3.4.3",
"dotkernel/dot-user-agent-sniffer": "^3.3.3",
"friendsofphp/proxy-manager-lts": "^1.0.16",
"laminas/laminas-component-installer": "^3.4.0",
"laminas/laminas-config-aggregator": "^1.14.0",
Expand Down
1 change: 0 additions & 1 deletion config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
Dot\Rbac\Guard\ConfigProvider::class,
Dot\Session\ConfigProvider::class,
Dot\Twig\ConfigProvider::class,
Dot\UserAgentSniffer\ConfigProvider::class,
Dot\Cache\ConfigProvider::class,

// Include cache configuration
Expand Down
18 changes: 9 additions & 9 deletions public/images/app/favicon/browserconfig.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<browserconfig>
<msapplication>
<tile>
<square150x150logo src="/mstile-150x150.png"/>
<TileColor>#2d89ef</TileColor>
</tile>
</msapplication>
</browserconfig>
<?xml version="1.0" encoding="utf-8"?>
<browserconfig>
<msapplication>
<tile>
<square150x150logo src="/mstile-150x150.png"/>
<TileColor>#2d89ef</TileColor>
</tile>
</msapplication>
</browserconfig>
47 changes: 17 additions & 30 deletions src/Admin/src/Service/AdminService.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use Dot\AnnotatedServices\Annotation\Inject;
use Dot\AnnotatedServices\Annotation\Service;
use Dot\GeoIP\Service\LocationServiceInterface;
use Dot\UserAgentSniffer\Service\DeviceServiceInterface;
use Frontend\Admin\Entity\Admin;
use Frontend\Admin\Entity\AdminLogin;
use Frontend\Admin\Entity\AdminRole;
Expand All @@ -38,17 +37,15 @@ class AdminService implements AdminServiceInterface
/**
* @Inject({
* LocationServiceInterface::class,
* DeviceServiceInterface::class,
* EntityManager::class,
* "config.resultCacheLifetime"
* })
* @throws NotSupported
*/
public function __construct(
protected LocationServiceInterface $locationService,
protected DeviceServiceInterface $deviceService,
EntityManager $em,
int $cacheLifetime
int $cacheLifetime,
) {
$this->adminRepository = $em->getRepository(Admin::class);
$this->adminRoleRepository = $em->getRepository(AdminRole::class);
Expand Down Expand Up @@ -215,9 +212,11 @@ public function updateAdmin(Admin $admin, array $data): Admin

public function logAdminVisit(array $serverParams, string $name): AdminLogin
{
$deviceData = $this->deviceService->getDetails($serverParams['HTTP_USER_AGENT']);
$deviceOs = ! empty($deviceData->getOs()->getName()) ? $deviceData->getOs() : null;
$deviceClient = ! empty($deviceData->getClient()->getName()) ? $deviceData->getClient() : null;
/**
* For device information
*
* @see https://github.com/dotkernel/dot-user-agent-sniffer
*/

$ipAddress = IpService::getUserIp($serverParams);

Expand All @@ -230,34 +229,22 @@ public function logAdminVisit(array $serverParams, string $name): AdminLogin
$organization = ! empty($this->locationService->getOrganization($ipAddress)->getName()) ?
$this->locationService->getOrganization($ipAddress)->getName() : '';

$deviceType = ! empty($deviceData->getType()) ? $deviceData->getType() : null;
$deviceBrand = ! empty($deviceData->getBrand()) ? $deviceData->getBrand() : null;
$deviceModel = ! empty($deviceData->getModel()) ? $deviceData->getModel() : null;
$isMobile = $deviceData->getIsMobile() ? AdminLogin::IS_MOBILE_YES : AdminLogin::IS_MOBILE_NO;
$osName = ! empty($deviceOs->getName()) ? $deviceOs->getName() : null;
$osVersion = ! empty($deviceOs->getVersion()) ? $deviceOs->getVersion() : null;
$osPlatform = ! empty($deviceOs->getPlatform()) ? $deviceOs->getPlatform() : null;
$clientType = ! empty($deviceClient->getType()) ? $deviceClient->getType() : null;
$clientName = ! empty($deviceClient->getName()) ? $deviceClient->getName() : null;
$clientEngine = ! empty($deviceClient->getEngine()) ? $deviceClient->getEngine() : null;
$clientVersion = ! empty($deviceClient->getVersion()) ? $deviceClient->getVersion() : null;

$adminLogin = (new AdminLogin())
->setAdminIp($ipAddress)
->setContinent($continent)
->setCountry($country)
->setOrganization($organization)
->setDeviceType($deviceType)
->setDeviceBrand($deviceBrand)
->setDeviceModel($deviceModel)
->setIsMobile($isMobile)
->setOsName($osName)
->setOsVersion($osVersion)
->setOsPlatform($osPlatform)
->setClientType($clientType)
->setClientName($clientName)
->setClientEngine($clientEngine)
->setClientVersion($clientVersion)
->setDeviceType(null)
->setDeviceBrand(null)
->setDeviceModel(null)
->setIsMobile(AdminLogin::IS_MOBILE_NO)
->setOsName(null)
->setOsVersion(null)
->setOsPlatform(null)
->setClientType(null)
->setClientName(null)
->setClientEngine(null)
->setClientVersion(null)
->setIdentity($name);

return $this->adminRepository->saveAdminVisit($adminLogin);
Expand Down
2 changes: 0 additions & 2 deletions test/Unit/Admin/Service/AdminServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Exception\NotSupported;
use Dot\GeoIP\Service\LocationServiceInterface;
use Dot\UserAgentSniffer\Service\DeviceServiceInterface;
use Frontend\Admin\Service\AdminService;
use Frontend\Admin\Service\AdminServiceInterface;
use FrontendTest\Unit\UnitTest;
Expand All @@ -30,7 +29,6 @@ public function testWillCreate(): void

$service = new AdminService(
$this->createMock(LocationServiceInterface::class),
$this->createMock(DeviceServiceInterface::class),
$entityManager,
0
);
Expand Down

0 comments on commit c83fa8b

Please sign in to comment.