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={"username"}, message="There is already an account with this username")
  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 $username;
  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="string", length=255)
  35.      */
  36.     private $user;
  37.     /**
  38.      * @ORM\Column(type="datetime")
  39.      */
  40.     private $modified;
  41.     /**
  42.      * @ORM\Column(type="datetime")
  43.      */
  44.     private $created;
  45.     /**
  46.      * @ORM\OneToOne(targetEntity=Users::class, mappedBy="user", cascade={"persist", "remove"})
  47.      */
  48.     private $users;
  49.     /**
  50.      * @ORM\Column(type="boolean")
  51.      */
  52.     private $isVerified false;
  53.     /**
  54.      * @ORM\Column(type="string", length=255, nullable=true)
  55.      */
  56.     private $plainPassword;
  57.     public function __construct() {
  58.         $this->setCreated(new \DateTime());
  59.         if ($this->getModified() == null) {
  60.             $this->setModified(new \DateTime());
  61.         }
  62.     }
  63.     public function getId(): ?int
  64.     {
  65.         return $this->id;
  66.     }
  67.     /**
  68.      * @deprecated since Symfony 5.3, use getUserIdentifier instead
  69.      */
  70.     public function getUsername(): string
  71.     {
  72.         return (string) $this->username;
  73.     }
  74.     public function setUsername(string $username): self
  75.     {
  76.         $this->username $username;
  77.         return $this;
  78.     }
  79.     /**
  80.      * A visual identifier that represents this user.
  81.      *
  82.      * @see UserInterface
  83.      */
  84.     public function getUserIdentifier(): string
  85.     {
  86.         return (string) $this->username;
  87.     }
  88.     /**
  89.      * @see UserInterface
  90.      */
  91.     public function getRoles(): array
  92.     {
  93.         $roles $this->roles;
  94.         // guarantee every user at least has ROLE_USER
  95.         $roles[] = 'ROLE_USER';
  96.         return array_unique($roles);
  97.     }
  98.     public function setRoles(array $roles): self
  99.     {
  100.         $this->roles $roles;
  101.         return $this;
  102.     }
  103.     /**
  104.      * @see PasswordAuthenticatedUserInterface
  105.      */
  106.     public function getPassword(): string
  107.     {
  108.         return $this->password;
  109.     }
  110.     public function setPassword(string $password): self
  111.     {
  112.         $this->password $password;
  113.         return $this;
  114.     }
  115.     /**
  116.      * Returning a salt is only needed, if you are not using a modern
  117.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  118.      *
  119.      * @see UserInterface
  120.      */
  121.     public function getSalt(): ?string
  122.     {
  123.         return null;
  124.     }
  125.     /**
  126.      * @see UserInterface
  127.      */
  128.     public function eraseCredentials()
  129.     {
  130.         // If you store any temporary, sensitive data on the user, clear it here
  131.         // $this->plainPassword = null;
  132.     }
  133.     public function getUser(): ?string
  134.     {
  135.         return $this->user;
  136.     }
  137.     public function setUser(string $user): self
  138.     {
  139.         $this->user $user;
  140.         return $this;
  141.     }
  142.     public function getModified(): ?\DateTimeInterface
  143.     {
  144.         return $this->modified;
  145.     }
  146.     public function setModified(\DateTimeInterface $modified): self
  147.     {
  148.         $this->modified $modified;
  149.         return $this;
  150.     }
  151.     public function getCreated(): ?\DateTimeInterface
  152.     {
  153.         return $this->created;
  154.     }
  155.     public function setCreated(\DateTimeInterface $created): self
  156.     {
  157.         $this->created $created;
  158.         return $this;
  159.     }
  160.     public function getUsers(): ?Users
  161.     {
  162.         return $this->users;
  163.     }
  164.     public function setUsers(?Users $users): self
  165.     {
  166.         // unset the owning side of the relation if necessary
  167.         if ($users === null && $this->users !== null) {
  168.             $this->users->setUser(null);
  169.         }
  170.         // set the owning side of the relation if necessary
  171.         if ($users !== null && $users->getUser() !== $this) {
  172.             $users->setUser($this);
  173.         }
  174.         $this->users $users;
  175.         return $this;
  176.     }
  177.     public function isVerified(): bool
  178.     {
  179.         return $this->isVerified;
  180.     }
  181.     public function setIsVerified(bool $isVerified): self
  182.     {
  183.         $this->isVerified $isVerified;
  184.         return $this;
  185.     }
  186.     public function getPlainPassword(): ?string
  187.     {
  188.         return $this->plainPassword;
  189.     }
  190.     public function setPlainPassword(?string $plainPassword): self
  191.     {
  192.         $this->plainPassword $plainPassword;
  193.         return $this;
  194.     }
  195. }