<?php
namespace App\Entity;
use App\Repository\UserRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Scheb\TwoFactorBundle\Model\Google\TwoFactorInterface;
/**
* @ORM\Entity(repositoryClass="App\Repository\UserRepository")
* @ORM\Table(name="users", indexes={@ORM\Index(name="id_index", columns={"id"})})
*/
class User implements UserInterface, TwoFactorInterface
{
/**
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=100, nullable=false)
*/
private $first_name;
/**
* @ORM\Column(type="string", length=100, nullable=false)
*/
private $last_name;
/**
* @ORM\Column(type="string", unique=true, length=320, nullable=false)
*/
private $email;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $login_number;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $last_activity_at;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $wrong_login_number;
/**
* @ORM\Column(type="boolean", nullable=false)
*/
private $status;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Setting", mappedBy="user")
*/
private $settings;
/**
* @ORM\OneToMany(targetEntity="App\Entity\UserCustomer", mappedBy="user")
*/
private $userCustomers;
/**
* @ORM\Column(type="json", nullable=false)
*/
private $roles = [];
/**
* @var
* @ORM\Column(type="string", length=255, nullable=false) string The hashed password
*/
private $password;
/**
* @ORM\Column(name="authCode", type="string", nullable=true)
*/
private $authCode;
/**
* @ORM\Column(name="googleAuthenticatorSecret", type="string", nullable=true)
*/
private $googleAuthenticatorSecret;
/**
* @ORM\OneToMany(targetEntity="App\Entity\CheckNuked", mappedBy="user")
*/
private $checkNukeds;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Ticket", mappedBy="user")
*/
private $tickets;
/**
* @ORM\OneToMany(targetEntity="App\Entity\TicketReply", mappedBy="user")
*/
private $ticketReplies;
/**
* @ORM\OneToMany(targetEntity="App\Entity\UserProfile", mappedBy="user")
*/
private $userProfiles;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Language", inversedBy="users")
* @ORM\JoinColumn(name="language_id", referencedColumnName="id", nullable=false)
*/
private $language;
public function __construct()
{
$this->settings = new ArrayCollection();
$this->userCustomers = new ArrayCollection();
$this->checkNukeds = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getEmail(): ?string
{
return $this->email;
}
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
{
foreach ($this->getUserProfiles() as $user_profile) {
if ($user_profile->getProfile()->getStatus() === true) {
foreach ($user_profile->getProfile()->getRoles() as $role) {
$roles[] = $role;
}
}
}
$roles[] = 'ROLE_USER';
return array_unique($roles);
/*$roles = $this->roles;
// guarantee every user at least has ROLE_USER
$roles[] = 'ROLE_USER';
return array_unique($roles);*/
}
public function setRoles(array $roles): self
{
$this->roles = $roles;
return $this;
}
/**
* @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;
}
public function getFirstName(): ?string
{
return $this->first_name;
}
public function setFirstName(string $first_name): self
{
$this->first_name = $first_name;
return $this;
}
public function getLastName(): ?string
{
return $this->last_name;
}
public function setLastName(string $last_name): self
{
$this->last_name = $last_name;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->created_at;
}
public function setCreatedAt(\DateTimeInterface $created_at): self
{
$this->created_at = $created_at;
return $this;
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updated_at;
}
public function setUpdatedAt(?\DateTimeInterface $updated_at): self
{
$this->updated_at = $updated_at;
return $this;
}
public function getStatus(): ?bool
{
return $this->status;
}
public function setStatus(bool $status): self
{
$this->status = $status;
return $this;
}
public function isGoogleAuthenticatorEnabled(): bool
{
return null !== $this->googleAuthenticatorSecret;
}
public function getGoogleAuthenticatorUsername(): string
{
return $this->email;
}
public function getGoogleAuthenticatorSecret(): ?string
{
return $this->googleAuthenticatorSecret;
}
public function setGoogleAuthenticatorSecret(?string $googleAuthenticatorSecret): void
{
$this->googleAuthenticatorSecret = $googleAuthenticatorSecret;
}
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 Collection|Setting[]
*/
public function getSettings(): Collection
{
return $this->settings;
}
public function addSetting(Setting $setting): self
{
if (!$this->settings->contains($setting)) {
$this->settings[] = $setting;
$setting->setUser($this);
}
return $this;
}
public function removeSetting(Setting $setting): self
{
if ($this->settings->removeElement($setting)) {
// set the owning side to null (unless already changed)
if ($setting->getUser() === $this) {
$setting->setUser(null);
}
}
return $this;
}
/**
* @return Collection|UserCustomer[]
*/
public function getUserCustomers(): Collection
{
return $this->userCustomers;
}
public function addUserCustomer(UserCustomer $userCustomer): self
{
if (!$this->userCustomers->contains($userCustomer)) {
$this->userCustomers[] = $userCustomer;
$userCustomer->setUser($this);
}
return $this;
}
public function removeUserCustomer(UserCustomer $userCustomer): self
{
if ($this->userCustomers->removeElement($userCustomer)) {
// set the owning side to null (unless already changed)
if ($userCustomer->getUser() === $this) {
$userCustomer->setUser(null);
}
}
return $this;
}
public function getLanguage(): ?Language
{
return $this->language;
}
public function setLanguage(?Language $language): self
{
$this->language = $language;
return $this;
}
public function getLoginNumber(): ?int
{
return $this->login_number;
}
public function setLoginNumber(?int $login_number): self
{
$this->login_number = $login_number;
return $this;
}
public function getLastActivityAt(): ?\DateTimeInterface
{
return $this->last_activity_at;
}
public function setLastActivityAt(?\DateTimeInterface $last_activity_at): self
{
$this->last_activity_at = $last_activity_at;
return $this;
}
public function getWrongLoginNumber(): ?int
{
return $this->wrong_login_number;
}
public function setWrongLoginNumber(?int $wrong_login_number): self
{
$this->wrong_login_number = $wrong_login_number;
return $this;
}
/**
* @return Collection|CheckNuked[]
*/
public function getCheckNukeds(): Collection
{
return $this->checkNukeds;
}
public function addCheckNuked(CheckNuked $checkNuked): self
{
if (!$this->checkNukeds->contains($checkNuked)) {
$this->checkNukeds[] = $checkNuked;
$checkNuked->setUser($this);
}
return $this;
}
public function removeCheckNuked(CheckNuked $checkNuked): self
{
if ($this->checkNukeds->removeElement($checkNuked)) {
// set the owning side to null (unless already changed)
if ($checkNuked->getUser() === $this) {
$checkNuked->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, UserProfile>
*/
public function getUserProfiles(): Collection
{
return $this->userProfiles;
}
public function addUserProfile(UserProfile $userProfile): self
{
if (!$this->userProfiles->contains($userProfile)) {
$this->userProfiles[] = $userProfile;
$userProfile->setUser($this);
}
return $this;
}
public function removeUserProfile(UserProfile $userProfile): self
{
if ($this->userProfiles->removeElement($userProfile)) {
// set the owning side to null (unless already changed)
if ($userProfile->getUser() === $this) {
$userProfile->setUser(null);
}
}
return $this;
}
public function isActiveNow()
{
$delay = new \DateTime('2 minutes ago');
return ( $this->getLastActivityAt() > $delay );
}
}