misuzu/src/Auth/LoginAttemptInfo.php

75 lines
1.9 KiB
PHP

<?php
namespace Misuzu\Auth;
use Index\DateTime;
use Index\Data\IDbResult;
use Index\Net\IPAddress;
use Misuzu\ClientInfo;
class LoginAttemptInfo {
public function __construct(
private ?string $userId,
private bool $success,
private string $remoteAddr,
private string $countryCode,
private int $created,
private string $userAgent,
private string $clientInfo,
) {}
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),
);
}
public function hasUserId(): bool {
return $this->userId !== null;
}
public function getUserId(): ?string {
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);
}
}