feat: minimal locally stored user entity

This commit is contained in:
Björn Fromme
2025-04-24 17:09:05 +02:00
parent 53884e4e12
commit c418ae6399
14 changed files with 217 additions and 200 deletions
+126
View File
@@ -0,0 +1,126 @@
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
#[ORM\Entity]
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private ?int $id = null;
#[ORM\Column(type: 'string', length: 180, unique: true)]
private ?string $email;
#[ORM\Column(type: 'text')]
private ?string $password;
#[ORM\Column(type: 'integer', nullable: true)]
private ?int $personId = null;
#[ORM\Column(type: 'integer', nullable: true)]
private ?int $addressId = null;
#[ORM\Column(type: 'json')]
private array $roles = [];
#[ORM\Column(type: 'datetime_immutable', nullable: true)]
private ?\DateTimeImmutable $lastLoginAt = null;
public function __construct(string $email, string $password)
{
$this->email = $email;
$this->password = base64_encode($password);
}
public function getId(): ?int
{
return $this->id;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(?string $email): static
{
$this->email = $email;
return $this;
}
public function getPersonId(): ?int
{
return $this->personId;
}
public function setPersonId(?int $personId): static
{
$this->personId = $personId;
return $this;
}
public function getAddressId(): ?int
{
return $this->addressId;
}
public function setAddressId(?int $addressId): static
{
$this->addressId = $addressId;
return $this;
}
public function getPassword(): ?string
{
return base64_decode($this->password);
}
public function setPassword(?string $password): static
{
$this->password = base64_encode($password);
return $this;
}
public function getRoles(): array
{
return ['ROLE_USER', ...$this->roles];
}
public function setRoles(array $roles): static
{
$this->roles = $roles;
return $this;
}
public function getLastLoginAt(): ?\DateTimeImmutable
{
return $this->lastLoginAt;
}
public function setLastLoginAt(?\DateTimeImmutable $lastLoginAt): static
{
$this->lastLoginAt = $lastLoginAt;
return $this;
}
public function eraseCredentials(): void
{
}
public function getUserIdentifier(): string
{
return $this->email;
}
}