src/Entity/User.php line 25

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Annotations\Xss\XssAware;
  4. use App\Annotations\Xss\XssProperty;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\DBAL\Types\Types;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Doctrine\ORM\Mapping\OneToOne;
  10. use Firebase\JWT\JWT;
  11. use FOS\UserBundle\Model\User as BaseUser;
  12. use Scheb\TwoFactorBundle\Model\Google\TwoFactorInterface;
  13. use Symfony\Bridge\Doctrine\Validator\Constraints as ORMAsserts;
  14. use Symfony\Component\Validator\Constraints as Assert;
  15. /**
  16.  * @ORM\Entity
  17.  *
  18.  * @XssAware
  19.  */
  20. #[ORMAsserts\UniqueEntity('email'message'admin.email_invalid_value')]
  21. #[ORMAsserts\UniqueEntity('username'message'admin.username_invalid_value')]
  22. class User extends BaseUser implements TwoFactorInterface
  23. {
  24.     use BaseTrait;
  25.     /**
  26.      * @ORM\Id
  27.      * @ORM\Column(type="integer")
  28.      * @ORM\GeneratedValue(strategy="AUTO")
  29.      */
  30.     protected $id;
  31.     /**
  32.      * @var string
  33.      * @XssProperty
  34.      */
  35.     protected $username;
  36.     /**
  37.      * Plain password. Used for model validation. Must not be persisted.
  38.      *
  39.      * @var string
  40.      */
  41.     #[Assert\Length(min8max200minMessage'Your password must be at least {{ limit }} characters long.'maxMessage'Your password cannot be longer than {{ limit }} characters.')]
  42.     #[Assert\NotCompromisedPassword(message'This password has previously appeared in a data breach. Please choose a more secure alternative.')]
  43.     #[Assert\NotEqualTo(propertyPath'username'message'Your password should not be the same as your username.')]
  44.     protected $plainPassword;
  45.     /**
  46.      * One User has Many Blogs.
  47.      *
  48.      * @var Blog[]|ArrayCollection
  49.      *
  50.      * @ORM\OneToMany(targetEntity="Blog", mappedBy="owner")
  51.      */
  52.     private $blogs;
  53.     /**
  54.      * Many Users has Many Companies.
  55.      *
  56.      * @var Company[]|ArrayCollection
  57.      *
  58.      * @ORM\ManyToMany(targetEntity="Company", inversedBy="users")
  59.      * @ORM\JoinTable(name="user_company")
  60.      */
  61.     private $companies;
  62.     /**
  63.      * One User has Many ApplicantLogs.
  64.      *
  65.      * @var ApplicantLog[]|ArrayCollection
  66.      *
  67.      * @ORM\OneToMany(targetEntity="ApplicantLog", mappedBy="owner")
  68.      */
  69.     private $applicantLogs;
  70.     /**
  71.      * @ORM\Column(name="azure_id", type="string", length=255, nullable=true)
  72.      */
  73.     protected string $azureId;
  74.     /**
  75.      * @ORM\Column(name="azure_access_token", type="text", nullable=true)
  76.      */
  77.     protected string $azureAccessToken;
  78.     /**
  79.      * @ORM\Column(name="google_id", type="string", length=255, nullable=true)
  80.      */
  81.     protected string $googleId;
  82.     /**
  83.      * @ORM\Column(name="google_access_token", type="string", length=255, nullable=true)
  84.      */
  85.     protected string $googleAccessToken;
  86.     /**
  87.      * @ORM\Column(name="getnoticed_google_id", type="string", length=255, nullable=true)
  88.      */
  89.     protected string $getnoticedGoogleId;
  90.     /**
  91.      * @ORM\Column(name="getnoticed_google_access_token", type="string", length=255, nullable=true)
  92.      */
  93.     protected string $getnoticedGoogleAccessToken;
  94.     /**
  95.      * @ORM\Column(name="pingfederate_id", type=Types::STRING, length=255, nullable=true)
  96.      */
  97.     protected string $pingfederateId;
  98.     /**
  99.      * @ORM\Column(name="pingfederate_access_token", type=Types::TEXT, nullable=true)
  100.      */
  101.     protected string $pingfederateAccessToken;
  102.     /**
  103.      * @ORM\Column(type="string", length=8, nullable=true)
  104.      */
  105.     private $locale;
  106.     /**
  107.      * @var Collection<int, UserRole>
  108.      *
  109.      * @ORM\ManyToMany(targetEntity=UserRole::class, inversedBy="users")
  110.      */
  111.     private Collection $userRoles;
  112.     /**
  113.      * @ORM\Column(name="googleAuthenticatorSecret", type="string", nullable=true)
  114.      */
  115.     private $googleAuthenticatorSecret;
  116.     /**
  117.      * @ORM\Column(name="city", type=Types::STRING, nullable=true)
  118.      */
  119.     private ?string $city null;
  120.     /**
  121.      * @ORM\Column(name="first_name", type=Types::STRING, nullable=true)
  122.      */
  123.     private ?string $firstName null;
  124.     /**
  125.      * @ORM\Column(name="last_name", type=Types::STRING, nullable=true)
  126.      */
  127.     private ?string $lastName null;
  128.     /**
  129.      * @OneToOne(targetEntity="App\Entity\SiteUserData", mappedBy="user")
  130.      */
  131.     private SiteUserData $userProfile;
  132.     public function __construct()
  133.     {
  134.         parent::__construct();
  135.         $this->blogs = new ArrayCollection();
  136.         $this->companies = new ArrayCollection();
  137.         $this->applicantLogs = new ArrayCollection();
  138.         $this->userRoles = new ArrayCollection();
  139.     }
  140.     /**
  141.      * @return Collection|Blog[]
  142.      */
  143.     public function getBlogs(): Collection
  144.     {
  145.         return $this->blogs;
  146.     }
  147.     public function addBlog(Blog $blog): self
  148.     {
  149.         if (!$this->blogs->contains($blog)) {
  150.             $this->blogs[] = $blog;
  151.             $blog->setOwner($this);
  152.         }
  153.         return $this;
  154.     }
  155.     public function removeBlog(Blog $blog): self
  156.     {
  157.         if ($this->blogs->contains($blog)) {
  158.             $this->blogs->removeElement($blog);
  159.             // set the owning side to null (unless already changed)
  160.             if ($blog->getOwner() === $this) {
  161.                 $blog->setOwner(null);
  162.             }
  163.         }
  164.         return $this;
  165.     }
  166.     /**
  167.      * @return Collection|Company[]
  168.      */
  169.     public function getCompanies(): Collection
  170.     {
  171.         return $this->companies;
  172.     }
  173.     public function getCompany(): ?Company
  174.     {
  175.         if ($this->getCompanies()->isEmpty()) {
  176.             return null;
  177.         }
  178.         return $this->getCompanies()->first();
  179.     }
  180.     public function addCompany(Company $company): self
  181.     {
  182.         if (!$this->companies->contains($company)) {
  183.             $this->companies[] = $company;
  184.         }
  185.         return $this;
  186.     }
  187.     public function removeCompany(Company $company): self
  188.     {
  189.         if ($this->companies->contains($company)) {
  190.             $this->companies->removeElement($company);
  191.         }
  192.         return $this;
  193.     }
  194.     /**
  195.      * @return Collection|ApplicantLog[]
  196.      */
  197.     public function getApplicantLogs(): Collection
  198.     {
  199.         return $this->applicantLogs;
  200.     }
  201.     public function addApplicantLog(ApplicantLog $applicantLog): self
  202.     {
  203.         if (!$this->applicantLogs->contains($applicantLog)) {
  204.             $this->applicantLogs[] = $applicantLog;
  205.             $applicantLog->setOwner($this);
  206.         }
  207.         return $this;
  208.     }
  209.     public function removeApplicantLog(ApplicantLog $applicantLog): self
  210.     {
  211.         if ($this->applicantLogs->contains($applicantLog)) {
  212.             $this->applicantLogs->removeElement($applicantLog);
  213.             // set the owning side to null (unless already changed)
  214.             if ($applicantLog->getOwner() === $this) {
  215.                 $applicantLog->setOwner(null);
  216.             }
  217.         }
  218.         return $this;
  219.     }
  220.     public function getJwtToken(): string
  221.     {
  222.         return JWT::urlsafeB64Encode(json_encode(
  223.             [
  224.                 'username' => $this->getUsername(),
  225.                 'roles' => $this->getRoles(),
  226.             ]
  227.         ));
  228.     }
  229.     public function getAzureId(): string
  230.     {
  231.         return $this->azureId;
  232.     }
  233.     public function setAzureId(string $azureId): self
  234.     {
  235.         $this->azureId $azureId;
  236.         return $this;
  237.     }
  238.     public function getAzureAccessToken(): string
  239.     {
  240.         return $this->azureAccessToken;
  241.     }
  242.     public function setAzureAccessToken(string $azureAccessToken): self
  243.     {
  244.         $this->azureAccessToken $azureAccessToken;
  245.         return $this;
  246.     }
  247.     public function getGoogleId(): string
  248.     {
  249.         return $this->googleId;
  250.     }
  251.     public function setGoogleId(string $googleId): self
  252.     {
  253.         $this->googleId $googleId;
  254.         return $this;
  255.     }
  256.     public function getGoogleAccessToken(): string
  257.     {
  258.         return $this->googleAccessToken;
  259.     }
  260.     public function setGoogleAccessToken(string $googleAccessToken): self
  261.     {
  262.         $this->googleAccessToken $googleAccessToken;
  263.         return $this;
  264.     }
  265.     public function getGetnoticedGoogleId(): string
  266.     {
  267.         return $this->getnoticedGoogleId;
  268.     }
  269.     public function setGetnoticedGoogleId(string $getnoticedGoogleId): self
  270.     {
  271.         $this->getnoticedGoogleId $getnoticedGoogleId;
  272.         return $this;
  273.     }
  274.     public function getGetnoticedGoogleAccessToken(): string
  275.     {
  276.         return $this->getnoticedGoogleAccessToken;
  277.     }
  278.     public function setGetnoticedGoogleAccessToken(string $getnoticedGoogleAccessToken): self
  279.     {
  280.         $this->getnoticedGoogleAccessToken $getnoticedGoogleAccessToken;
  281.         return $this;
  282.     }
  283.     public function getPingfederateId(): string
  284.     {
  285.         return $this->pingfederateId;
  286.     }
  287.     public function setPingfederateId(string $PingfederateId): self
  288.     {
  289.         $this->pingfederateId $PingfederateId;
  290.         return $this;
  291.     }
  292.     public function getPingfederateAccessToken(): string
  293.     {
  294.         return $this->pingfederateAccessToken;
  295.     }
  296.     public function setPingfederateAccessToken(string $PingfederateAccessToken): self
  297.     {
  298.         $this->pingfederateAccessToken $PingfederateAccessToken;
  299.         return $this;
  300.     }
  301.     public function getLocale(): ?string
  302.     {
  303.         return $this->locale;
  304.     }
  305.     public function setLocale(?string $locale): self
  306.     {
  307.         $this->locale $locale;
  308.         return $this;
  309.     }
  310.     /**
  311.      * @return Collection<int, UserRole>
  312.      */
  313.     public function getUserRoles(): Collection
  314.     {
  315.         return $this->userRoles;
  316.     }
  317.     public function addUserRole(UserRole $userRole): self
  318.     {
  319.         if (!$this->userRoles->contains($userRole)) {
  320.             $this->userRoles[] = $userRole;
  321.         }
  322.         return $this;
  323.     }
  324.     public function removeUserRole(UserRole $userRole): self
  325.     {
  326.         $this->userRoles->removeElement($userRole);
  327.         return $this;
  328.     }
  329.     public function isGoogleAuthenticatorEnabled(): bool
  330.     {
  331.         return (bool) $this->googleAuthenticatorSecret;
  332.     }
  333.     public function getGoogleAuthenticatorUsername(): string
  334.     {
  335.         return $this->username;
  336.     }
  337.     public function getGoogleAuthenticatorSecret(): ?string
  338.     {
  339.         return $this->googleAuthenticatorSecret;
  340.     }
  341.     public function setGoogleAuthenticatorSecret(?string $googleAuthenticatorSecret): void
  342.     {
  343.         $this->googleAuthenticatorSecret $googleAuthenticatorSecret;
  344.     }
  345.     public function getCity(): ?string
  346.     {
  347.         return $this->city;
  348.     }
  349.     public function setCity(?string $city): self
  350.     {
  351.         $this->city $city;
  352.         return $this;
  353.     }
  354.     public function getFirstName(): ?string
  355.     {
  356.         return $this->firstName;
  357.     }
  358.     public function setFirstName(?string $firstName): self
  359.     {
  360.         $this->firstName $firstName;
  361.         return $this;
  362.     }
  363.     public function getLastName(): ?string
  364.     {
  365.         return $this->lastName;
  366.     }
  367.     public function setLastName(?string $lastName): self
  368.     {
  369.         $this->lastName $lastName;
  370.         return $this;
  371.     }
  372.     public function getUserProfile(): SiteUserData
  373.     {
  374.         return $this->userProfile;
  375.     }
  376.     public function setUserProfile(SiteUserData $userProfile): void
  377.     {
  378.         $this->userProfile $userProfile;
  379.     }
  380. }