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="array", nullable=true)
  35.      */
  36.     private $role = [];
  37.     /**
  38.      * @ORM\Column(type="string", length=255, nullable=true)
  39.      */
  40.     private $name;
  41.     /**
  42.      * @ORM\Column(type="string", length=255, nullable=true)
  43.      */
  44.     private $surname;
  45.     /**
  46.      * @ORM\Column(type="string", length=255, nullable=true)
  47.      */
  48.     private $organization;
  49.     /**
  50.      * @ORM\Column(type="boolean")
  51.      */
  52.     private $isVerified false;
  53.     public function getId(): ?int
  54.     {
  55.         return $this->id;
  56.     }
  57.     public function getEmail(): ?string
  58.     {
  59.         return $this->email;
  60.     }
  61.     public function setEmail(string $email): self
  62.     {
  63.         $this->email $email;
  64.         return $this;
  65.     }
  66.     /**
  67.      * A visual identifier that represents this user.
  68.      *
  69.      * @see UserInterface
  70.      */
  71.     public function getUserIdentifier(): string
  72.     {
  73.         return (string) $this->email;
  74.     }
  75.     /**
  76.      * @deprecated since Symfony 5.3, use getUserIdentifier instead
  77.      */
  78.     public function getUsername(): string
  79.     {
  80.         return (string) $this->email;
  81.     }
  82.     /**
  83.      * @see UserInterface
  84.      */
  85.     public function getRoles(): array
  86.     {
  87.         $roles $this->roles;
  88.         // guarantee every user at least has ROLE_USER
  89.         $roles[] = 'ROLE_USER';
  90.         return array_unique($roles);
  91.     }
  92.     public function setRoles(array $roles): self
  93.     {
  94.         $this->roles $roles;
  95.         return $this;
  96.     }
  97.     /**
  98.      * @see PasswordAuthenticatedUserInterface
  99.      */
  100.     public function getPassword(): string
  101.     {
  102.         return $this->password;
  103.     }
  104.     public function setPassword(string $password): self
  105.     {
  106.         $this->password $password;
  107.         return $this;
  108.     }
  109.     /**
  110.      * Returning a salt is only needed, if you are not using a modern
  111.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  112.      *
  113.      * @see UserInterface
  114.      */
  115.     public function getSalt(): ?string
  116.     {
  117.         return null;
  118.     }
  119.     /**
  120.      * @see UserInterface
  121.      */
  122.     public function eraseCredentials()
  123.     {
  124.         // If you store any temporary, sensitive data on the user, clear it here
  125.         // $this->plainPassword = null;
  126.     }
  127.     public function getRole(): ?array
  128.     {
  129.         return $this->role;
  130.     }
  131.     public function setRole(?array $role): self
  132.     {
  133.         $this->role $role;
  134.         return $this;
  135.     }
  136.     public function getName(): ?string
  137.     {
  138.         return $this->name;
  139.     }
  140.     public function setName(?string $name): self
  141.     {
  142.         $this->name $name;
  143.         return $this;
  144.     }
  145.     public function getSurname(): ?string
  146.     {
  147.         return $this->surname;
  148.     }
  149.     public function setSurname(?string $surname): self
  150.     {
  151.         $this->surname $surname;
  152.         return $this;
  153.     }
  154.     public function getOrganization(): ?string
  155.     {
  156.         return $this->organization;
  157.     }
  158.     public function setOrganization(?string $organization): self
  159.     {
  160.         $this->organization $organization;
  161.         return $this;
  162.     }
  163.     public function isVerified(): bool
  164.     {
  165.         return $this->isVerified;
  166.     }
  167.     public function setIsVerified(bool $isVerified): self
  168.     {
  169.         $this->isVerified $isVerified;
  170.         return $this;
  171.     }
  172. }