<?php
namespace App\Entity;
use App\Annotations\Xss\XssAware;
use App\Annotations\Xss\XssProperty;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\Mapping\OneToOne;
use Firebase\JWT\JWT;
use FOS\UserBundle\Model\User as BaseUser;
use Scheb\TwoFactorBundle\Model\Google\TwoFactorInterface;
use Symfony\Bridge\Doctrine\Validator\Constraints as ORMAsserts;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity
*
* @XssAware
*/
#[ORMAsserts\UniqueEntity('email', message: 'admin.email_invalid_value')]
#[ORMAsserts\UniqueEntity('username', message: 'admin.username_invalid_value')]
class User extends BaseUser implements TwoFactorInterface
{
use BaseTrait;
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @var string
* @XssProperty
*/
protected $username;
/**
* Plain password. Used for model validation. Must not be persisted.
*
* @var string
*/
#[Assert\Length(min: 8, max: 200, minMessage: 'Your password must be at least {{ limit }} characters long.', maxMessage: 'Your password cannot be longer than {{ limit }} characters.')]
#[Assert\NotCompromisedPassword(message: 'This password has previously appeared in a data breach. Please choose a more secure alternative.')]
#[Assert\NotEqualTo(propertyPath: 'username', message: 'Your password should not be the same as your username.')]
protected $plainPassword;
/**
* One User has Many Blogs.
*
* @var Blog[]|ArrayCollection
*
* @ORM\OneToMany(targetEntity="Blog", mappedBy="owner")
*/
private $blogs;
/**
* Many Users has Many Companies.
*
* @var Company[]|ArrayCollection
*
* @ORM\ManyToMany(targetEntity="Company", inversedBy="users")
* @ORM\JoinTable(name="user_company")
*/
private $companies;
/**
* One User has Many ApplicantLogs.
*
* @var ApplicantLog[]|ArrayCollection
*
* @ORM\OneToMany(targetEntity="ApplicantLog", mappedBy="owner")
*/
private $applicantLogs;
/**
* @ORM\Column(name="azure_id", type="string", length=255, nullable=true)
*/
protected string $azureId;
/**
* @ORM\Column(name="azure_access_token", type="text", nullable=true)
*/
protected string $azureAccessToken;
/**
* @ORM\Column(name="google_id", type="string", length=255, nullable=true)
*/
protected string $googleId;
/**
* @ORM\Column(name="google_access_token", type="string", length=255, nullable=true)
*/
protected string $googleAccessToken;
/**
* @ORM\Column(name="getnoticed_google_id", type="string", length=255, nullable=true)
*/
protected string $getnoticedGoogleId;
/**
* @ORM\Column(name="getnoticed_google_access_token", type="string", length=255, nullable=true)
*/
protected string $getnoticedGoogleAccessToken;
/**
* @ORM\Column(name="pingfederate_id", type=Types::STRING, length=255, nullable=true)
*/
protected string $pingfederateId;
/**
* @ORM\Column(name="pingfederate_access_token", type=Types::TEXT, nullable=true)
*/
protected string $pingfederateAccessToken;
/**
* @ORM\Column(type="string", length=8, nullable=true)
*/
private $locale;
/**
* @var Collection<int, UserRole>
*
* @ORM\ManyToMany(targetEntity=UserRole::class, inversedBy="users")
*/
private Collection $userRoles;
/**
* @ORM\Column(name="googleAuthenticatorSecret", type="string", nullable=true)
*/
private $googleAuthenticatorSecret;
/**
* @ORM\Column(name="city", type=Types::STRING, nullable=true)
*/
private ?string $city = null;
/**
* @ORM\Column(name="first_name", type=Types::STRING, nullable=true)
*/
private ?string $firstName = null;
/**
* @ORM\Column(name="last_name", type=Types::STRING, nullable=true)
*/
private ?string $lastName = null;
/**
* @OneToOne(targetEntity="App\Entity\SiteUserData", mappedBy="user")
*/
private SiteUserData $userProfile;
public function __construct()
{
parent::__construct();
$this->blogs = new ArrayCollection();
$this->companies = new ArrayCollection();
$this->applicantLogs = new ArrayCollection();
$this->userRoles = new ArrayCollection();
}
/**
* @return Collection|Blog[]
*/
public function getBlogs(): Collection
{
return $this->blogs;
}
public function addBlog(Blog $blog): self
{
if (!$this->blogs->contains($blog)) {
$this->blogs[] = $blog;
$blog->setOwner($this);
}
return $this;
}
public function removeBlog(Blog $blog): self
{
if ($this->blogs->contains($blog)) {
$this->blogs->removeElement($blog);
// set the owning side to null (unless already changed)
if ($blog->getOwner() === $this) {
$blog->setOwner(null);
}
}
return $this;
}
/**
* @return Collection|Company[]
*/
public function getCompanies(): Collection
{
return $this->companies;
}
public function getCompany(): ?Company
{
if ($this->getCompanies()->isEmpty()) {
return null;
}
return $this->getCompanies()->first();
}
public function addCompany(Company $company): self
{
if (!$this->companies->contains($company)) {
$this->companies[] = $company;
}
return $this;
}
public function removeCompany(Company $company): self
{
if ($this->companies->contains($company)) {
$this->companies->removeElement($company);
}
return $this;
}
/**
* @return Collection|ApplicantLog[]
*/
public function getApplicantLogs(): Collection
{
return $this->applicantLogs;
}
public function addApplicantLog(ApplicantLog $applicantLog): self
{
if (!$this->applicantLogs->contains($applicantLog)) {
$this->applicantLogs[] = $applicantLog;
$applicantLog->setOwner($this);
}
return $this;
}
public function removeApplicantLog(ApplicantLog $applicantLog): self
{
if ($this->applicantLogs->contains($applicantLog)) {
$this->applicantLogs->removeElement($applicantLog);
// set the owning side to null (unless already changed)
if ($applicantLog->getOwner() === $this) {
$applicantLog->setOwner(null);
}
}
return $this;
}
public function getJwtToken(): string
{
return JWT::urlsafeB64Encode(json_encode(
[
'username' => $this->getUsername(),
'roles' => $this->getRoles(),
]
));
}
public function getAzureId(): string
{
return $this->azureId;
}
public function setAzureId(string $azureId): self
{
$this->azureId = $azureId;
return $this;
}
public function getAzureAccessToken(): string
{
return $this->azureAccessToken;
}
public function setAzureAccessToken(string $azureAccessToken): self
{
$this->azureAccessToken = $azureAccessToken;
return $this;
}
public function getGoogleId(): string
{
return $this->googleId;
}
public function setGoogleId(string $googleId): self
{
$this->googleId = $googleId;
return $this;
}
public function getGoogleAccessToken(): string
{
return $this->googleAccessToken;
}
public function setGoogleAccessToken(string $googleAccessToken): self
{
$this->googleAccessToken = $googleAccessToken;
return $this;
}
public function getGetnoticedGoogleId(): string
{
return $this->getnoticedGoogleId;
}
public function setGetnoticedGoogleId(string $getnoticedGoogleId): self
{
$this->getnoticedGoogleId = $getnoticedGoogleId;
return $this;
}
public function getGetnoticedGoogleAccessToken(): string
{
return $this->getnoticedGoogleAccessToken;
}
public function setGetnoticedGoogleAccessToken(string $getnoticedGoogleAccessToken): self
{
$this->getnoticedGoogleAccessToken = $getnoticedGoogleAccessToken;
return $this;
}
public function getPingfederateId(): string
{
return $this->pingfederateId;
}
public function setPingfederateId(string $PingfederateId): self
{
$this->pingfederateId = $PingfederateId;
return $this;
}
public function getPingfederateAccessToken(): string
{
return $this->pingfederateAccessToken;
}
public function setPingfederateAccessToken(string $PingfederateAccessToken): self
{
$this->pingfederateAccessToken = $PingfederateAccessToken;
return $this;
}
public function getLocale(): ?string
{
return $this->locale;
}
public function setLocale(?string $locale): self
{
$this->locale = $locale;
return $this;
}
/**
* @return Collection<int, UserRole>
*/
public function getUserRoles(): Collection
{
return $this->userRoles;
}
public function addUserRole(UserRole $userRole): self
{
if (!$this->userRoles->contains($userRole)) {
$this->userRoles[] = $userRole;
}
return $this;
}
public function removeUserRole(UserRole $userRole): self
{
$this->userRoles->removeElement($userRole);
return $this;
}
public function isGoogleAuthenticatorEnabled(): bool
{
return (bool) $this->googleAuthenticatorSecret;
}
public function getGoogleAuthenticatorUsername(): string
{
return $this->username;
}
public function getGoogleAuthenticatorSecret(): ?string
{
return $this->googleAuthenticatorSecret;
}
public function setGoogleAuthenticatorSecret(?string $googleAuthenticatorSecret): void
{
$this->googleAuthenticatorSecret = $googleAuthenticatorSecret;
}
public function getCity(): ?string
{
return $this->city;
}
public function setCity(?string $city): self
{
$this->city = $city;
return $this;
}
public function getFirstName(): ?string
{
return $this->firstName;
}
public function setFirstName(?string $firstName): self
{
$this->firstName = $firstName;
return $this;
}
public function getLastName(): ?string
{
return $this->lastName;
}
public function setLastName(?string $lastName): self
{
$this->lastName = $lastName;
return $this;
}
public function getUserProfile(): SiteUserData
{
return $this->userProfile;
}
public function setUserProfile(SiteUserData $userProfile): void
{
$this->userProfile = $userProfile;
}
}