<?php
/**
* Created by PhpStorm.
* User: parcel
* Date: 9/20/18
* Time: 4:03 PM
*/
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation as Serializer;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Serializer\Annotation\Ignore;
/**
* @ORM\Entity
* @ORM\Table(name="user",
* uniqueConstraints={@ORM\UniqueConstraint(name="username", columns={"username"}),
* @ORM\UniqueConstraint(name="person_id", columns={"person_id"}),
* @ORM\UniqueConstraint(name="email", columns={"email"})})
*
*/
class User implements UserInterface, PasswordAuthenticatedUserInterface {
/**
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=100)
*/
private $username;
/**
* @Ignore
* @Serializer\Exclude()
* @ORM\Column(type="text")
*/
private $password;
private $plainPassword;
/**
* @Serializer\Type("DateTime<'d/m/Y'>")
* @ORM\Column(type="datetime")
*/
private $createdAt;
/**
* @var Person
* @Serializer\Type("App\Entity\Person")
* @ORM\ManyToOne(targetEntity="App\Entity\Person", cascade={"persist", "remove"})
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="person_id", referencedColumnName="id")
* })
*/
private $person;
/**
* @Ignore
* @ORM\Column(type="json")
*/
private $roles;
/**
* @ORM\Column(type="string", length=45)
*/
private $email;
/**
* Returns the roles granted to the user.
*
* <code>
* public function getRoles()
* {
* return array('ROLE_USER');
* }
* </code>
*
* Alternatively, the roles might be stored on a ``roles`` property,
* and populated in any number of different ways when the user object
* is created.
*
* @return (Role|string)[] The user roles
*/
public function getRoles()
{
// TODO: Implement getRoles() method.
return $this->roles;
}
/**
* Returns the password used to authenticate the user.
*
* This should be the encoded password. On authentication, a plain-text
* password will be salted, encoded, and then compared to this value.
*
* @return string The password
*/
public function getPassword() : ?string {
// TODO: Implement getPassword() method.
return $this->password;
}
/**
* Returns the salt that was originally used to encode the password.
*
* This can return null if the password was not encoded using a salt.
*
* @return string|null The salt
*/
public function getSalt()
{
// TODO: Implement getSalt() method.
}
/**
* Returns the username used to authenticate the user.
*
* @return string The username
*/
public function getUsername()
{
// TODO: Implement getUsername() method.
return $this->username;
}
/**
* Removes sensitive data from the user.
*
* This is important if, at any given point, sensitive information like
* the plain-text password is stored on this object.
*/
public function eraseCredentials()
{
// TODO: Implement eraseCredentials() method.
$this->plainPassword = "";
}
/**
* @return mixed
*/
public function getId()
{
return $this->id;
}
/**
* @param mixed $id
*/
public function setId($id)
{
$this->id = $id;
}
/**
* @return mixed
*/
public function getPlainPassword()
{
return $this->plainPassword;
}
/**
* @param mixed $plainPassword
*/
public function setPlainPassword($plainPassword)
{
$this->plainPassword = $plainPassword;
}
/**
* @return mixed
*/
public function getCreatedAt(){
return $this->createdAt;
}
/**
* @param mixed $createdAt
*/
public function setCreatedAt($createdAt){
$this->createdAt = $createdAt;
}
/**
* @param mixed $username
*/
public function setUsername($username){
$this->username = $username;
}
/**
* @param mixed $password
*/
public function setPassword($password) {
$this->password = $password;
}
/**
* @param mixed $roles
*/
public function setRoles($roles){
$this->roles = $roles;
}
/**
* @return Person
*/
public function getPerson(){
return $this->person;
}
/**
* @param Person $person
*/
public function setPerson($person){
$this->person = $person;
}
/**
* @return mixed
*/
public function getEmail()
{
return $this->email;
}
/**
* @param mixed $email
*/
public function setEmail($email)
{
$this->email = $email;
}
public function getUserIdentifier(): string
{
return $this->username;
}
public function __toString()
{
// TODO: Implement __toString() method.
return $this->username."";
}
}