src/Entity/User.php line 25

  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiFilter;
  4. use ApiPlatform\Core\Annotation\ApiResource;
  5. use App\Repository\UserRepository;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  10. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  11. use Symfony\Component\Security\Core\User\UserInterface;
  12. use Symfony\Component\Serializer\Annotation\Groups;
  13. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  14. #[ApiResource(
  15.     normalizationContext: ['groups' => ['read']],
  16.     denormalizationContext: ['groups' => ['write']],
  17. )]
  18. #[ApiFilter(SearchFilter::class, properties: ['username' => 'exact','googleId' => 'exact'])]
  19. #[ORM\Table(name'user')]
  20. #[ORM\Entity(repositoryClassUserRepository::class)]
  21. #[UniqueEntity(fields: ['username'], message'There is already an account with this username')]
  22. class User implements UserInterfacePasswordAuthenticatedUserInterface
  23. {
  24.     #[ORM\Id]
  25.     #[ORM\GeneratedValue]
  26.     #[ORM\Column(type'integer')]
  27.     private $id;
  28.     #[Groups(["read","write"])]
  29.     #[ORM\Column(type'string'length180uniquetrue)]
  30.     private ?string $username null;
  31.     #[Groups(["read","write"])]
  32.     #[ORM\Column(type'json')]
  33.     private array $roles = [];
  34.     #[Groups(["read","write"])]
  35.     #[ORM\Column(type'string')]
  36.     private ?string $password "";
  37.     
  38.     #[ORM\Column(type'boolean'nullabletrue)]
  39.     #[Groups(["read","write"])]
  40.     private ?bool $isValid null;
  41.     #[ORM\Column(type'boolean')]
  42.     #[Groups(["read","write"])]
  43.     private bool $isVerified false;
  44.     #[ORM\ManyToMany(targetEntityRole::class, inversedBy'users')]
  45.     private Collection $storedRoles;
  46.     
  47.     #[Groups(["read","write"])]
  48.     #[ORM\Column(length255nullabletrue)]
  49.     private ?string $exponentPushToken null;
  50.     #[Groups(["read","write"])]
  51.     #[ORM\Column(length255nullabletrue)]
  52.     private ?string $googleId null;
  53.     #[Groups(["read","write"])]
  54.     #[ORM\Column(length255nullabletrue)]
  55.     private ?string $avatar null;
  56.     #[Groups(["read","write"])]
  57.     #[ORM\Column(length255nullabletrue)]
  58.     private ?string $facebookId null;
  59.     #[ORM\OneToMany(mappedBy'user'targetEntityAiRequest::class)]
  60.     private Collection $aiRequests;
  61.     #[ORM\Column(nullabletrue)]
  62.     private ?bool $isAutoConnectUsed null;
  63.     public function __construct()
  64.     {
  65.         $this->storedRoles = new ArrayCollection();
  66.         $this->isValid true;
  67.         $this->aiRequests = new ArrayCollection();
  68.     }
  69.     public function __toString()
  70.     {
  71.         return $this->getUserIdentifier();
  72.     }
  73.     public function getId(): ?int
  74.     {
  75.         return $this->id;
  76.     }
  77.     /**
  78.      * @deprecated since Symfony 5.3, use getUserIdentifier instead
  79.      */
  80.     public function getUsername(): string
  81.     {
  82.         return (string) $this->username;
  83.     }
  84.     public function setUsername(string $username): self
  85.     {
  86.         $this->username $username;
  87.         return $this;
  88.     }
  89.     /**
  90.      * A visual identifier that represents this user.
  91.      *
  92.      * @see UserInterface
  93.      */
  94.     public function getUserIdentifier(): string
  95.     {
  96.         return (string) $this->username;
  97.     }
  98.     /**
  99.      * @see UserInterface
  100.      */
  101.     public function getRoles(): array
  102.     {
  103.         $roles $this->roles;
  104.         // guarantee every user at least has ROLE_USER
  105.         $roles[] = 'ROLE_USER';
  106.         foreach($this->getStoredRoles() as $singleRole){
  107.             $roles[] = $singleRole->getName();
  108.         }
  109.         return array_unique($roles);
  110.     }
  111.     public function setRoles(array $roles): self
  112.     {
  113.         $this->roles $roles;
  114.         return $this;
  115.     }
  116.     /**
  117.      * @see PasswordAuthenticatedUserInterface
  118.      */
  119.     public function getPassword(): string
  120.     {
  121.         return $this->password;
  122.     }
  123.     public function setPassword(string $password): self
  124.     {
  125.         $this->password $password;
  126.         return $this;
  127.     }
  128.     /**
  129.      * Returning a salt is only needed, if you are not using a modern
  130.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  131.      *
  132.      * @see UserInterface
  133.      */
  134.     public function getSalt(): ?string
  135.     {
  136.         return null;
  137.     }
  138.     /**
  139.      * @see UserInterface
  140.      */
  141.     public function eraseCredentials()
  142.     {
  143.         // If you store any temporary, sensitive data on the user, clear it here
  144.         // $this->plainPassword = null;
  145.     }
  146.     public function getIsValid(): ?bool
  147.     {
  148.         return $this->isValid;
  149.     }
  150.     public function setIsValid(?bool $isValid): self
  151.     {
  152.         $this->isValid $isValid;
  153.         return $this;
  154.     }
  155.     public function isVerified(): bool
  156.     {
  157.         return $this->isVerified;
  158.     }
  159.     public function setIsVerified(bool $isVerified): self
  160.     {
  161.         $this->isVerified $isVerified;
  162.         return $this;
  163.     }
  164.     /**
  165.      * @return Collection<int, Role>
  166.      */
  167.     public function getStoredRoles(): Collection
  168.     {
  169.         return $this->storedRoles;
  170.     }
  171.     public function addStoredRole(Role $storedRole): self
  172.     {
  173.         if (!$this->storedRoles->contains($storedRole)) {
  174.             $this->storedRoles->add($storedRole);
  175.             $storedRole->addUser($this);
  176.         }
  177.         return $this;
  178.     }
  179.     public function removeStoredRole(Role $storedRole): self
  180.     {
  181.         if ($this->storedRoles->removeElement($storedRole)) {
  182.             $storedRole->removeUser($this);
  183.         }
  184.         return $this;
  185.     }
  186.     public function getExponentPushToken(): ?string
  187.     {
  188.         return $this->exponentPushToken;
  189.     }
  190.     public function setExponentPushToken(?string $exponentPushToken): self
  191.     {
  192.         $this->exponentPushToken $exponentPushToken;
  193.         return $this;
  194.     }
  195.     public function getGoogleId(): ?string
  196.     {
  197.         return $this->googleId;
  198.     }
  199.     public function setGoogleId(?string $googleId): self
  200.     {
  201.         $this->googleId $googleId;
  202.         return $this;
  203.     }
  204.     public function getAvatar(): ?string
  205.     {
  206.         return $this->avatar;
  207.     }
  208.     public function setAvatar(?string $avatar): self
  209.     {
  210.         $this->avatar $avatar;
  211.         return $this;
  212.     }
  213.     public function getFacebookId(): ?string
  214.     {
  215.         return $this->facebookId;
  216.     }
  217.     public function setFacebookId(?string $facebookId): self
  218.     {
  219.         $this->facebookId $facebookId;
  220.         return $this;
  221.     }
  222.     /**
  223.      * @return Collection<int, AiRequest>
  224.      */
  225.     public function getAiRequests(): Collection
  226.     {
  227.         return $this->aiRequests;
  228.     }
  229.     public function addAiRequest(AiRequest $aiRequest): static
  230.     {
  231.         if (!$this->aiRequests->contains($aiRequest)) {
  232.             $this->aiRequests->add($aiRequest);
  233.             $aiRequest->setUser($this);
  234.         }
  235.         return $this;
  236.     }
  237.     public function removeAiRequest(AiRequest $aiRequest): static
  238.     {
  239.         if ($this->aiRequests->removeElement($aiRequest)) {
  240.             // set the owning side to null (unless already changed)
  241.             if ($aiRequest->getUser() === $this) {
  242.                 $aiRequest->setUser(null);
  243.             }
  244.         }
  245.         return $this;
  246.     }
  247.     public function isIsAutoConnectUsed(): ?bool
  248.     {
  249.         return $this->isAutoConnectUsed;
  250.     }
  251.     public function setIsAutoConnectUsed(?bool $isAutoConnectUsed): static
  252.     {
  253.         $this->isAutoConnectUsed $isAutoConnectUsed;
  254.         return $this;
  255.     }
  256. }