Implement basic database access and login
This commit is contained in:
parent
8be7988d97
commit
b24fe56c8a
14 changed files with 307 additions and 31 deletions
75
src/Models/AdminUser.php
Normal file
75
src/Models/AdminUser.php
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace MailAccountAdmin\Models;
|
||||
|
||||
use DateTimeImmutable;
|
||||
|
||||
class AdminUser
|
||||
{
|
||||
/** @var int */
|
||||
private $id;
|
||||
/** @var string */
|
||||
private $username;
|
||||
/** @var string */
|
||||
private $passwordHash;
|
||||
/** @var bool */
|
||||
private $active;
|
||||
/** @var DateTimeImmutable */
|
||||
private $createdAt;
|
||||
/** @var DateTimeImmutable */
|
||||
private $modifiedAt;
|
||||
|
||||
private function __construct(int $id, string $username, string $passwordHash, bool $isActive,
|
||||
DateTimeImmutable $createdAt, DateTimeImmutable $modifiedAt)
|
||||
{
|
||||
$this->id = $id;
|
||||
$this->username = $username;
|
||||
$this->passwordHash = $passwordHash;
|
||||
$this->active = $isActive;
|
||||
$this->createdAt = $createdAt;
|
||||
$this->modifiedAt = $modifiedAt;
|
||||
}
|
||||
|
||||
public static function createFromArray(array $data): self
|
||||
{
|
||||
return new self(
|
||||
(int)$data['admin_id'],
|
||||
$data['username'],
|
||||
$data['password'],
|
||||
$data['is_active'] === '1',
|
||||
new DateTimeImmutable($data['created_at']),
|
||||
new DateTimeImmutable($data['modified_at']),
|
||||
);
|
||||
}
|
||||
|
||||
public function getId(): int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getUsername(): string
|
||||
{
|
||||
return $this->username;
|
||||
}
|
||||
|
||||
public function getPasswordHash(): string
|
||||
{
|
||||
return $this->passwordHash;
|
||||
}
|
||||
|
||||
public function isActive(): bool
|
||||
{
|
||||
return $this->active;
|
||||
}
|
||||
|
||||
public function getCreatedAt(): DateTimeImmutable
|
||||
{
|
||||
return $this->createdAt;
|
||||
}
|
||||
|
||||
public function getModifiedAt(): DateTimeImmutable
|
||||
{
|
||||
return $this->modifiedAt;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue