src/Entity/User.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\UserRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  8. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  9. use Symfony\Component\Security\Core\User\UserInterface;
  10. /**
  11.  * @ORM\Entity(repositoryClass=UserRepository::class)
  12.  * @UniqueEntity(fields={"email"}, message="There is already an account with this email")
  13.  */
  14. class User implements UserInterfacePasswordAuthenticatedUserInterface
  15. {
  16.     /**
  17.      * @ORM\Id
  18.      * @ORM\GeneratedValue
  19.      * @ORM\Column(type="integer")
  20.      */
  21.     private $id;
  22.     /**
  23.      * @ORM\Column(type="string", length=180, unique=true)
  24.      */
  25.     private $email;
  26.     /**
  27.      * @ORM\Column(type="json")
  28.      */
  29.     private $roles = [];
  30.     /**
  31.      * @var string The hashed password
  32.      * @ORM\Column(type="string")
  33.      */
  34.     private $password;
  35.     /**
  36.      * @ORM\Column(type="string", length=255, nullable=true)
  37.      */
  38.     private $firstName;
  39.     /**
  40.      * @ORM\Column(type="string", length=255, nullable=true)
  41.      */
  42.     private $lastName;
  43.     /**
  44.      * @ORM\Column(type="boolean")
  45.      */
  46.     private $emailVerified;
  47.     public function getId(): ?int
  48.     {
  49.         return $this->id;
  50.     }
  51.     public function getEmail(): ?string
  52.     {
  53.         return $this->email;
  54.     }
  55.     public function setEmail(string $email): self
  56.     {
  57.         $this->email $email;
  58.         return $this;
  59.     }
  60.     /**
  61.      * A visual identifier that represents this user.
  62.      *
  63.      * @see UserInterface
  64.      */
  65.     public function getUserIdentifier(): string
  66.     {
  67.         return (string)$this->email;
  68.     }
  69.     /**
  70.      * @deprecated since Symfony 5.3, use getUserIdentifier instead
  71.      */
  72.     public function getUsername(): string
  73.     {
  74.         return (string)$this->email;
  75.     }
  76.     /**
  77.      * @see UserInterface
  78.      */
  79.     public function getRoles(): array
  80.     {
  81.         $roles $this->roles;
  82.         return array_unique($roles);
  83.     }
  84.     public function setRoles(array $roles): self
  85.     {
  86.         $this->roles $roles;
  87.         return $this;
  88.     }
  89.     /**
  90.      * @see PasswordAuthenticatedUserInterface
  91.      */
  92.     public function getPassword(): string
  93.     {
  94.         return $this->password;
  95.     }
  96.     public function setPassword(string $password): self
  97.     {
  98.         $this->password $password;
  99.         return $this;
  100.     }
  101.     /**
  102.      * Returning a salt is only needed, if you are not using a modern
  103.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  104.      *
  105.      * @see UserInterface
  106.      */
  107.     public function getSalt(): ?string
  108.     {
  109.         return null;
  110.     }
  111.     /**
  112.      * @see UserInterface
  113.      */
  114.     public function eraseCredentials()
  115.     {
  116.         // If you store any temporary, sensitive data on the user, clear it here
  117.         // $this->plainPassword = null;
  118.     }
  119.     public function getFirstName(): ?string
  120.     {
  121.         return $this->firstName;
  122.     }
  123.     public function setFirstName(?string $firstName): self
  124.     {
  125.         $this->firstName $firstName;
  126.         return $this;
  127.     }
  128.     public function getLastName(): ?string
  129.     {
  130.         return $this->lastName;
  131.     }
  132.     public function setLastName(?string $lastName): self
  133.     {
  134.         $this->lastName $lastName;
  135.         return $this;
  136.     }
  137.     public function getFullName(): ?string
  138.     {
  139.         return $this->firstName " " $this->lastName;
  140.     }
  141.     public function isEmailVerified(): ?bool
  142.     {
  143.         return $this->emailVerified;
  144.     }
  145.     public function setEmailVerified(bool $emailVerified): self
  146.     {
  147.         $this->emailVerified $emailVerified;
  148.         return $this;
  149.     }
  150. }