<?php
namespace App\Entity;
use App\Entity\Company\Person;
use App\Entity\Traits\Creation;
use App\Entity\Traits\Idable;
use App\Repository\UserRepository;
use Doctrine\ORM\Mapping as ORM;
use Scheb\TwoFactorBundle\Model\Email\TwoFactorInterface;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
#[ORM\Entity(repositoryClass: UserRepository::class)]
#[ORM\Table(name: 'users')]
class User implements UserInterface, PasswordAuthenticatedUserInterface, TwoFactorInterface
{
use Idable;
use Creation;
#[ORM\OneToOne(targetEntity: Person::class, mappedBy: 'relatedUser')]
protected $person;
#[ORM\Column(type: 'string', length: 180, unique: true)]
protected $email;
#[ORM\Column(type: 'string', length: 50)]
protected $name;
#[ORM\Column(type: 'string', length: 50)]
protected $surname;
#[ORM\Column(type: 'string', length: 100)]
protected $fullName;
#[ORM\ManyToOne(targetEntity: Company::class, inversedBy: 'users')]
protected $company;
#[ORM\Column(type: 'boolean', nullable: true, options: ['default' => 1])]
protected $isActive;
#[ORM\Column(type: 'json')]
protected $roles = [];
#[ORM\Column(type: 'boolean', nullable: true, options: ['default' => 0])]
protected $isBackOfficeUser;
#[ORM\Column(type: 'string')]
protected $password;
#[ORM\Column(type: 'string', nullable: true)]
protected ?string $authCode;
#[ORM\Column(type: 'boolean', nullable: true, options: ['default' => 1])]
protected $tempPassword;
#[ORM\Column(type: 'string', nullable: true, options: ['default' => null])]
protected $googleAuthId;
#[ORM\Column(type: 'string', nullable: true)]
protected $uid;
#[ORM\Column(type: 'datetime', nullable: true)]
protected $forgotPasswordCreatedTime;
#[ORM\Column(type: 'datetime', nullable: true)]
protected $forgotPasswordUpdatedTime;
/**
* @return mixed
*/
public function getUid()
{
return $this->uid;
}
/**
* @param mixed $uid
*/
public function setUid($uid): void
{
$this->uid = $uid;
}
public function getEmail(): ?string
{
return $this->email;
}
public function getAuthCode(): ?string
{
return $this->authCode;
}
public function setAuthCode(?string $authCode): void
{
$this->authCode = $authCode;
}
/**
* @return mixed
*/
public function getTempPassword()
{
return $this->tempPassword;
}
/**
* @param mixed $tempPassword
*/
public function setTempPassword($tempPassword): void
{
$this->tempPassword = $tempPassword;
}
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}
/**
* A visual identifier that represents this user.
*
* @see UserInterface
*/
public function getUserIdentifier(): string
{
return (string) $this->email;
}
/**
* @deprecated since Symfony 5.3, use getUserIdentifier instead
*/
public function getUsername(): string
{
return (string) $this->email;
}
/**
* @see UserInterface
*/
public function getRoles(): array
{
$roles = $this->roles;
return array_unique($roles);
}
public function setRoles(array $roles): self
{
$this->roles = $roles;
return $this;
}
/**
* @return mixed
*/
public function getIsBackOfficeUser()
{
return $this->isBackOfficeUser;
}
/**
* @param mixed $isBackOfficeUser
*/
public function setIsBackOfficeUser($isBackOfficeUser): void
{
$this->isBackOfficeUser = $isBackOfficeUser;
}
/**
* @see PasswordAuthenticatedUserInterface
*/
public function getPassword(): string
{
return $this->password;
}
public function setPassword(string $password): self
{
$this->password = $password;
return $this;
}
/**
* Returning a salt is only needed, if you are not using a modern
* hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
*
* @see UserInterface
*/
public function getSalt(): ?string
{
return null;
}
/**
* @see UserInterface
*/
public function eraseCredentials()
{
// If you store any temporary, sensitive data on the user, clear it here
// $this->plainPassword = null;
}
/**
* @return mixed
*/
public function getName()
{
return $this->name;
}
/**
* @param mixed $name
*/
public function setName($name): void
{
$this->name = $name;
}
/**
* @return mixed
*/
public function getSurname()
{
return $this->surname;
}
/**
* @param mixed $surname
*/
public function setSurname($surname): void
{
$this->surname = $surname;
}
/**
* @return mixed
*/
public function getFullName()
{
return $this->fullName;
}
/**
* @param mixed $fullName
*/
public function setFullName($fullName): void
{
$this->fullName = $fullName;
}
public function getCompany(): ?Company
{
return $this->company;
}
public function setCompany(?Company $company): self
{
$this->company = $company;
return $this;
}
/**
* @return mixed
*/
public function getIsActive()
{
return $this->isActive;
}
/**
* @param mixed $isActive
*/
public function setIsActive($isActive): void
{
$this->isActive = $isActive;
}
/**
* @return Person
*/
public function getPerson()
{
return $this->person;
}
public function isEmailAuthEnabled(): bool
{
return true; // This can be a persisted field to switch email code authentication on/off
}
public function getEmailAuthRecipient(): string
{
return $this->email;
}
public function getEmailAuthCode(): string
{
if (null === $this->authCode) {
throw new \LogicException('The email authentication code was not set');
}
return $this->authCode;
}
public function setEmailAuthCode(string $authCode): void
{
$this->authCode = $authCode;
}
/**
* @return mixed
*/
public function getGoogleAuthId()
{
return $this->googleAuthId;
}
/**
* @param mixed $googleAuthId
*/
public function setGoogleAuthId($googleAuthId): void
{
$this->googleAuthId = $googleAuthId;
}
/**
* @return mixed
*/
public function getForgotPasswordCreatedTime()
{
return $this->forgotPasswordCreatedTime;
}
/**
* @param mixed $forgotPasswordCreatedTime
*/
public function setForgotPasswordCreatedTime($forgotPasswordCreatedTime): void
{
$this->forgotPasswordCreatedTime = $forgotPasswordCreatedTime;
}
/**
* @return mixed
*/
public function getForgotPasswordUpdatedTime()
{
return $this->forgotPasswordUpdatedTime;
}
/**
* @param mixed $forgotPasswordUpdatedTime
*/
public function setForgotPasswordUpdatedTime($forgotPasswordUpdatedTime): void
{
$this->forgotPasswordUpdatedTime = $forgotPasswordUpdatedTime;
}
}