|
|
@ -3,97 +3,258 @@
|
|
|
|
namespace App\Entity;
|
|
|
|
namespace App\Entity;
|
|
|
|
|
|
|
|
|
|
|
|
use App\Repository\UserRepository;
|
|
|
|
use App\Repository\UserRepository;
|
|
|
|
|
|
|
|
use DateTimeImmutable;
|
|
|
|
|
|
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
|
|
|
|
|
|
|
use Doctrine\Common\Collections\Collection;
|
|
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
|
|
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
|
|
|
|
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
|
|
|
|
use Symfony\Component\Security\Core\User\UserInterface;
|
|
|
|
use Symfony\Component\Security\Core\User\UserInterface;
|
|
|
|
|
|
|
|
use Symfony\Component\Validator\Constraints as Assert;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* A registered user
|
|
|
|
|
|
|
|
*/
|
|
|
|
#[ORM\Entity(repositoryClass: UserRepository::class)]
|
|
|
|
#[ORM\Entity(repositoryClass: UserRepository::class)]
|
|
|
|
class User implements UserInterface, PasswordAuthenticatedUserInterface
|
|
|
|
class User implements UserInterface, PasswordAuthenticatedUserInterface {
|
|
|
|
{
|
|
|
|
use TEntityBase;
|
|
|
|
#[ORM\Id]
|
|
|
|
|
|
|
|
#[ORM\GeneratedValue]
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @var string|null The email
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#[ORM\Column(length: 100, unique: true)]
|
|
|
|
|
|
|
|
#[Assert\NotBlank]
|
|
|
|
|
|
|
|
#[Assert\Email]
|
|
|
|
|
|
|
|
private ?string $email = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @var string|null The hashed password
|
|
|
|
|
|
|
|
*/
|
|
|
|
#[ORM\Column]
|
|
|
|
#[ORM\Column]
|
|
|
|
private ?int $id = null;
|
|
|
|
#[Assert\NotBlank]
|
|
|
|
|
|
|
|
private ?string $password = null;
|
|
|
|
|
|
|
|
|
|
|
|
#[ORM\Column(length: 180, unique: true)]
|
|
|
|
/**
|
|
|
|
private ?string $username = null;
|
|
|
|
* @var string|null The name
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#[ORM\Column(length: 100, nullable: true)]
|
|
|
|
|
|
|
|
private ?string $name = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @var string[] The roles
|
|
|
|
|
|
|
|
*/
|
|
|
|
#[ORM\Column]
|
|
|
|
#[ORM\Column]
|
|
|
|
private array $roles = [];
|
|
|
|
private array $roles = [];
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @var string The hashed password
|
|
|
|
* @var Collection<int, Tag> The {@see Tag tags} of the user
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
#[ORM\Column]
|
|
|
|
#[ORM\OneToMany(mappedBy: 'user', targetEntity: Tag::class, orphanRemoval: true)]
|
|
|
|
private ?string $password = null;
|
|
|
|
#[Assert\Valid]
|
|
|
|
|
|
|
|
private Collection $tags;
|
|
|
|
|
|
|
|
|
|
|
|
public function getId(): ?int
|
|
|
|
/**
|
|
|
|
{
|
|
|
|
* @var User|null The administrator who had validated this user or Null if not validated yet
|
|
|
|
return $this->id;
|
|
|
|
*/
|
|
|
|
|
|
|
|
#[ORM\ManyToOne(targetEntity: self::class)]
|
|
|
|
|
|
|
|
#[Assert\Valid]
|
|
|
|
|
|
|
|
private ?self $validationAdministrator = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @var DateTimeImmutable|null The date and time of the validation of this user or Null if not validated yet
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#[ORM\Column(nullable: true)]
|
|
|
|
|
|
|
|
private ?DateTimeImmutable $validationDate = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Initialization
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function __construct () {
|
|
|
|
|
|
|
|
$this->tags = new ArrayCollection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function getUsername(): ?string
|
|
|
|
/**
|
|
|
|
{
|
|
|
|
* The email
|
|
|
|
return $this->username;
|
|
|
|
*
|
|
|
|
|
|
|
|
* @return string|null The email
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function getEmail (): ?string {
|
|
|
|
|
|
|
|
return $this->email;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Change the email
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param string $email The new email
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @return $this
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function setEmail (string $email): self {
|
|
|
|
|
|
|
|
$this->email = $email;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function setUsername(string $username): self
|
|
|
|
/**
|
|
|
|
{
|
|
|
|
* The hashed password
|
|
|
|
$this->username = $username;
|
|
|
|
*
|
|
|
|
|
|
|
|
* @return string The hashed password
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @see PasswordAuthenticatedUserInterface
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function getPassword (): string {
|
|
|
|
|
|
|
|
return $this->password;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Change the hashed password
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param string $password The new hashed password
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @return $this
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function setPassword (string $password): self {
|
|
|
|
|
|
|
|
$this->password = $password;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* The name
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @return string|null The name
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function getName (): ?string {
|
|
|
|
|
|
|
|
return $this->name;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Change the name
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param string|null $name The new name
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @return $this
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function setName (?string $name): self {
|
|
|
|
|
|
|
|
$this->name = $name;
|
|
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* A visual identifier that represents this user.
|
|
|
|
* A visual identifier that represents this user
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @see UserInterface
|
|
|
|
* @see UserInterface
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function getUserIdentifier(): string
|
|
|
|
public function getUserIdentifier (): string {
|
|
|
|
{
|
|
|
|
return (string)$this->email;
|
|
|
|
return (string) $this->username;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
|
|
|
|
* The roles
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @return string[] The roles
|
|
|
|
|
|
|
|
*
|
|
|
|
* @see UserInterface
|
|
|
|
* @see UserInterface
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function getRoles(): array
|
|
|
|
public function getRoles (): array {
|
|
|
|
{
|
|
|
|
|
|
|
|
$roles = $this->roles;
|
|
|
|
$roles = $this->roles;
|
|
|
|
// guarantee every user at least has ROLE_USER
|
|
|
|
// guarantee every user at least has ROLE_USER
|
|
|
|
$roles[] = 'ROLE_USER';
|
|
|
|
$roles[] = 'ROLE_USER';
|
|
|
|
|
|
|
|
|
|
|
|
return array_unique($roles);
|
|
|
|
return array_unique($roles);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
public function setRoles(array $roles): self
|
|
|
|
* Set the roles
|
|
|
|
{
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param array $roles The new roles
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @return void
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function setRoles (array $roles): void {
|
|
|
|
$this->roles = $roles;
|
|
|
|
$this->roles = $roles;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Removes sensitive data from the user
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @see UserInterface
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function eraseCredentials () {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @see PasswordAuthenticatedUserInterface
|
|
|
|
* The {@see Tag tags} of the user
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @return Collection<int, Tag> The {@see Tag tags} of the user
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function getPassword(): string
|
|
|
|
public function getTags (): Collection {
|
|
|
|
{
|
|
|
|
return $this->tags;
|
|
|
|
return $this->password;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Add a {@see Tag tag} to the user
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* Do nothing if the {@see Tag tag} already exists
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param Tag $tag The new {@see Tag tag}
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @return $this
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function addTag (Tag $tag): static {
|
|
|
|
|
|
|
|
if (!$this->tags->contains($tag)) {
|
|
|
|
|
|
|
|
$this->tags->add($tag);
|
|
|
|
|
|
|
|
$tag->setUser($this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function setPassword(string $password): self
|
|
|
|
return $this;
|
|
|
|
{
|
|
|
|
}
|
|
|
|
$this->password = $password;
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Remove a {@see Tag tag} from the user
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* Do nothing if the {@see Tag tag} don't exist
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param Tag $tag The {@see Tag tag} to remove
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @return $this
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function removeTag (Tag $tag): static {
|
|
|
|
|
|
|
|
if ($this->tags->removeElement($tag)) {
|
|
|
|
|
|
|
|
if ($tag->getUser() === $this) {
|
|
|
|
|
|
|
|
$tag->setUser(null);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @see UserInterface
|
|
|
|
* The administrator who had validated this user or Null if not validated yet
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @return self|null The administrator who had validated this user or Null if not validated yet
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @see self::validate()
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function getValidationAdministrator (): ?self
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return $this->validationAdministrator;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* The date and time of the validation of this user or Null if not validated yet
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @return DateTimeImmutable|null The date and time of the validation of this user or Null if not validated yet
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @see self::validate()
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function eraseCredentials()
|
|
|
|
public function getValidationDate (): ?DateTimeImmutable
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// If you store any temporary, sensitive data on the user, clear it here
|
|
|
|
return $this->validationDate;
|
|
|
|
// $this->plainPassword = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Validate this user
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* Set validation administrator and date-time
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param User $administrator The administrator doing the validation
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @return $this
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function validate (self $administrator): static {
|
|
|
|
|
|
|
|
$this->validationAdministrator = $administrator;
|
|
|
|
|
|
|
|
$this->validationDate = new DateTimeImmutable();
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|