src/Entity/User.php line 17

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\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  8. use Symfony\Component\Security\Core\User\UserInterface;
  9. use Scheb\TwoFactorBundle\Model\Google\TwoFactorInterface;
  10. /**
  11.  * @ORM\Entity(repositoryClass="App\Repository\UserRepository")
  12.  * @ORM\Table(name="users", indexes={@ORM\Index(name="id_index", columns={"id"})})
  13.  */
  14. class User implements UserInterfaceTwoFactorInterface
  15. {
  16.     /**
  17.      * @ORM\Id
  18.      * @ORM\GeneratedValue(strategy="AUTO")
  19.      * @ORM\Column(type="integer")
  20.      */
  21.     private $id;
  22.     /**
  23.      * @ORM\Column(type="string", length=100, nullable=false)
  24.      */
  25.     private $first_name;
  26.     /**
  27.      * @ORM\Column(type="string", length=100, nullable=false)
  28.      */
  29.     private $last_name;
  30.     /**
  31.      * @ORM\Column(type="string", unique=true, length=320, nullable=false)
  32.      */
  33.     private $email;
  34.     /**
  35.      * @ORM\Column(type="integer", nullable=true)
  36.      */
  37.     private $login_number;
  38.     /**
  39.      * @ORM\Column(type="datetime", nullable=true)
  40.      */
  41.     private $last_activity_at;
  42.     /**
  43.      * @ORM\Column(type="integer", nullable=true)
  44.      */
  45.     private $wrong_login_number;
  46.     /**
  47.      * @ORM\Column(type="boolean", nullable=false)
  48.      */
  49.     private $status;
  50.     /**
  51.      * @ORM\OneToMany(targetEntity="App\Entity\Setting", mappedBy="user")
  52.      */
  53.     private $settings;
  54.     /**
  55.      * @ORM\OneToMany(targetEntity="App\Entity\UserCustomer", mappedBy="user")
  56.      */
  57.     private $userCustomers;
  58.     /**
  59.      * @ORM\Column(type="json", nullable=false)
  60.      */
  61.     private $roles = [];
  62.     /**
  63.      * @var
  64.      * @ORM\Column(type="string", length=255, nullable=false) string The hashed password
  65.      */
  66.     private $password;
  67.     /**
  68.      * @ORM\Column(name="authCode", type="string", nullable=true)
  69.      */
  70.     private $authCode;
  71.     /**
  72.      * @ORM\Column(name="googleAuthenticatorSecret", type="string", nullable=true)
  73.      */
  74.     private $googleAuthenticatorSecret;
  75.     /**
  76.      * @ORM\OneToMany(targetEntity="App\Entity\CheckNuked", mappedBy="user")
  77.      */
  78.     private $checkNukeds;
  79.     /**
  80.      * @ORM\OneToMany(targetEntity="App\Entity\Ticket", mappedBy="user")
  81.      */
  82.     private $tickets;
  83.     /**
  84.      * @ORM\OneToMany(targetEntity="App\Entity\TicketReply", mappedBy="user")
  85.      */
  86.     private $ticketReplies;
  87.     /**
  88.      * @ORM\OneToMany(targetEntity="App\Entity\UserProfile", mappedBy="user")
  89.      */
  90.     private $userProfiles;
  91.     /**
  92.      * @ORM\ManyToOne(targetEntity="App\Entity\Language", inversedBy="users")
  93.      * @ORM\JoinColumn(name="language_id", referencedColumnName="id", nullable=false)
  94.      */
  95.     private $language;
  96.     public function __construct()
  97.     {
  98.         $this->settings = new ArrayCollection();
  99.         $this->userCustomers = new ArrayCollection();
  100.         $this->checkNukeds = new ArrayCollection();
  101.     }
  102.     public function getId(): ?int
  103.     {
  104.         return $this->id;
  105.     }
  106.     public function getEmail(): ?string
  107.     {
  108.         return $this->email;
  109.     }
  110.     public function setEmail(string $email): self
  111.     {
  112.         $this->email $email;
  113.         return $this;
  114.     }
  115.     /**
  116.      * A visual identifier that represents this user.
  117.      *
  118.      * @see UserInterface
  119.      */
  120.     public function getUserIdentifier(): string
  121.     {
  122.         return (string) $this->email;
  123.     }
  124.     /**
  125.      * @deprecated since Symfony 5.3, use getUserIdentifier instead
  126.      */
  127.     public function getUsername(): string
  128.     {
  129.         return (string) $this->email;
  130.     }
  131.     /**
  132.      * @see UserInterface
  133.      */
  134.     public function getRoles(): array
  135.     {
  136.         foreach ($this->getUserProfiles() as $user_profile) {
  137.             if ($user_profile->getProfile()->getStatus() === true) {
  138.                 foreach ($user_profile->getProfile()->getRoles() as $role) {
  139.                     $roles[] = $role;
  140.                 }
  141.             }
  142.         }
  143.         $roles[] = 'ROLE_USER';
  144.         return array_unique($roles);
  145.         /*$roles = $this->roles;
  146.         // guarantee every user at least has ROLE_USER
  147.         $roles[] = 'ROLE_USER';
  148.         return array_unique($roles);*/
  149.     }
  150.     public function setRoles(array $roles): self
  151.     {
  152.         $this->roles $roles;
  153.         return $this;
  154.     }
  155.     /**
  156.      * @see PasswordAuthenticatedUserInterface
  157.      */
  158.     public function getPassword(): string
  159.     {
  160.         return $this->password;
  161.     }
  162.     public function setPassword(string $password): self
  163.     {
  164.         $this->password $password;
  165.         return $this;
  166.     }
  167.     /**
  168.      * Returning a salt is only needed, if you are not using a modern
  169.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  170.      *
  171.      * @see UserInterface
  172.      */
  173.     public function getSalt(): ?string
  174.     {
  175.         return null;
  176.     }
  177.     /**
  178.      * @see UserInterface
  179.      */
  180.     public function eraseCredentials()
  181.     {
  182.         // If you store any temporary, sensitive data on the user, clear it here
  183.         // $this->plainPassword = null;
  184.     }
  185.     public function getFirstName(): ?string
  186.     {
  187.         return $this->first_name;
  188.     }
  189.     public function setFirstName(string $first_name): self
  190.     {
  191.         $this->first_name $first_name;
  192.         return $this;
  193.     }
  194.     public function getLastName(): ?string
  195.     {
  196.         return $this->last_name;
  197.     }
  198.     public function setLastName(string $last_name): self
  199.     {
  200.         $this->last_name $last_name;
  201.         return $this;
  202.     }
  203.     public function getCreatedAt(): ?\DateTimeInterface
  204.     {
  205.         return $this->created_at;
  206.     }
  207.     public function setCreatedAt(\DateTimeInterface $created_at): self
  208.     {
  209.         $this->created_at $created_at;
  210.         return $this;
  211.     }
  212.     public function getUpdatedAt(): ?\DateTimeInterface
  213.     {
  214.         return $this->updated_at;
  215.     }
  216.     public function setUpdatedAt(?\DateTimeInterface $updated_at): self
  217.     {
  218.         $this->updated_at $updated_at;
  219.         return $this;
  220.     }
  221.     public function getStatus(): ?bool
  222.     {
  223.         return $this->status;
  224.     }
  225.     public function setStatus(bool $status): self
  226.     {
  227.         $this->status $status;
  228.         return $this;
  229.     }
  230.     public function isGoogleAuthenticatorEnabled(): bool
  231.     {
  232.         return null !== $this->googleAuthenticatorSecret;
  233.     }
  234.     public function getGoogleAuthenticatorUsername(): string
  235.     {
  236.         return $this->email;
  237.     }
  238.     public function getGoogleAuthenticatorSecret(): ?string
  239.     {
  240.         return $this->googleAuthenticatorSecret;
  241.     }
  242.     public function setGoogleAuthenticatorSecret(?string $googleAuthenticatorSecret): void
  243.     {
  244.         $this->googleAuthenticatorSecret $googleAuthenticatorSecret;
  245.     }
  246.     public function isEmailAuthEnabled(): bool
  247.     {
  248.         return true// This can be a persisted field to switch email code authentication on/off
  249.     }
  250.     public function getEmailAuthRecipient(): string
  251.     {
  252.         return $this->email;
  253.     }
  254.     public function getEmailAuthCode(): string
  255.     {
  256.         if (null === $this->authCode) {
  257.             throw new \LogicException('The email authentication code was not set');
  258.         }
  259.         return $this->authCode;
  260.     }
  261.     public function setEmailAuthCode(string $authCode): void
  262.     {
  263.         $this->authCode $authCode;
  264.     }
  265.     /**
  266.      * @return Collection|Setting[]
  267.      */
  268.     public function getSettings(): Collection
  269.     {
  270.         return $this->settings;
  271.     }
  272.     public function addSetting(Setting $setting): self
  273.     {
  274.         if (!$this->settings->contains($setting)) {
  275.             $this->settings[] = $setting;
  276.             $setting->setUser($this);
  277.         }
  278.         return $this;
  279.     }
  280.     public function removeSetting(Setting $setting): self
  281.     {
  282.         if ($this->settings->removeElement($setting)) {
  283.             // set the owning side to null (unless already changed)
  284.             if ($setting->getUser() === $this) {
  285.                 $setting->setUser(null);
  286.             }
  287.         }
  288.         return $this;
  289.     }
  290.     /**
  291.      * @return Collection|UserCustomer[]
  292.      */
  293.     public function getUserCustomers(): Collection
  294.     {
  295.         return $this->userCustomers;
  296.     }
  297.     public function addUserCustomer(UserCustomer $userCustomer): self
  298.     {
  299.         if (!$this->userCustomers->contains($userCustomer)) {
  300.             $this->userCustomers[] = $userCustomer;
  301.             $userCustomer->setUser($this);
  302.         }
  303.         return $this;
  304.     }
  305.     public function removeUserCustomer(UserCustomer $userCustomer): self
  306.     {
  307.         if ($this->userCustomers->removeElement($userCustomer)) {
  308.             // set the owning side to null (unless already changed)
  309.             if ($userCustomer->getUser() === $this) {
  310.                 $userCustomer->setUser(null);
  311.             }
  312.         }
  313.         return $this;
  314.     }
  315.     public function getLanguage(): ?Language
  316.     {
  317.         return $this->language;
  318.     }
  319.     public function setLanguage(?Language $language): self
  320.     {
  321.         $this->language $language;
  322.         return $this;
  323.     }
  324.     public function getLoginNumber(): ?int
  325.     {
  326.         return $this->login_number;
  327.     }
  328.     public function setLoginNumber(?int $login_number): self
  329.     {
  330.         $this->login_number $login_number;
  331.         return $this;
  332.     }
  333.     public function getLastActivityAt(): ?\DateTimeInterface
  334.     {
  335.         return $this->last_activity_at;
  336.     }
  337.     public function setLastActivityAt(?\DateTimeInterface $last_activity_at): self
  338.     {
  339.         $this->last_activity_at $last_activity_at;
  340.         return $this;
  341.     }
  342.     public function getWrongLoginNumber(): ?int
  343.     {
  344.         return $this->wrong_login_number;
  345.     }
  346.     public function setWrongLoginNumber(?int $wrong_login_number): self
  347.     {
  348.         $this->wrong_login_number $wrong_login_number;
  349.         return $this;
  350.     }
  351.     /**
  352.      * @return Collection|CheckNuked[]
  353.      */
  354.     public function getCheckNukeds(): Collection
  355.     {
  356.         return $this->checkNukeds;
  357.     }
  358.     public function addCheckNuked(CheckNuked $checkNuked): self
  359.     {
  360.         if (!$this->checkNukeds->contains($checkNuked)) {
  361.             $this->checkNukeds[] = $checkNuked;
  362.             $checkNuked->setUser($this);
  363.         }
  364.         return $this;
  365.     }
  366.     public function removeCheckNuked(CheckNuked $checkNuked): self
  367.     {
  368.         if ($this->checkNukeds->removeElement($checkNuked)) {
  369.             // set the owning side to null (unless already changed)
  370.             if ($checkNuked->getUser() === $this) {
  371.                 $checkNuked->setUser(null);
  372.             }
  373.         }
  374.         return $this;
  375.     }
  376.     /**
  377.      * @return Collection<int, UserProfile>
  378.      */
  379.     public function getUserProfiles(): Collection
  380.     {
  381.         return $this->userProfiles;
  382.     }
  383.     public function addUserProfile(UserProfile $userProfile): self
  384.     {
  385.         if (!$this->userProfiles->contains($userProfile)) {
  386.             $this->userProfiles[] = $userProfile;
  387.             $userProfile->setUser($this);
  388.         }
  389.         return $this;
  390.     }
  391.     public function removeUserProfile(UserProfile $userProfile): self
  392.     {
  393.         if ($this->userProfiles->removeElement($userProfile)) {
  394.             // set the owning side to null (unless already changed)
  395.             if ($userProfile->getUser() === $this) {
  396.                 $userProfile->setUser(null);
  397.             }
  398.         }
  399.         return $this;
  400.     }
  401.     public function isActiveNow()
  402.     {
  403.         $delay = new \DateTime('2 minutes ago');
  404.         return ( $this->getLastActivityAt() > $delay );
  405.     }
  406. }