<?php
/*
* This event is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* event that was distributed with this source code.
*/
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity(repositoryClass="App\Repository\UserRepository")
* @ORM\Table(name="user")
*
* Defines the properties of the User entity to represent the application users.
* See https://symfony.com/doc/current/doctrine.html#creating-an-entity-class
*
* Tip: if you have an existing database, you can generate these entity class automatically.
* See https://symfony.com/doc/current/doctrine/reverse_engineering.html
*
* @author Ryan Weaver <weaverryan@gmail.com>
* @author Javier Eguiluz <javier.eguiluz@gmail.com>
*/
class User implements UserInterface, PasswordAuthenticatedUserInterface {
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private ?int $id = null;
/**
* @ORM\Column(type="string")
*/
#[Assert\NotBlank]
private ?string $firstname = null;
/**
* @ORM\Column(type="string")
*/
#[Assert\NotBlank]
private ?string $lastname = null;
/**
* @ORM\Column(type="string", unique=true)
*/
#[
Assert\NotBlank,
Assert\Length(min: 2, max: 50)
]
private ?string $username = null;
/**
* @ORM\Column(type="string", nullable=true)
*/
private ?string $published = "1";
/**
* @ORM\Column(type="string", nullable=true)
*/
private ?string $bio;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private \DateTime $createdAt;
/**
* @ORM\Column(type="string", nullable=true)
*/
private ?string $emailVerification = "0";
/**
* @ORM\Column(type="string", unique=true)
*/
#[Assert\Email]
private ?string $email = null;
/**
* @ORM\Column(type="string", nullable=true)
*/
private ?string $password = null;
/**
* @ORM\Column(type="string", nullable=true)
*/
private ?string $tokenreset = null;
/**
* @ORM\Column(type="string", nullable=true)
*/
private ?string $phone = null;
/**
* @ORM\Column(type="string", nullable=true)
*/
private ?string $country = null;
/**
* @ORM\Column(type="string", nullable=true)
*/
private ?string $gender = null;
// 1 men 0 women
/**
* @ORM\Column(type="string", nullable=true)
*/
private ?string $address = null;
/**
* @ORM\Column(type="json")
*/
private array $roles = [];
/**
* @ORM\Column(type="string", nullable=true)
*/
private ?string $image = null;
public function __construct() {
$this->createdAt = new \DateTime('now');
}
public function getId(): ?int {
return $this->id;
}
public function setFullName(string $fullName): void {
$this->fullName = $fullName;
}
public function getFullName(): ?string {
return $this->fullName;
}
public function getUserIdentifier(): string {
return $this->username;
}
public function getFirstname(): ?string {
return $this->firstname;
}
public function getLastname(): ?string {
return $this->lastname;
}
public function getUsername(): ?string {
return $this->username;
}
public function getBio(): ?string {
return $this->bio;
}
public function getEmail(): ?string {
return $this->email;
}
public function getPassword(): ?string {
return $this->password;
}
public function setFirstname(?string $firstname): void {
$this->firstname = $firstname;
}
public function setLastname(?string $lastname): void {
$this->lastname = $lastname;
}
public function setUsername(?string $username): void {
$this->username = $username;
}
public function getPublished(): ?string {
return $this->published;
}
public function setPublished(?string $published): void {
$this->published = $published;
}
public function setBio(?string $bio): void {
$this->bio = $bio;
}
public function setEmail(?string $email): void {
$this->email = $email;
}
public function setPassword(?string $password): void {
$this->password = $password;
}
/**
* Returns the roles or permissions granted to the user for security.
*/
public function getRoles(): array {
$roles = $this->roles;
// guarantees that a user always has at least one role for security
if (empty($roles)) {
$roles[] = 'ROLE_USER';
}
return array_unique($roles);
}
public function setRoles(array $roles): void {
$this->roles = $roles;
}
public function getTokenreset(): ?string {
return $this->tokenreset;
}
public function setTokenreset(?string $tokenreset): void {
$this->tokenreset = $tokenreset;
}
public function getEmailVerification(): ?string {
return $this->emailVerification;
}
public function setEmailVerification(?string $emailVerification): void {
$this->emailVerification = $emailVerification;
}
public function getPhone(): ?string {
return $this->phone;
}
public function setPhone(?string $phone): void {
$this->phone = $phone;
}
public function getCreatedAt(): \DateTime {
return $this->createdAt;
}
public function setCreatedAt(\DateTime $createdAt): void {
$this->createdAt = $createdAt;
}
/**
* Returns the salt that was originally used to encode the password.
*
* {@inheritdoc}
*/
public function getSalt(): ?string {
// We're using bcrypt in security.yaml to encode the password, so
// the salt value is built-in and you don't have to generate one
// See https://en.wikipedia.org/wiki/Bcrypt
return null;
}
/**
* Removes sensitive data from the user.
*
* {@inheritdoc}
*/
public function eraseCredentials(): void {
// if you had a plainPassword property, you'd nullify it here
// $this->plainPassword = null;
}
public function __serialize(): array {
// add $this->salt too if you don't use Bcrypt or Argon2i
return [$this->id, $this->username, $this->password];
}
public function __unserialize(array $data): void {
// add $this->salt too if you don't use Bcrypt or Argon2i
[$this->id, $this->username, $this->password] = $data;
}
public function getImage(): ?string {
return $this->image;
}
public function setImage(?string $image): void {
$this->image = $image;
}
public function getCountry(): ?string {
return $this->country;
}
public function getAddress(): ?string {
return $this->address;
}
public function setCountry(?string $country): void {
$this->country = $country;
}
public function setAddress(?string $address): void {
$this->address = $address;
}
public function getGender(): ?string {
return $this->gender;
}
public function setGender(?string $gender): void {
$this->gender = $gender;
}
}