src/Entity/User.php line 15

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