<?php
namespace App\Entity;
use Serializable;
use Doctrine\ORM\Mapping as ORM;
use App\Repository\UserRepository;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Validator\Constraints as Assert; // va nous permettre de sécuriser notre formulaire
/**
* @ORM\Entity(repositoryClass=UserRepository::class)
* ORM\HasLifecycleCallbacks()
* @UniqueEntity(
* fields={"email"},
* message="Un autre utilisateur s'est déjà inscrit avec cette adresse email, merci de la modifier."
* )
*/
class User implements UserInterface, PasswordAuthenticatedUserInterface, \Serializable
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @Assert\Length(
* min = 1,
* max = 180,
* minMessage = "Vous devez mettre au minimum {{ limit }} charactères.",
* maxMessage = "Vous ne pouvez pas mettre plus de {{ limit }} charactères pour ce champs."
* )
* @ORM\Column(type="string", length=180, unique=true)
*/
private $email;
/**
* @ORM\Column(type="json")
*/
private $roles = [];
/**
* @var string The hashed password
* @ORM\Column(type="string")
*/
private $password;
/**
* @Assert\Length(
* min = 1,
* max = 255,
* minMessage = "Vous devez mettre au minimum {{ limit }} charactères.",
* maxMessage = "Vous ne pouvez pas mettre plus de {{ limit }} charactères pour ce champs."
* )
* @ORM\Column(type="string", length=255)
*/
private $firstname;
/**
* @Assert\Length(
* min = 1,
* max = 255,
* minMessage = "Vous devez mettre au minimum {{ limit }} charactères.",
* maxMessage = "Vous ne pouvez pas mettre plus de {{ limit }} charactères pour ce champs."
* )
* @ORM\Column(type="string", length=255)
*/
private $lastname;
/**
* @ORM\Column(type="boolean")
*/
private $isActive;
/**
* @ORM\Column(type="string", length=510)
*/
private $fullname;
/**
* @Assert\EqualTo(propertyPath="password", message="Vous n'avez pas correctement confirmé votre mot de passe !")
*/
public $passwordConfirm;
/**
* @ORM\OneToOne(targetEntity=Jobseeker::class, mappedBy="user", cascade={"persist", "remove"})
*/
private $jobseeker;
/**
* @ORM\ManyToOne(targetEntity=Organization::class, inversedBy="users")
*/
private $organization;
public $code;
public function getId(): ?int
{
return $this->id;
}
public function serialize()
{
return serialize(array(
$this->id,
$this->email,
$this->password,
// see section on salt below
// $this->salt,
));
}
public function unserialize($serialized)
{
list (
$this->id,
$this->email,
$this->password,
// see section on salt below
// $this->salt
) = unserialize($serialized);
}
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
{
$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->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 getIsActive(): ?bool
{
return $this->isActive;
}
public function setIsActive(bool $isActive): self
{
$this->isActive = $isActive;
return $this;
}
public function getFullname(): ?string
{
return $this->fullname;
}
public function setFullname(string $fullname): self
{
$this->fullname = $fullname;
return $this;
}
public function getPasswordConfirm(): ?string
{
return $this->passwordConfirm;
}
public function setPasswordConfirm(string $passwordConfirm): self
{
$this->passwordConfirm = $passwordConfirm;
return $this;
}
public function getJobseeker(): ?Jobseeker
{
return $this->jobseeker;
}
public function setJobseeker(Jobseeker $jobseeker): self
{
// set the owning side of the relation if necessary
if ($jobseeker->getUser() !== $this) {
$jobseeker->setUser($this);
}
$this->jobseeker = $jobseeker;
return $this;
}
public function isGranted($role)
{
return in_array($role, $this->getRoles());
}
public function getOrganization(): ?Organization
{
return $this->organization;
}
public function setOrganization(?Organization $organization): self
{
$this->organization = $organization;
return $this;
}
}