src/Entity/User.php line 26

Open in your IDE?
  1. <?php
  2. /**
  3.  * Created by PhpStorm.
  4.  * User: parcel
  5.  * Date: 9/20/18
  6.  * Time: 4:03 PM
  7.  */
  8. namespace App\Entity;
  9. use Doctrine\ORM\Mapping as ORM;
  10. use JMS\Serializer\Annotation as Serializer;
  11. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  12. use Symfony\Component\Security\Core\User\UserInterface;
  13. use Symfony\Component\Serializer\Annotation\Ignore;
  14. /**
  15.  * @ORM\Entity
  16.  * @ORM\Table(name="user",
  17.  *     uniqueConstraints={@ORM\UniqueConstraint(name="username", columns={"username"}),
  18.  *                          @ORM\UniqueConstraint(name="person_id", columns={"person_id"}),
  19.  *                              @ORM\UniqueConstraint(name="email", columns={"email"})})
  20.  *
  21.  */
  22. class User implements UserInterfacePasswordAuthenticatedUserInterface  {
  23.     /**
  24.      * @ORM\Id
  25.      * @ORM\GeneratedValue(strategy="IDENTITY")
  26.      * @ORM\Column(type="integer")
  27.      */
  28.     private $id;
  29.     /**
  30.      * @ORM\Column(type="string", length=100)
  31.      */
  32.     private $username;
  33.     /**
  34.      * @Ignore
  35.      * @Serializer\Exclude()
  36.      * @ORM\Column(type="text")
  37.      */
  38.     private $password;
  39.     private $plainPassword;
  40.     /**
  41.      * @Serializer\Type("DateTime<'d/m/Y'>")
  42.      * @ORM\Column(type="datetime")
  43.      */
  44.     private $createdAt;
  45.     /**
  46.      * @var Person
  47.      * @Serializer\Type("App\Entity\Person")
  48.      * @ORM\ManyToOne(targetEntity="App\Entity\Person", cascade={"persist", "remove"})
  49.      * @ORM\JoinColumns({
  50.      *   @ORM\JoinColumn(name="person_id", referencedColumnName="id")
  51.      * })
  52.      */
  53.     private $person;
  54.     /**
  55.      * @Ignore
  56.      * @ORM\Column(type="json")
  57.      */
  58.     private $roles;
  59.     /**
  60.      * @ORM\Column(type="string", length=45)
  61.      */
  62.     private $email;
  63.     /**
  64.      * Returns the roles granted to the user.
  65.      *
  66.      * <code>
  67.      * public function getRoles()
  68.      * {
  69.      *     return array('ROLE_USER');
  70.      * }
  71.      * </code>
  72.      *
  73.      * Alternatively, the roles might be stored on a ``roles`` property,
  74.      * and populated in any number of different ways when the user object
  75.      * is created.
  76.      *
  77.      * @return (Role|string)[] The user roles
  78.      */
  79.     public function getRoles()
  80.     {
  81.         // TODO: Implement getRoles() method.
  82.         return $this->roles;
  83.     }
  84.     /**
  85.      * Returns the password used to authenticate the user.
  86.      *
  87.      * This should be the encoded password. On authentication, a plain-text
  88.      * password will be salted, encoded, and then compared to this value.
  89.      *
  90.      * @return string The password
  91.      */
  92.     public function getPassword() : ?string {
  93.         // TODO: Implement getPassword() method.
  94.         return $this->password;
  95.     }
  96.     /**
  97.      * Returns the salt that was originally used to encode the password.
  98.      *
  99.      * This can return null if the password was not encoded using a salt.
  100.      *
  101.      * @return string|null The salt
  102.      */
  103.     public function getSalt()
  104.     {
  105.         // TODO: Implement getSalt() method.
  106.     }
  107.     /**
  108.      * Returns the username used to authenticate the user.
  109.      *
  110.      * @return string The username
  111.      */
  112.     public function getUsername()
  113.     {
  114.         // TODO: Implement getUsername() method.
  115.         return $this->username;
  116.     }
  117.     /**
  118.      * Removes sensitive data from the user.
  119.      *
  120.      * This is important if, at any given point, sensitive information like
  121.      * the plain-text password is stored on this object.
  122.      */
  123.     public function eraseCredentials()
  124.     {
  125.         // TODO: Implement eraseCredentials() method.
  126.         $this->plainPassword "";
  127.     }
  128.     /**
  129.      * @return mixed
  130.      */
  131.     public function getId()
  132.     {
  133.         return $this->id;
  134.     }
  135.     /**
  136.      * @param mixed $id
  137.      */
  138.     public function setId($id)
  139.     {
  140.         $this->id $id;
  141.     }
  142.     /**
  143.      * @return mixed
  144.      */
  145.     public function getPlainPassword()
  146.     {
  147.         return $this->plainPassword;
  148.     }
  149.     /**
  150.      * @param mixed $plainPassword
  151.      */
  152.     public function setPlainPassword($plainPassword)
  153.     {
  154.         $this->plainPassword $plainPassword;
  155.     }
  156.     /**
  157.      * @return mixed
  158.      */
  159.     public function getCreatedAt(){
  160.         return $this->createdAt;
  161.     }
  162.     /**
  163.      * @param mixed $createdAt
  164.      */
  165.     public function setCreatedAt($createdAt){
  166.         $this->createdAt $createdAt;
  167.     }
  168.     /**
  169.      * @param mixed $username
  170.      */
  171.     public function setUsername($username){
  172.         $this->username $username;
  173.     }
  174.     /**
  175.      * @param mixed $password
  176.      */
  177.     public function setPassword($password) {
  178.         $this->password $password;
  179.     }
  180.     /**
  181.      * @param mixed $roles
  182.      */
  183.     public function setRoles($roles){
  184.         $this->roles $roles;
  185.     }
  186.     /**
  187.      * @return Person
  188.      */
  189.     public function getPerson(){
  190.         return $this->person;
  191.     }
  192.     /**
  193.      * @param Person $person
  194.      */
  195.     public function setPerson($person){
  196.         $this->person $person;
  197.     }
  198.     /**
  199.      * @return mixed
  200.      */
  201.     public function getEmail()
  202.     {
  203.         return $this->email;
  204.     }
  205.     /**
  206.      * @param mixed $email
  207.      */
  208.     public function setEmail($email)
  209.     {
  210.         $this->email $email;
  211.     }
  212.     public function getUserIdentifier(): string
  213.     {
  214.         return $this->username;
  215.     }
  216.     public function __toString()
  217.     {
  218.         // TODO: Implement __toString() method.
  219.         return $this->username."";
  220.     }
  221. }