src/Entity/User.php line 15
<?phpnamespace App\Entity;use App\Repository\UserRepository;use Doctrine\ORM\Mapping as ORM;use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;use Symfony\Component\Security\Core\User\UserInterface;/*** @ORM\Entity(repositoryClass=UserRepository::class)* @UniqueEntity(fields={"email"}, message="There is already an account with this email")*/class User implements UserInterface, PasswordAuthenticatedUserInterface{/*** @ORM\Id* @ORM\GeneratedValue* @ORM\Column(type="integer")*/private ?int $id = null;/*** @ORM\Column(type="string", length=180, unique=true)*/private ?string $email = null;/*** @ORM\Column(type="string", length=100)*/private string $name;/*** @ORM\Column(type="string", length=30)*/private string $phone;/*** @ORM\Column(type="json")*/private array $roles = [];/*** @var string|null The hashed password* @ORM\Column(type="string", nullable=true)*/private ?string $password = '';/*** @ORM\Column(type="boolean")*/private bool $isVerified = false;/*** True for an account this app created by itself while a visitor was* checking out as a guest, rather than one somebody filled the sign-up form* in for. Such an account has a random password nobody knows, so it stays* unusable for signing in until the passenger follows the "choose a* password" link mailed to them. Cleared the moment they do.** @ORM\Column(type="boolean")*/private bool $isGuest = false;/*** One-time token behind that link. Null once used or never issued.** @ORM\Column(type="string", length=64, nullable=true, unique=true)*/private ?string $passwordSetToken = null;/*** @ORM\Column(type="datetime_immutable", nullable=true)*/private ?\DateTimeImmutable $passwordSetTokenExpiresAt = null;private ?string $plainPassword = null;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;}/*** Required by UserInterface for Symfony 5 compatibility.*/public function getUsername(): string{return $this->getUserIdentifier();}public function hasRole(string $role): bool{return in_array($role, $this->getRoles());}/*** @see UserInterface*/public function getRoles(): array{$roles = $this->roles;$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;}/*** @see UserInterface*/public function eraseCredentials(): void{$this->plainPassword = null;}/*** Required by UserInterface for Symfony 5 compatibility.*/public function getSalt(): ?string{return null;}public function isVerified(): bool{return $this->isVerified;}public function setIsVerified(bool $isVerified): self{$this->isVerified = $isVerified;return $this;}public function isIsVerified(): ?bool{return $this->isVerified;}public function isGuest(): bool{return $this->isGuest;}public function setIsGuest(bool $isGuest): self{$this->isGuest = $isGuest;return $this;}public function getPasswordSetToken(): ?string{return $this->passwordSetToken;}public function getPasswordSetTokenExpiresAt(): ?\DateTimeImmutable{return $this->passwordSetTokenExpiresAt;}/*** Issue (or re-issue) the one-time link that lets this account choose its* first password, and hand the raw token back for the email. Any token* issued earlier stops working, so the newest mail is always the live one.*/public function startPasswordSetup(int $validForDays = 14): string{$this->passwordSetToken = bin2hex(random_bytes(32));$this->passwordSetTokenExpiresAt = new \DateTimeImmutable(sprintf('+%d days', $validForDays));return $this->passwordSetToken;}public function isPasswordSetupPending(): bool{return $this->passwordSetToken !== null&& $this->passwordSetTokenExpiresAt !== null&& $this->passwordSetTokenExpiresAt > new \DateTimeImmutable();}/*** Burn the token. Called once the password is chosen, so the link in the* mailbox cannot be replayed by anyone who reads that inbox later.*/public function finishPasswordSetup(): void{$this->passwordSetToken = null;$this->passwordSetTokenExpiresAt = null;$this->isGuest = false;}public function getPlainPassword(): ?string{return $this->plainPassword;}public function setPlainPassword(?string $plainPassword): void{$this->plainPassword = $plainPassword;}public function getName(): string{return $this->name;}public function setName(string $name): void{$this->name = $name;}public function getPhone(): string{return $this->phone;}public function setPhone(string $phone): void{$this->phone = $phone;}public function __toString(): string{return $this->email ?? '';}}