2023-07-22 16:37:57 +00:00
|
|
|
<?php
|
|
|
|
namespace Misuzu\Auth;
|
|
|
|
|
|
|
|
use Index\DateTime;
|
|
|
|
use Index\Data\IDbResult;
|
|
|
|
use Index\Net\IPAddress;
|
|
|
|
use Misuzu\ClientInfo;
|
|
|
|
|
|
|
|
class LoginAttemptInfo {
|
2024-02-07 00:04:45 +00:00
|
|
|
public function __construct(
|
|
|
|
private ?string $userId,
|
|
|
|
private bool $success,
|
|
|
|
private string $remoteAddr,
|
|
|
|
private string $countryCode,
|
|
|
|
private int $created,
|
|
|
|
private string $userAgent,
|
|
|
|
private string $clientInfo,
|
|
|
|
) {}
|
2023-07-22 16:37:57 +00:00
|
|
|
|
2024-02-07 00:04:45 +00:00
|
|
|
public static function fromResult(IDbResult $result): LoginAttemptInfo {
|
|
|
|
return new LoginAttemptInfo(
|
|
|
|
userId: $result->getStringOrNull(0),
|
|
|
|
success: $result->getBoolean(1),
|
|
|
|
remoteAddr: $result->getString(2),
|
|
|
|
countryCode: $result->getString(3),
|
|
|
|
created: $result->getInteger(4),
|
|
|
|
userAgent: $result->getString(5),
|
|
|
|
clientInfo: $result->getString(6),
|
|
|
|
);
|
2023-07-22 16:37:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function hasUserId(): bool {
|
|
|
|
return $this->userId !== null;
|
|
|
|
}
|
|
|
|
|
2023-07-22 17:27:42 +00:00
|
|
|
public function getUserId(): ?string {
|
2023-07-22 16:37:57 +00:00
|
|
|
return $this->userId;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function isSuccess(): bool {
|
|
|
|
return $this->success;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getRemoteAddressRaw(): string {
|
|
|
|
return $this->remoteAddr;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getRemoteAddress(): IPAddress {
|
|
|
|
return IPAddress::parse($this->remoteAddr);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getCountryCode(): string {
|
|
|
|
return $this->countryCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getCreatedTime(): int {
|
|
|
|
return $this->created;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getCreatedAt(): DateTime {
|
|
|
|
return DateTime::fromUnixTimeSeconds($this->created);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getUserAgentString(): string {
|
|
|
|
return $this->userAgent;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getClientInfoRaw(): string {
|
|
|
|
return $this->clientInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getClientInfo(): ClientInfo {
|
|
|
|
return ClientInfo::decode($this->clientInfo);
|
|
|
|
}
|
|
|
|
}
|