src/Entity/User.php line 18

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.  * @ORM\Table(name="`user`")
  13.  * @UniqueEntity(fields={"username"}, message="There is already an account with this username")
  14.  */
  15. class User implements UserInterfacePasswordAuthenticatedUserInterface
  16. {
  17.     /**
  18.      * @ORM\Id
  19.      * @ORM\GeneratedValue
  20.      * @ORM\Column(type="integer")
  21.      */
  22.     private $id;
  23.     /**
  24.      * @ORM\Column(type="string", length=180, unique=true)
  25.      */
  26.     private $username;
  27.     /**
  28.      * @ORM\Column(type="string", length=180)
  29.      */
  30.     private $email;
  31.     /**
  32.      * @ORM\Column(type="json")
  33.      */
  34.     private $roles = [];
  35.     /**
  36.      * @var string The hashed password
  37.      * @ORM\Column(type="string")
  38.      */
  39.     private $password;
  40.     /**
  41.      * @ORM\Column(type="boolean")
  42.      */
  43.     private $isVerified false;
  44.     /**
  45.      * @ORM\OneToMany(targetEntity="App\Entity\Channel", mappedBy="user")
  46.      */
  47.     private $channels;
  48.     public function __construct()
  49.     {
  50.         $this->channels = new ArrayCollection();
  51.     }
  52.     public function getId(): ?int
  53.     {
  54.         return $this->id;
  55.     }
  56.     /**
  57.      * @return Collection|Channel[]
  58.      */
  59.     public function getChannels(): Collection
  60.     {
  61.         return $this->channels;
  62.     }
  63.     /**
  64.      * @deprecated since Symfony 5.3, use getUserIdentifier instead
  65.      */
  66.     public function getUsername(): string
  67.     {
  68.         return (string) $this->username;
  69.     }
  70.     public function setUsername(string $username): self
  71.     {
  72.         $this->username $username;
  73.         return $this;
  74.     }
  75.     public function getEmail(): string
  76.     {
  77.         return (string) $this->email;
  78.     }
  79.     public function setEmail(string $email): self
  80.     {
  81.         $this->email $email;
  82.         return $this;
  83.     }
  84.     /**
  85.      * A visual identifier that represents this user.
  86.      *
  87.      * @see UserInterface
  88.      */
  89.     public function getUserIdentifier(): string
  90.     {
  91.         return (string) $this->username;
  92.     }
  93.     /**
  94.      * @see UserInterface
  95.      */
  96.     public function getRoles(): array
  97.     {
  98.         $roles $this->roles;
  99.         // guarantee every user at least has ROLE_USER
  100.         $roles[] = 'ROLE_USER';
  101.         return array_unique($roles);
  102.     }
  103.     public function setRoles(array $roles): self
  104.     {
  105.         $this->roles $roles;
  106.         return $this;
  107.     }
  108.     /**
  109.      * @see PasswordAuthenticatedUserInterface
  110.      */
  111.     public function getPassword(): string
  112.     {
  113.         return $this->password;
  114.     }
  115.     public function setPassword(string $password): self
  116.     {
  117.         $this->password $password;
  118.         return $this;
  119.     }
  120.     /**
  121.      * Returning a salt is only needed, if you are not using a modern
  122.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  123.      *
  124.      * @see UserInterface
  125.      */
  126.     public function getSalt(): ?string
  127.     {
  128.         return null;
  129.     }
  130.     /**
  131.      * @see UserInterface
  132.      */
  133.     public function eraseCredentials()
  134.     {
  135.         // If you store any temporary, sensitive data on the user, clear it here
  136.         // $this->plainPassword = null;
  137.     }
  138.     public function isVerified(): bool
  139.     {
  140.         return $this->isVerified;
  141.     }
  142.     public function setIsVerified(bool $isVerified): self
  143.     {
  144.         $this->isVerified $isVerified;
  145.         return $this;
  146.     }
  147. }