SuperSeller3000/src/Domain/Auth/User.php

76 lines
2.2 KiB
PHP
Raw Normal View History

<?php
declare(strict_types=1);
namespace App\Domain\Auth;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Uid\Uuid;
#[ORM\Entity]
#[ORM\Table(name: 'users', schema: 'app')]
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
#[ORM\Id]
#[ORM\Column(type: 'uuid')]
private Uuid $id;
#[ORM\Column(type: 'string', length: 255, unique: true)]
private string $email;
#[ORM\Column(type: 'string')]
private string $passwordHash;
#[ORM\Column(type: 'string', nullable: true)]
private ?string $totpSecret = null;
/** @var array<string, bool> */
#[ORM\Column(type: 'json')]
private array $permissions = [];
#[ORM\Column(type: 'boolean')]
private bool $isActive = true;
public function __construct(string $email, string $passwordHash)
{
$this->id = Uuid::v7();
$this->email = $email;
$this->passwordHash = $passwordHash;
}
public function getId(): Uuid { return $this->id; }
public function getEmail(): string { return $this->email; }
public function getPassword(): string { return $this->passwordHash; }
public function getUserIdentifier(): string { return $this->email; }
/** @return list<string> */
public function getRoles(): array { return ['ROLE_USER']; }
public function eraseCredentials(): void {}
public function getTotpSecret(): ?string { return $this->totpSecret; }
public function setTotpSecret(?string $secret): void { $this->totpSecret = $secret; }
public function isActive(): bool { return $this->isActive; }
public function setIsActive(bool $active): void { $this->isActive = $active; }
/** @return array<string, bool> */
public function getPermissions(): array { return $this->permissions; }
public function hasPermission(string $permission): bool
{
return $this->permissions[$permission] ?? false;
}
public function grantPermission(string $permission): void
{
$this->permissions[$permission] = true;
}
public function revokePermission(string $permission): void
{
unset($this->permissions[$permission]);
}
}