111 lines
2.6 KiB
PHP
111 lines
2.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Entity;
|
|
|
|
use ApiPlatform\Metadata\ApiResource;
|
|
use ApiPlatform\Metadata\Get;
|
|
use ApiPlatform\Metadata\GetCollection;
|
|
use App\State\MeProvider;
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
|
|
use Symfony\Component\Security\Core\User\UserInterface;
|
|
use Symfony\Component\Serializer\Attribute\Groups;
|
|
|
|
#[ORM\Entity]
|
|
#[ORM\Table(name: 'user', schema: 'public')]
|
|
#[ApiResource(
|
|
operations: [
|
|
new Get(
|
|
uriTemplate: '/me',
|
|
normalizationContext: ['groups' => ['user:read']],
|
|
security: "is_granted('ROLE_USER')",
|
|
provider: MeProvider::class
|
|
),
|
|
new Get(
|
|
requirements: ['id' => '\d+'],
|
|
normalizationContext: ['groups' => ['user:read']],
|
|
security: "is_granted('ROLE_USER')"
|
|
),
|
|
new GetCollection(
|
|
normalizationContext: ['groups' => ['user:read']],
|
|
security: "is_granted('PUBLIC_ACCESS')"
|
|
),
|
|
],
|
|
normalizationContext: ['groups' => ['user:read']],
|
|
paginationEnabled: false
|
|
)]
|
|
class User implements UserInterface, PasswordAuthenticatedUserInterface
|
|
{
|
|
#[ORM\Id]
|
|
#[ORM\GeneratedValue]
|
|
#[ORM\Column(type: 'integer')]
|
|
#[Groups(['user:read', 'reception:read'])]
|
|
private ?int $id = null;
|
|
|
|
#[ORM\Column(length: 180, unique: true)]
|
|
#[Groups(['user:read', 'reception:read'])]
|
|
private string $username = '';
|
|
|
|
#[ORM\Column(type: 'json')]
|
|
private array $roles = [];
|
|
|
|
#[ORM\Column]
|
|
private string $password = '';
|
|
|
|
public function getId(): ?int
|
|
{
|
|
return $this->id;
|
|
}
|
|
|
|
public function getUsername(): string
|
|
{
|
|
return $this->username;
|
|
}
|
|
|
|
public function setUsername(string $username): self
|
|
{
|
|
$this->username = $username;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getUserIdentifier(): string
|
|
{
|
|
return $this->username;
|
|
}
|
|
|
|
public function getRoles(): array
|
|
{
|
|
$roles = $this->roles;
|
|
$roles[] = 'ROLE_USER';
|
|
|
|
return array_unique($roles);
|
|
}
|
|
|
|
public function setRoles(array $roles): self
|
|
{
|
|
$this->roles = $roles;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getPassword(): string
|
|
{
|
|
return $this->password;
|
|
}
|
|
|
|
public function setPassword(string $password): self
|
|
{
|
|
$this->password = $password;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function eraseCredentials(): void
|
|
{
|
|
// No-op: we don't store temporary sensitive data on the entity.
|
|
}
|
|
}
|