<?php
namespace App\Entity;
use App\Repository\UsersRepository;
use DH\Auditor\Provider\Doctrine\Auditing\Annotation\Auditable;
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 Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity(repositoryClass=UsersRepository::class)
* @UniqueEntity(fields={"mail"}, message="Un autre compte avec ce mail existe déjà.")
* @UniqueEntity(fields={"login"}, message="Un autre compte avec ce login existe déjà.")
* @UniqueEntity(fields={"telephone"}, message="Un autre compte avec ce numéro existe déjà.")
* @Auditable
*/
class Users implements UserInterface, PasswordAuthenticatedUserInterface
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @var string The hashed password
* @ORM\Column(type="string", length=4096)
*/
private $username;
/**
* @ORM\Column(type="string", length=255)
* @Assert\Regex(
* pattern="/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[!@#\$%\^&\*]).{6,}$/",
* message="Votre mot de passe doit contenir au moins une lettre en majuscule, un chiffre, un caractère spécial parmi !@#$%^&*"
* )
* @Assert\Length(
* min="6",
* max="4096",
* minMessage="Ce champ accepte un minimum de 6 caractères",
* maxMessage="Ce champ accepte un maximum de 4096 caractères"
* )
* @Assert\NotCompromisedPassword(
* message="Ce mot de passe n'est pas sécurisé veuillez saisir un autre "
* )
*/
private $password;
/**
* @ORM\Column(type="integer")
*/
private $userType;
/**
* @ORM\Column(type="string", length=255, nullable=true, unique=true)
*/
private $mail;
/**
* @ORM\Column(type="string", length=255, nullable=true, unique=true)
*/
private $telephone;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $isAuthority;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $signature;
/**
* @ORM\Column(type="string", length=255, unique=true)
*/
private $login;
/**
* @ORM\ManyToOne(targetEntity=Sites::class)
* @ORM\JoinColumn(nullable=true)
*/
private $site;
/**
* @ORM\Column(type="boolean")
*/
private $isDeleted;
/**
* @ORM\Column(type="boolean")
*/
private $status;
/**
* @ORM\Column(type="datetime")
*/
private $dateCreate;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $lastConnection;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $otp;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $timeOtp;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $firstLogin;
/**
* @ORM\OneToMany(targetEntity=Report::class, mappedBy="user")
*/
private $reports;
// /**
// * @ORM\Column(type="datetime", nullable=true)
// */
// private $LastConnection;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $updatePasswordDate;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $deletedDate;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $userDeleted;
/**
* @ORM\OneToMany(targetEntity=ExchangeRate::class, mappedBy="userModify")
*/
private $exchangeRates;
/**
* @ORM\OneToMany(targetEntity=Livraison::class, mappedBy="createdBy")
*/
private $livraisons;
/**
* @ORM\Column(type="string", length=255)
*/
private $uID;
public function __construct()
{
$this->username = "";
$this->status = true;
$this->isDeleted = false;
$this->dateCreate = new \DateTime();
$this->reports = new ArrayCollection();
$this->exchangeRates = new ArrayCollection();
$this->livraisons = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
/**
* A visual identifier that represents this user.
*
* @see UserInterface
*/
public function getUsername(): ?string
{
return $this->username;
}
public function setUsername(string $username): self
{
$this->username = $username;
return $this;
}
public function getLogin(): ?string
{
return $this->login;
}
public function setLogin(string $login): self
{
$this->login = $login;
return $this;
}
/**
* @see UserInterface
*/
public function getPassword(): ?string
{
return $this->password;
}
public function setPassword(string $password): self
{
$this->password = $password;
return $this;
}
/**
* @see UserInterface
*/
public function getSalt() : ?string
{
// not needed when using the "bcrypt" algorithm in security.yaml
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 getUserType(): ?int
{
return $this->userType;
}
public function setUserType(int $userType): self
{
$this->userType = $userType;
return $this;
}
public function getMail(): ?string
{
return $this->mail;
}
public function setMail(?string $mail): self
{
$this->mail = $mail;
return $this;
}
public function getTelephone(): ?string
{
return $this->telephone;
}
public function setTelephone(?string $telephone): self
{
$this->telephone = $telephone;
return $this;
}
public function getIsAuthority(): ?bool
{
return $this->isAuthority;
}
public function setIsAuthority(?bool $isAuthority): self
{
$this->isAuthority = $isAuthority;
return $this;
}
public function getSignature(): ?string
{
return $this->signature;
}
public function setSignature(?string $signature): self
{
$this->signature = $signature;
return $this;
}
public function getSite(): ?Sites
{
return $this->site;
}
public function setSite(?Sites $site): self
{
$this->site = $site;
return $this;
}
public function getIsDeleted(): ?bool
{
return $this->isDeleted;
}
public function setIsDeleted(bool $isDeleted): self
{
$this->isDeleted = $isDeleted;
return $this;
}
public function getRoles(): ?array
{
return ['ROLE_USER'];
}
public function getStatus(): ?bool
{
return $this->status;
}
public function setStatus(bool $status): self
{
$this->status = $status;
return $this;
}
public function getLastConnection(): ?\DateTimeInterface
{
return $this->lastConnection;
}
public function setLastConnection(?\DateTimeInterface $lastConnection): self
{
$this->lastConnection = $lastConnection;
return $this;
}
public function getDateCreate(): ?\DateTimeInterface
{
return $this->dateCreate;
}
public function setDateCreate(\DateTimeInterface $dateCreate): self
{
$this->dateCreate = $dateCreate;
return $this;
}
public function getOtp(): ?string
{
return $this->otp;
}
public function setOtp(?string $otp): self
{
$this->otp = $otp;
return $this;
}
public function getTimeOtp(): ?\DateTimeInterface
{
return $this->timeOtp;
}
public function setTimeOtp(?\DateTimeInterface $timeOtp): self
{
$this->timeOtp = $timeOtp;
return $this;
}
public function getFirstLogin(): ?bool
{
return $this->firstLogin;
}
public function setFirstLogin(?bool $firstLogin): self
{
$this->firstLogin = $firstLogin;
return $this;
}
/**
* @return Collection|Report[]
*/
public function getReports(): Collection
{
return $this->reports;
}
public function addReport(Report $report): self
{
if (!$this->reports->contains($report)) {
$this->reports[] = $report;
$report->setUser($this);
}
return $this;
}
public function removeReport(Report $report): self
{
if ($this->reports->removeElement($report)) {
// set the owning side to null (unless already changed)
if ($report->getUser() === $this) {
$report->setUser(null);
}
}
return $this;
}
public function getUpdatePasswordDate(): ?\DateTimeInterface
{
return $this->updatePasswordDate;
}
public function setUpdatePasswordDate(?\DateTimeInterface $updatePasswordDate): self
{
$this->updatePasswordDate = $updatePasswordDate;
return $this;
}
public function getDeletedDate(): ?\DateTimeInterface
{
return $this->deletedDate;
}
public function setDeletedDate(?\DateTimeInterface $deletedDate): self
{
$this->deletedDate = $deletedDate;
return $this;
}
public function getUserDeleted(): ?int
{
return $this->userDeleted;
}
public function setUserDeleted(?int $userDeleted): self
{
$this->userDeleted = $userDeleted;
return $this;
}
/**
* @return Collection<int, ExchangeRate>
*/
public function getExchangeRates(): Collection
{
return $this->exchangeRates;
}
public function addExchangeRate(ExchangeRate $exchangeRate): self
{
if (!$this->exchangeRates->contains($exchangeRate)) {
$this->exchangeRates[] = $exchangeRate;
$exchangeRate->setUserModify($this);
}
return $this;
}
public function removeExchangeRate(ExchangeRate $exchangeRate): self
{
if ($this->exchangeRates->removeElement($exchangeRate)) {
// set the owning side to null (unless already changed)
if ($exchangeRate->getUserModify() === $this) {
$exchangeRate->setUserModify(null);
}
}
return $this;
}
public function getUserIdentifier(): string
{
// Implement the method to return the user identifier
return $this->login;
}
/**
* @return Collection<int, Livraison>
*/
public function getLivraisons(): Collection
{
return $this->livraisons;
}
public function addLivraison(Livraison $livraison): self
{
if (!$this->livraisons->contains($livraison)) {
$this->livraisons[] = $livraison;
$livraison->setCreatedBy($this);
}
return $this;
}
public function removeLivraison(Livraison $livraison): self
{
if ($this->livraisons->removeElement($livraison)) {
// set the owning side to null (unless already changed)
if ($livraison->getCreatedBy() === $this) {
$livraison->setCreatedBy(null);
}
}
return $this;
}
public function getUID(): ?string
{
return $this->uID;
}
public function setUID(string $uID): self
{
$this->uID = $uID;
return $this;
}
}