Skip to content

Commit 47d123a

Browse files
committed
updated admin login columns
Signed-off-by: bidi <bidi@apidemia.com>
1 parent e7bbdcf commit 47d123a

4 files changed

Lines changed: 47 additions & 156 deletions

File tree

src/Admin/src/Service/AdminLoginService.php

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Dot\DependencyInjection\Attribute\Inject;
1515
use Dot\GeoIP\Service\LocationService;
1616
use Exception;
17+
use stdClass;
1718

1819
use function get_browser;
1920
use function in_array;
@@ -51,16 +52,12 @@ public function getAdminLogins(array $params): array
5152
'login.continent',
5253
'login.organization',
5354
'login.deviceType',
54-
'login.deviceBrand',
55-
'login.deviceModel',
5655
'login.isMobile',
5756
'login.osName',
5857
'login.osVersion',
59-
'login.osPlatform',
6058
'login.clientType',
6159
'login.clientName',
62-
'login.clientEngine',
63-
'login.clientVersion',
60+
'login.isCrawler',
6461
'login.loginStatus',
6562
'login.identity',
6663
'login.created',
@@ -101,12 +98,6 @@ public function logSuccessfulLogin(array $serverParams, string $name): AdminLogi
10198
*/
10299
private function logAdminVisit(array $serverParams, string $name, SuccessFailureEnum $status): AdminLogin
103100
{
104-
/**
105-
* For device information
106-
*
107-
* @see https://github.com/dotkernel/dot-user-agent-sniffer
108-
*/
109-
110101
$ipAddress = IpService::getUserIp($serverParams);
111102

112103
$country = $this->locationService->getCountry($ipAddress)->getName();
@@ -118,6 +109,7 @@ private function logAdminVisit(array $serverParams, string $name, SuccessFailure
118109
*
119110
* @see https://www.php.net/manual/en/function.get-browser.php
120111
*/
112+
$browser = new stdClass();
121113
if (ini_get('browscap')) {
122114
$browser = get_browser($_SERVER['HTTP_USER_AGENT']);
123115
}
@@ -127,20 +119,16 @@ private function logAdminVisit(array $serverParams, string $name, SuccessFailure
127119
->setContinent($continent)
128120
->setCountry($country)
129121
->setOrganization($organization)
130-
->setDeviceType($browser->device_type ?? null)
131-
->setDeviceBrand($browser->device_name ?? null)
132-
->setDeviceModel(null)
122+
->setDeviceType(! empty($browser->device_type) ? $browser->device_type : null)
133123
->setIsMobile(
134-
isset($browser->ismobiledevice) && $browser->ismobiledevice ? YesNoEnum::Yes : YesNoEnum::No
124+
! empty($browser->ismobiledevice) ? YesNoEnum::Yes : YesNoEnum::No
135125
)
136-
->setOsName($browser->platform_description ?? null)
137-
->setOsVersion($browser->platform_version ?? null)
138-
->setOsPlatform($browser->platform ?? null)
139-
->setClientType($browser->browser_type ?? null)
140-
->setClientName($browser->browser ?? null)
141-
->setClientEngine($browser->renderingengine_name ?? null)
142-
->setClientVersion(null)
126+
->setOsName(! empty($browser->platform) ? $browser->platform : null)
127+
->setOsVersion(! empty($browser->platform_version) ? $browser->platform_version : null)
128+
->setClientType(! empty($browser->browser_type) ? $browser->browser_type : null)
129+
->setClientName(! empty($browser->browser) ? $browser->browser : null)
143130
->setLoginStatus($status)
131+
->setIsCrawler(! empty($browser->crawler) ? YesNoEnum::Yes : YesNoEnum::No)
144132
->setIdentity($name);
145133

146134
$this->adminLoginRepository->saveResource($adminLogin);

src/Admin/templates/admin/list-admin-login.html.twig

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,6 @@
7676
<th class="column-login-deviceType">
7777
{{ sortableColumn('admin::list-admin-login', {}, pagination.queryParams, 'login.deviceType', 'Device Type') }}
7878
</th>
79-
<th class="column-login-deviceBrand">
80-
{{ sortableColumn('admin::list-admin-login', {}, pagination.queryParams, 'login.deviceBrand', 'Device Brand') }}
81-
</th>
82-
<th class="column-login-deviceModel">
83-
{{ sortableColumn('admin::list-admin-login', {}, pagination.queryParams, 'login.deviceModel', 'Device Model') }}
84-
</th>
8579
<th class="column-login-isMobile">
8680
{{ sortableColumn('admin::list-admin-login', {}, pagination.queryParams, 'login.isMobile', 'Is Mobile') }}
8781
</th>
@@ -91,20 +85,14 @@
9185
<th class="column-login-osVersion">
9286
{{ sortableColumn('admin::list-admin-login', {}, pagination.queryParams, 'login.osVersion', 'Os Version') }}
9387
</th>
94-
<th class="column-login-osPlatform">
95-
{{ sortableColumn('admin::list-admin-login', {}, pagination.queryParams, 'login.osPlatform', 'Os Platform') }}
96-
</th>
9788
<th class="column-login-clientType">
9889
{{ sortableColumn('admin::list-admin-login', {}, pagination.queryParams, 'login.clientType', 'Client Type') }}
9990
</th>
10091
<th class="column-login-clientName">
10192
{{ sortableColumn('admin::list-admin-login', {}, pagination.queryParams, 'login.clientName', 'Client Name') }}
10293
</th>
103-
<th class="column-login-clientEngine">
104-
{{ sortableColumn('admin::list-admin-login', {}, pagination.queryParams, 'login.clientEngine', 'Client Engine') }}
105-
</th>
106-
<th class="column-login-clientVersion">
107-
{{ sortableColumn('admin::list-admin-login', {}, pagination.queryParams, 'login.clientVersion', 'Client Version') }}
94+
<th class="column-login-isCrawler">
95+
{{ sortableColumn('admin::list-admin-login', {}, pagination.queryParams, 'login.isCrawler', 'Is Crawler') }}
10896
</th>
10997
<th class="column-login-created">
11098
{{ sortableColumn('admin::list-admin-login', {}, pagination.queryParams, 'login.created', 'Created') }}
@@ -127,8 +115,6 @@
127115
<td class="column-login-continent">{{ login.continent }}</td>
128116
<td class="column-login-organization">{{ login.organization }}</td>
129117
<td class="column-login-deviceType">{{ login.deviceType }}</td>
130-
<td class="column-login-deviceBrand">{{ login.deviceBrand }}</td>
131-
<td class="column-login-deviceModel">{{ login.deviceModel }}</td>
132118
<td class="column-login-isMobile">
133119
{% if login.isMobile.value == 'yes' %}
134120
<span class="badge text-bg-primary">Yes</span>
@@ -138,11 +124,15 @@
138124
</td>
139125
<td class="column-login-osName">{{ login.osName }}</td>
140126
<td class="column-login-osVersion">{{ login.osVersion }}</td>
141-
<td class="column-login-osPlatform">{{ login.osPlatform }}</td>
142127
<td class="column-login-clientType">{{ login.clientType }}</td>
143128
<td class="column-login-clientName">{{ login.clientName }}</td>
144-
<td class="column-login-clientEngine">{{ login.clientEngine }}</td>
145-
<td class="column-login-clientVersion">{{ login.clientVersion }}</td>
129+
<td class="column-login-isCrawler">
130+
{% if login.isCrawler.value == 'yes' %}
131+
<span class="badge text-bg-primary">Yes</span>
132+
{% else %}
133+
<span class="badge text-bg-secondary">No</span>
134+
{% endif %}
135+
</td>
146136
<td class="column-login-created">{{ login.getCreated()|date('Y-m-d H:i:s') }}</td>
147137
</tr>
148138
{% endfor %}

src/Core/src/Admin/src/Entity/AdminLogin.php

Lines changed: 24 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,6 @@ class AdminLogin extends AbstractEntity
3939
#[ORM\Column(name: 'deviceType', type: 'string', length: 191, nullable: true)]
4040
protected ?string $deviceType = null;
4141

42-
#[ORM\Column(name: 'deviceBrand', type: 'string', length: 191, nullable: true)]
43-
protected ?string $deviceBrand = null;
44-
45-
#[ORM\Column(name: 'deviceModel', type: 'string', length: 40, nullable: true)]
46-
protected ?string $deviceModel = null;
47-
4842
#[ORM\Column(type: 'yes_no_enum', nullable: true, enumType: YesNoEnum::class)]
4943
protected YesNoEnum $isMobile = YesNoEnum::No;
5044

@@ -54,20 +48,14 @@ class AdminLogin extends AbstractEntity
5448
#[ORM\Column(name: 'osVersion', type: 'string', length: 191, nullable: true)]
5549
protected ?string $osVersion = null;
5650

57-
#[ORM\Column(name: 'osPlatform', type: 'string', length: 191, nullable: true)]
58-
protected ?string $osPlatform = null;
59-
6051
#[ORM\Column(name: 'clientType', type: 'string', length: 191, nullable: true)]
6152
protected ?string $clientType = null;
6253

6354
#[ORM\Column(name: 'clientName', type: 'string', length: 191, nullable: true)]
6455
protected ?string $clientName = null;
6556

66-
#[ORM\Column(name: 'clientEngine', type: 'string', length: 191, nullable: true)]
67-
protected ?string $clientEngine = null;
68-
69-
#[ORM\Column(name: 'clientVersion', type: 'string', length: 191, nullable: true)]
70-
protected ?string $clientVersion = null;
57+
#[ORM\Column(type: 'yes_no_enum', nullable: true, enumType: YesNoEnum::class)]
58+
protected YesNoEnum $isCrawler = YesNoEnum::No;
7159

7260
#[ORM\Column(type: 'success_failure_enum', nullable: true, enumType: SuccessFailureEnum::class)]
7361
protected SuccessFailureEnum $loginStatus = SuccessFailureEnum::Fail;
@@ -144,30 +132,6 @@ public function setDeviceType(?string $deviceType): self
144132
return $this;
145133
}
146134

147-
public function getDeviceBrand(): ?string
148-
{
149-
return $this->deviceBrand;
150-
}
151-
152-
public function setDeviceBrand(?string $deviceBrand): self
153-
{
154-
$this->deviceBrand = $deviceBrand;
155-
156-
return $this;
157-
}
158-
159-
public function getDeviceModel(): ?string
160-
{
161-
return $this->deviceModel;
162-
}
163-
164-
public function setDeviceModel(?string $deviceModel): self
165-
{
166-
$this->deviceModel = $deviceModel;
167-
168-
return $this;
169-
}
170-
171135
public function getIsMobile(): ?YesNoEnum
172136
{
173137
return $this->isMobile;
@@ -204,18 +168,6 @@ public function setOsVersion(?string $osVersion): self
204168
return $this;
205169
}
206170

207-
public function getOsPlatform(): ?string
208-
{
209-
return $this->osPlatform;
210-
}
211-
212-
public function setOsPlatform(?string $osPlatform): self
213-
{
214-
$this->osPlatform = $osPlatform;
215-
216-
return $this;
217-
}
218-
219171
public function getClientType(): ?string
220172
{
221173
return $this->clientType;
@@ -240,26 +192,14 @@ public function setClientName(?string $clientName): self
240192
return $this;
241193
}
242194

243-
public function getClientEngine(): ?string
244-
{
245-
return $this->clientEngine;
246-
}
247-
248-
public function setClientEngine(?string $clientEngine): self
249-
{
250-
$this->clientEngine = $clientEngine;
251-
252-
return $this;
253-
}
254-
255-
public function getClientVersion(): ?string
195+
public function getIsCrawler(): ?YesNoEnum
256196
{
257-
return $this->clientVersion;
197+
return $this->isCrawler;
258198
}
259199

260-
public function setClientVersion(?string $clientVersion): self
200+
public function setIsCrawler(YesNoEnum $isCrawler): self
261201
{
262-
$this->clientVersion = $clientVersion;
202+
$this->isCrawler = $isCrawler;
263203

264204
return $this;
265205
}
@@ -285,16 +225,12 @@ public function setLoginStatus(SuccessFailureEnum $loginStatus): self
285225
* continent: string|null,
286226
* organization: string|null,
287227
* deviceType: string|null,
288-
* deviceBrand: string|null,
289-
* deviceModel: string|null,
290-
* isMobile: string,
228+
* isMobile: 'no'|'yes',
291229
* osName: string|null,
292230
* osVersion: string|null,
293-
* osPlatform: string|null,
294231
* clientType: string|null,
295232
* clientName: string|null,
296-
* clientEngine: string|null,
297-
* clientVersion: string|null,
233+
* isCrawler: 'no'|'yes',
298234
* loginStatus: string,
299235
* created: DateTimeImmutable|null,
300236
* updated: DateTimeImmutable|null,
@@ -303,26 +239,22 @@ public function setLoginStatus(SuccessFailureEnum $loginStatus): self
303239
public function getArrayCopy(): array
304240
{
305241
return [
306-
'id' => $this->id->toString(),
307-
'identity' => $this->identity,
308-
'adminIp' => $this->adminIp,
309-
'country' => $this->country,
310-
'continent' => $this->continent,
311-
'organization' => $this->organization,
312-
'deviceType' => $this->deviceType,
313-
'deviceBrand' => $this->deviceBrand,
314-
'deviceModel' => $this->deviceModel,
315-
'isMobile' => $this->isMobile->value,
316-
'osName' => $this->osName,
317-
'osVersion' => $this->osVersion,
318-
'osPlatform' => $this->osPlatform,
319-
'clientType' => $this->clientType,
320-
'clientName' => $this->clientName,
321-
'clientEngine' => $this->clientEngine,
322-
'clientVersion' => $this->clientVersion,
323-
'loginStatus' => $this->loginStatus->value,
324-
'created' => $this->created,
325-
'updated' => $this->updated,
242+
'id' => $this->id->toString(),
243+
'identity' => $this->identity,
244+
'adminIp' => $this->adminIp,
245+
'country' => $this->country,
246+
'continent' => $this->continent,
247+
'organization' => $this->organization,
248+
'deviceType' => $this->deviceType,
249+
'isMobile' => $this->isMobile->value,
250+
'osName' => $this->osName,
251+
'osVersion' => $this->osVersion,
252+
'clientType' => $this->clientType,
253+
'clientName' => $this->clientName,
254+
'isCrawler' => $this->isCrawler->value,
255+
'loginStatus' => $this->loginStatus->value,
256+
'created' => $this->created,
257+
'updated' => $this->updated,
326258
];
327259
}
328260
}

test/Unit/Admin/Entity/AdminLoginTest.php

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,6 @@ public function testAccessors(): void
6767
$this->assertSame(AdminLogin::class, $adminLogin::class);
6868
$this->assertSame('test', $adminLogin->getDeviceType());
6969

70-
$this->assertNull($adminLogin->getDeviceBrand());
71-
$adminLogin = $adminLogin->setDeviceBrand('test');
72-
$this->assertSame(AdminLogin::class, $adminLogin::class);
73-
$this->assertSame('test', $adminLogin->getDeviceBrand());
74-
75-
$this->assertNull($adminLogin->getDeviceModel());
76-
$adminLogin = $adminLogin->setDeviceModel('test');
77-
$this->assertSame(AdminLogin::class, $adminLogin::class);
78-
$this->assertSame('test', $adminLogin->getDeviceModel());
79-
8070
$this->assertSame(YesNoEnum::No, $adminLogin->getIsMobile());
8171
$adminLogin = $adminLogin->setIsMobile(YesNoEnum::Yes);
8272
$this->assertSame(AdminLogin::class, $adminLogin::class);
@@ -93,11 +83,6 @@ public function testAccessors(): void
9383
$this->assertSame(AdminLogin::class, $adminLogin::class);
9484
$this->assertSame('test', $adminLogin->getOsVersion());
9585

96-
$this->assertNull($adminLogin->getOsPlatform());
97-
$adminLogin = $adminLogin->setOsPlatform('test');
98-
$this->assertSame(AdminLogin::class, $adminLogin::class);
99-
$this->assertSame('test', $adminLogin->getOsPlatform());
100-
10186
$this->assertNull($adminLogin->getClientType());
10287
$adminLogin = $adminLogin->setClientType('test');
10388
$this->assertSame(AdminLogin::class, $adminLogin::class);
@@ -108,15 +93,11 @@ public function testAccessors(): void
10893
$this->assertSame(AdminLogin::class, $adminLogin::class);
10994
$this->assertSame('test', $adminLogin->getClientName());
11095

111-
$this->assertNull($adminLogin->getClientEngine());
112-
$adminLogin = $adminLogin->setClientEngine('test');
113-
$this->assertSame(AdminLogin::class, $adminLogin::class);
114-
$this->assertSame('test', $adminLogin->getClientEngine());
115-
116-
$this->assertNull($adminLogin->getClientVersion());
117-
$adminLogin = $adminLogin->setClientVersion('test');
96+
$this->assertSame(YesNoEnum::No, $adminLogin->getIsCrawler());
97+
$adminLogin = $adminLogin->setIsCrawler(YesNoEnum::Yes);
11898
$this->assertSame(AdminLogin::class, $adminLogin::class);
119-
$this->assertSame('test', $adminLogin->getClientVersion());
99+
$this->assertNotNull($adminLogin->getIsCrawler());
100+
$this->assertSame('yes', $adminLogin->getIsCrawler()->value);
120101

121102
$this->assertSame(SuccessFailureEnum::Fail, $adminLogin->getLoginStatus());
122103
$adminLogin = $adminLogin->setLoginStatus(SuccessFailureEnum::Success);

0 commit comments

Comments
 (0)