. */ namespace Sikofitt\App\Entity; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Security\Core\Encoder\BCryptPasswordEncoder; use Symfony\Component\Validator\Constraints as Assert; /** * Class User. * * @ORM\Entity(repositoryClass="Sikofitt\App\Repository\UserRepository") * @ORM\Table(name="users") */ class User { const KATRINA_SIDE = 'Katrina'; const ERIC_SIDE = 'Eric'; /** * @ORM\Id() * @ORM\Column(name="id", type="integer", nullable=false, unique=true) * @ORM\GeneratedValue(strategy="IDENTITY") * * @var int */ private $id; /** * @ORM\Column(name="first_name", type="string", length=255, nullable=false) * @Assert\NotBlank() * @Assert\Regex(pattern="/\w+/") */ private $firstName; /** * @ORM\Column(name="last_name", type="string", length=255, nullable=false) * @Assert\NotBlank() * @Assert\Regex(pattern="/\w+/") */ private $lastName; /** * @ORM\Column(type="boolean", name="is_family", nullable=false) * @Assert\Type(type="bool") */ private $family = false; /** * @ORM\Column(type="string", name="family_side", nullable=true) * @Assert\Choice(choices="{self::KATRINA_SIDE, self::ERIC_SIDE}", multiple=false) * * @var null|string */ private $familySide = null; /** * @ORM\Column(name="email", type="string", length=255) * @Assert\Email(strict=true, checkHost=true, checkMX=true) */ private $email; /** * @var string * @ORM\Column(name="password", type="string", length=255)) */ private $password; /** * @var string */ private $plainPassword; /** * @var string * @ORM\Column(name="token", type="string", length=255, nullable=true) */ private $token; /** * @var int * @ORM\OneToOne(targetEntity="Sikofitt\App\Entity\Rsvp", inversedBy="user", cascade={"persist"}) */ private $rsvp; /** * @ORM\Column(type="datetime", name="created") */ private $created = null; /** * @ORM\Column(type="datetime", name="updated") */ private $updated = null; public function __construct() { if (null === $this->created) { $this->created = new \DateTime('now'); } $this->updated = new \DateTime('now'); } /** * Get id. * * @return int */ public function getId() { return $this->id; } /** * Set firstName. * * @param string $firstName * * @return User */ public function setFirstName($firstName) { $this->firstName = $firstName; return $this; } /** * Get firstName. * * @return string */ public function getFirstName() { return $this->firstName; } /** * Set lastName. * * @param string $lastName * * @return User */ public function setLastName($lastName) { $this->lastName = $lastName; return $this; } /** * Get lastName. * * @return string */ public function getLastName() { return $this->lastName; } /** * Set family. * * @param bool $family * * @return User */ public function setFamily($family) { $this->family = $family; return $this; } /** * Get family. * * @return bool */ public function getFamily() { return $this->family; } /** * Set familySide. * * @param string $familySide * * @return User */ public function setFamilySide($familySide) { $this->familySide = $familySide; return $this; } /** * Get familySide. * * @return string */ public function getFamilySide() { return $this->familySide; } /** * Set email. * * @param string $email * * @return User */ public function setEmail($email) { $this->email = $email; return $this; } /** * Get email. * * @return string */ public function getEmail() { return $this->email; } /** * @param string $password * * @return $this */ public function setPassword($password) { $encoder = new BCryptPasswordEncoder(14); $salt = bin2hex(random_bytes(16)); $this->password = $encoder->encodePassword($password, $salt); return $this; } /** * @return string */ public function getPassword() { return $this->password; } /** * @return string */ public function getPlainPassword(): string { if (null === $this->plainPassword) { return ''; } else { return $this->plainPassword; } } /** * @param string $plainPassword * * @return User */ public function setPlainPassword(string $plainPassword): User { $this->plainPassword = $plainPassword; return $this; } /** * @param string $token * * @return $this */ public function setToken($token) { $this->token = $token; return $this; } /** * @return string */ public function getToken() { return $this->token; } /** * Set created. * * @param \DateTime $created * * @return User */ public function setCreated($created) { $this->created = $created; return $this; } /** * Get created. * * @return \DateTime */ public function getCreated() { return $this->created; } /** * Set updated. * * @param \DateTime $updated * * @return User */ public function setUpdated($updated) { $this->updated = $updated; return $this; } /** * Get updated. * * @return \DateTime */ public function getUpdated() { return $this->updated; } /** * Set rsvp. * * @param \Sikofitt\App\Entity\Rsvp $rsvp * * @return User */ public function setRsvp(\Sikofitt\App\Entity\Rsvp $rsvp = null) { $this->rsvp = $rsvp; return $this; } /** * Get rsvp. * * @return \Sikofitt\App\Entity\Rsvp */ public function getRsvp() { return $this->rsvp; } }