src/Entity/User.php line 24

  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use App\Repository\UserRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Exception;
  9. use Scheb\TwoFactorBundle\Model\Totp\TotpConfigurationInterface;
  10. use Scheb\TwoFactorBundle\Model\Totp\TwoFactorInterface;
  11. use Scheb\TwoFactorBundle\Model\Totp\TotpConfiguration;
  12. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  13. use Symfony\Component\Security\Core\User\UserInterface;
  14. use Symfony\Component\Validator\Constraints as Assert;
  15. use Symfony\Component\Validator\Mapping\ClassMetadata;
  16. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  17. #[ORM\Entity(repositoryClassUserRepository::class)]
  18. #[UniqueEntity(fields: ['email'], message'There is already an account with this email')]
  19. #[UniqueEntity(fields: ['uuid'], message'There is already an account with this ID')]
  20. class User implements UserInterfacePasswordAuthenticatedUserInterfaceTwoFactorInterface
  21. {
  22.     public static function loadValidatorMetadata(ClassMetadata $metadata): void
  23.     {
  24.         $metadata->addPropertyConstraint('rawPassword', new Assert\NotCompromisedPassword());
  25.     }
  26.     private string $rawPassword;
  27.     /**
  28.      * @return string
  29.      */
  30.     public function getRawPassword():string
  31.     {
  32.         return $this->rawPassword;
  33.     }
  34.     public function setRawPassword($rawPassword):self
  35.     {
  36.         $this->rawPassword $rawPassword;
  37.         return $this;
  38.     }
  39.     #[ORM\Id]
  40.     #[ORM\GeneratedValue]
  41.     #[ORM\Column]
  42.     protected ?int $id null;
  43.     #[ORM\OneToOne(inversedBy"user"targetEntityUserDetails::class, cascade: ["persist""remove"])]
  44.     #[ORM\JoinColumn(name"userdetails"nullablefalse)]
  45.     protected ?UserDetails $userdetails;
  46.     #[ORM\OneToOne(inversedBy"user"targetEntityUserRegister::class, cascade: ["persist""remove"])]
  47.     #[ORM\JoinColumn(name"register"nullabletrue)]
  48.     protected ?UserRegister $register;
  49.     #[ORM\OneToOne(inversedBy"user"targetEntityUserDashboard::class, cascade: ["persist""remove"])]
  50.     #[ORM\JoinColumn(name"dashboard"nullabletrue)]
  51.     protected ?UserDashboard $dashboard;
  52.     #[ORM\OneToOne(inversedBy"user"targetEntityUserStudio::class, cascade: ["persist""remove"])]
  53.     #[ORM\JoinColumn(name"userStudio"nullabletrue)]
  54.     protected ?UserStudio $userStudio;
  55.     #[ORM\OneToOne(mappedBy'user'targetEntityFranchiseNehmer::class)]
  56.     protected FranchiseNehmer $franchise;
  57.     #[ORM\Column(type"string",length255nullabletrue)]
  58.     private ?string $totpSecret null;
  59.     #[ORM\Column(length180uniquetrue)]
  60.     private ?string $email null;
  61.     #[ORM\Column]
  62.     private array $roles = [];
  63.     /**
  64.      * @var ?string The hashed password
  65.      */
  66.     #[ORM\Column]
  67.     private ?string $password null;
  68.     #[ORM\Column(length36,uniquetrue)]
  69.     private ?string $uuid;
  70.     #[ORM\Column(length255nullabletrue)]
  71.     private ?string $locale null;
  72.     #[ORM\OneToMany(mappedBy'user'targetEntityOAuth2UserConsent::class, orphanRemovaltrue)]
  73.     private Collection $oAuth2UserConsents;
  74.     /**
  75.      * @throws Exception
  76.      */
  77.     public function __construct()
  78.     {
  79.         $this->oAuth2UserConsents = new ArrayCollection();
  80.     }
  81.     public function getId(): ?int
  82.     {
  83.         return $this->id;
  84.     }
  85.     public function getEmail(): ?string
  86.     {
  87.         return $this->email;
  88.     }
  89.     public function setEmail(string $email): self
  90.     {
  91.         $this->email $email;
  92.         return $this;
  93.     }
  94.     public function getSalt(): ?string
  95.     {
  96.         return null;
  97.     }
  98.     /**
  99.      * A visual identifier that represents this user.
  100.      *
  101.      * @see UserInterface
  102.      */
  103.     public function getUserIdentifier(): string
  104.     {
  105.         //  return $this->email;
  106.         return $this->uuid;
  107.     }
  108.     /**
  109.      * @see UserInterface
  110.      */
  111.     public function getRoles(): array
  112.     {
  113.         $roles $this->roles;
  114.         // guarantee every user at least has ROLE_USER
  115.         $roles[] = 'ROLE_USER';
  116.         return array_unique($roles);
  117.     }
  118.     public function setRoles(array $roles): self
  119.     {
  120.         $this->roles $roles;
  121.         return $this;
  122.     }
  123.     /**
  124.      * @see PasswordAuthenticatedUserInterface
  125.      */
  126.     public function getPassword(): string
  127.     {
  128.         return $this->password;
  129.     }
  130.     public function setPassword(string $password): self
  131.     {
  132.         $this->password $password;
  133.         return $this;
  134.     }
  135.     /**
  136.      * @see UserInterface
  137.      */
  138.     public function eraseCredentials()
  139.     {
  140.         // If you store any temporary, sensitive data on the user, clear it here
  141.         // $this->plainPassword = null;
  142.     }
  143.     /*  public function __toString()
  144.       {
  145.           $format = "User (id: %d,email: %s, role: %s, information: %s)\n";
  146.           return sprintf($format, $this->id, $this->email, $this->roles, $this->information);
  147.       }*/
  148.     public function getUserdetails(): ?UserDetails
  149.     {
  150.         return $this->userdetails;
  151.     }
  152.     public function setUserdetails(UserDetails $userdetails): self
  153.     {
  154.         $this->userdetails $userdetails;
  155.         return $this;
  156.     }
  157.     public function getLocale(): ?string
  158.     {
  159.         return $this->locale;
  160.     }
  161.     public function setLocale(string $locale): self
  162.     {
  163.         $this->locale $locale;
  164.         return $this;
  165.     }
  166.     public function getRegister(): ?UserRegister
  167.     {
  168.         return $this->register;
  169.     }
  170.     public function setRegister(?UserRegister $register): self
  171.     {
  172.         $this->register $register;
  173.         return $this;
  174.     }
  175.     /**
  176.      * @return Collection<int, OAuth2UserConsent>
  177.      */
  178.     public function getOAuth2UserConsents(): Collection
  179.     {
  180.         return $this->oAuth2UserConsents;
  181.     }
  182.     public function addOAuth2UserConsent(OAuth2UserConsent $oAuth2UserConsent): self
  183.     {
  184.         if (!$this->oAuth2UserConsents->contains($oAuth2UserConsent)) {
  185.             $this->oAuth2UserConsents->add($oAuth2UserConsent);
  186.             $oAuth2UserConsent->setUser($this);
  187.         }
  188.         return $this;
  189.     }
  190.     public function removeOAuth2UserConsent(OAuth2UserConsent $oAuth2UserConsent): self
  191.     {
  192.         if ($this->oAuth2UserConsents->removeElement($oAuth2UserConsent)) {
  193.             // set the owning side to null (unless already changed)
  194.             if ($oAuth2UserConsent->getUser() === $this) {
  195.                 $oAuth2UserConsent->setUser(null);
  196.             }
  197.         }
  198.         return $this;
  199.     }
  200.     public function getUuid(): ?string
  201.     {
  202.         return $this->uuid;
  203.     }
  204.     public function setUuid(string $uuid): self
  205.     {
  206.         $this->uuid $uuid;
  207.         return $this;
  208.     }
  209.     public function isTotpAuthenticationEnabled(): bool
  210.     {
  211.         return (bool)$this->totpSecret;
  212.     }
  213.     public function getTotpAuthenticationUsername(): string
  214.     {
  215.         return $this->getUserIdentifier();
  216.     }
  217.     public function getTotpAuthenticationConfiguration(): ?TotpConfigurationInterface
  218.     {
  219.         return new TotpConfiguration($this->totpSecretTotpConfiguration::ALGORITHM_SHA1306);
  220.     }
  221.     public function getTotpSecret(): string
  222.     {
  223.         return $this->totpSecret ?? '';
  224.     }
  225.     public function setTotpSecret(?string $totpSecret): self
  226.     {
  227.         $this->totpSecret $totpSecret;
  228.         return $this;
  229.     }
  230.     public function getFranchise(): ?FranchiseNehmer
  231.     {
  232.         return $this->franchise;
  233.     }
  234.     public function setFranchise(?FranchiseNehmer $franchise): self
  235.     {
  236.         // unset the owning side of the relation if necessary
  237.         if ($franchise === null && $this->franchise !== null) {
  238.             $this->franchise->setUser(null);
  239.         }
  240.         // set the owning side of the relation if necessary
  241.         if ($franchise !== null && $franchise->getUser() !== $this) {
  242.             $franchise->setUser($this);
  243.         }
  244.         $this->franchise $franchise;
  245.         return $this;
  246.     }
  247.     public function getDashboard(): ?UserDashboard
  248.     {
  249.         return $this->dashboard;
  250.     }
  251.     public function setDashboard(?UserDashboard $dashboard): self
  252.     {
  253.         $this->dashboard $dashboard;
  254.         return $this;
  255.     }
  256.     public function getUserStudio(): ?UserStudio
  257.     {
  258.         return $this->userStudio;
  259.     }
  260.     public function setUserStudio(?UserStudio $userStudio): self
  261.     {
  262.         $this->userStudio $userStudio;
  263.         return $this;
  264.     }
  265. }