Select Git revision

David Beniamine authored
User.php 6.51 KiB
<?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\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\LegacyPasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity(repositoryClass=UserRepository::class)
* @ORM\Table(name="`user`")
* @UniqueEntity(fields={"email"}, message="email.unique")
*/
class User implements UserInterface, LegacyPasswordAuthenticatedUserInterface
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private int $id;
/**
* @ORM\Column(type="boolean", name="accept_gnl_conditions")
*/
private bool $acceptGeneralConditions;
/**
* @ORM\Column(type="boolean", name="inscription_newsletter")
*/
private bool $is_subscribed_news_letter;
/**
* @ORM\Column(type="string", length=255)
* @Assert\Email(message = "The email {{ value }} is not a valid email.")
*/
private string $email;
/**
* @ORM\Column(type="string", length=255, unique=true)
*/
private string $email_canonical;
/**
* @ORM\Column(type="string", name="name")
*/
private string $lastName;
/**
* @ORM\Column(type="string", name="firstname")
*/
private string $firstName;
/**
* @ORM\Column(type="string")
*/
private string $username;
/**
* @ORM\Column(type="string", name="username_canonical", unique=true)
*/
private string $username_canonical;
/**
* @ORM\Column(type="boolean", name="credential_expired")
*/
private bool $credentialExpired = false;
/**
* @ORM\Column(type="json")
*/
private array $roles = []; /** @phpstan-ignore-line */
/**
* @var string The hashed password
* @ORM\Column(type="string")
*/
private string $password;
/**
* @ORM\Column(type="boolean", name="enabled")
*/
private bool $isVerified;
/**
* @ORM\Column(type="string", length=255, name="salt")
*/
private string $salt;
/**
* @var Collection<Capsule>
* @ORM\ManyToMany(targetEntity="App\Entity\Capsule", mappedBy="editors")
*/
private Collection $capsules;
public function __construct()
{
$this->capsules = new ArrayCollection();
$this->acceptGeneralConditions = false;
$this->isVerified = false;
$this->credentialExpired = false;
}
public function getId(): int
{
return $this->id;
}
public function getEmail(): string
{
return $this->email;
}
public function setEmail(string $email): self
{
$this->email = $email;
$this->email_canonical = strtolower($email);
$this->username = $email;
$this->username_canonical = strtolower($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 $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);
}
/**
* @param array<string> $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 $this->salt;
}
/**
* @see UserInterface
*/
public function eraseCredentials(): void
{
// If you store any temporary, sensitive data on the user, clear it here
// $this->plainPassword = null;
}
public function isVerified(): bool
{
return $this->isVerified;
}
public function setIsVerified(bool $isVerified): self
{
$this->isVerified = $isVerified;
return $this;
}
public function getFirstName(): string
{
return $this->firstName;
}
public function getLastName(): ?string
{
return $this->lastName;
}
public function setFirstName(string $firstName): void
{
$this->firstName = $firstName;
}
public function setLastName(string $name): void
{
$this->lastName = $name;
}
public function setSalt(string $salt): void
{
$this->salt = $salt;
}
public function getFullName(): string
{
return $this->firstName . " " . $this->lastName;
}
/**
* @return Collection<Capsule>
*/
public function getCapsules(): Collection
{
return $this->capsules;
}
public function addCapsule(Capsule $capsule): void
{
$this->capsules[] = $capsule;
}
public function removeCapsule(Capsule $capsule): User
{
$this->capsules->removeElement($capsule);
return $this;
}
/**
* @return bool
*/
public function hasAcceptGeneralConditions(): bool
{
return $this->acceptGeneralConditions;
}
/**
* @param bool $acceptGeneralConditions
*/
public function setAcceptGeneralConditions(bool $acceptGeneralConditions): void
{
$this->acceptGeneralConditions = $acceptGeneralConditions;
}
/**
* @return bool
*/
public function isSubscribedToNewsLetter(): bool
{
return $this->is_subscribed_news_letter;
}
/**
* @param bool $is_subscribed_news_letter
*/
public function setSubscribedToNewsLetter(bool $is_subscribed_news_letter): void
{
$this->is_subscribed_news_letter = $is_subscribed_news_letter;
}
}