<?php
namespace App\Entity;
use App\Repository\UserRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Validator\Constraints as Assert;
use App\Validator as CDOSAssert;
/**
* @ORM\Entity(repositoryClass=UserRepository::class)
* @ORM\Table(name="`user`")
* @UniqueEntity(fields={"email"}, message="Il existe déjà un utilisateur avec cette adresse email")
*/
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=180, unique=true)
* @Assert\Email(message="Le format de mail n'est pas respecté")
*/
private $email;
/**
* @ORM\Column(type="string", nullable=true)
*/
private $firstName;
/**
* @ORM\Column(type="string", nullable=true)
*/
private $lastName;
/**
* @var string The hashed password
* @ORM\Column(type="string")
* @Assert\Length(min="8", minMessage="Le mot de passe doit contenir au moins 8 caractères")
* @CDOSAssert\StrongPassword(message="Le mot de passe doit contenir au moins une lettre majuscule, une lettre minuscule et un chiffre.")
*/
private $password;
/**
* @var string Confirmation of the password
* @Assert\EqualTo(propertyPath="password", message="Les deux mots de passe doivent être identiques")
*/
private $confirmPassword;
/**
* @ORM\Column(type="json")
*/
private array $roles = [];
/**
* @ORM\ManyToMany(targetEntity=Structure::class, inversedBy="users")
*/
private $structureUser;
/**
* @ORM\Column(type="boolean")
*/
private $isVerified = false;
public function __construct()
{
$this->structureUser = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
/**
* A visual identifier that represents this user.
*
* @see UserInterface
*/
public function getUserIdentifier(): string
{
return (string) $this->email;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}
/**
* @return mixed
*/
public function getUserType()
{
return $this->userType;
}
/**
* @param mixed $userType
*/
public function setUserType($userType): void
{
$this->userType = $userType;
}
/**
* @return mixed
*/
public function getFirstName()
{
return $this->firstName;
}
/**
* @param mixed $firstName
*/
public function setFirstName($firstName): void
{
$this->firstName = $firstName;
}
/**
* @return mixed
*/
public function getLastName()
{
return $this->lastName;
}
/**
* @param mixed $lastName
*/
public function setLastName($lastName): void
{
$this->lastName = $lastName;
}
/**
* @see PasswordAuthenticatedUserInterface
*/
public function getPassword(): string
{
return $this->password;
}
public function setPassword(string $password): self
{
$this->password = $password;
return $this;
}
/**
* @return string
*/
public function getConfirmPassword(): string
{
return $this->confirmPassword;
}
/**
* @param string $confirmPassword
*/
public function setConfirmPassword(string $confirmPassword): void
{
$this->confirmPassword = $confirmPassword;
}
/**
* @see UserInterface
*/
public function getRoles(): array
{
$roles = $this->roles;
// guarantee every user at least has ROLE_USER
$roles[] = 'ROLE_USER';
return array_unique($roles);
}
public function setRoles(array $roles): self
{
$this->roles = $roles;
return $this;
}
/**
* @see UserInterface
*/
public function eraseCredentials()
{
// If you store any temporary, sensitive data on the user, clear it here
// $this->plainPassword = null;
}
/**
* @return Collection<int, Structure>
*/
public function getStructureUser(): Collection
{
return $this->structureUser;
}
public function addStructureUser(Structure $structureUser): self
{
if (!$this->structureUser->contains($structureUser)) {
$this->structureUser[] = $structureUser;
}
return $this;
}
public function removeStructureUser(Structure $structureUser): self
{
$this->structureUser->removeElement($structureUser);
return $this;
}
public function isIsVerified(): ?bool
{
return $this->isVerified;
}
public function setIsVerified(bool $isVerified): self
{
$this->isVerified = $isVerified;
return $this;
}
}