hanyuu/src/Auth/Db/DbAuthLogin.php
2023-10-18 10:34:30 +00:00

78 lines
2.1 KiB
PHP

<?php
namespace Hanyuu\Auth\Db;
use Index\DateTime;
use Index\Data\IDbResult;
use Index\Net\IPAddress;
use Hanyuu\Auth\IAuthLogin;
class DbAuthLogin implements IAuthLogin {
private string $id;
private string $userId;
private IPAddress $remoteAddr;
private string $country;
private int $factorsRequired;
private int $factorsDone;
private DateTime $started;
private DateTime $valid;
private bool $hasCompleted;
private DateTime $completed;
public function __construct(IDbResult $result) {
$this->id = $result->getString(0);
$this->userId = $result->getString(1);
$this->remoteAddr = new IPAddress($result->getString(2));
$this->country = $result->getString(3);
$this->factorsRequired = $result->getInteger(4);
$this->factorsDone = $result->getInteger(5);
$this->started = DateTime::fromUnixTimeSeconds($result->getInteger(6));
$this->valid = DateTime::fromUnixTimeSeconds($result->getInteger(7));
$this->hasCompleted = !$result->isNull(8);
$this->completed = DateTime::fromUnixTimeSeconds($result->getInteger(8));
}
public function getId(): string {
return $this->id;
}
public function getUserId(): string {
return $this->userId;
}
public function getRemoteAddress(): IPAddress {
return $this->remoteAddr;
}
public function getCountryCode(): string {
return $this->country;
}
public function getFactorsRequired(): int {
return $this->factorsRequired;
}
public function getFactorsDone(): int {
return $this->factorsDone;
}
public function getStartedTime(): DateTime {
return $this->started;
}
public function isValid(): bool {
return DateTime::utcNow()->isLessThan($this->valid);
}
public function getValidTime(): DateTime {
return $this->valid;
}
public function hasCompleted(): bool {
return $this->hasCompleted;
}
public function getCompletedTime(): DateTime {
return $this->completed;
}
}