Advertisement
Guest User

Untitled

a guest
Mar 11th, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.14 KB | None | 0 0
  1. <?php
  2.  
  3. namespace ImmoWebBundle\Entity;
  4.  
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Symfony\Component\Security\Core\User\AdvancedUserInterface;
  7. use Symfony\Component\Validator\Constraints as Assert;
  8. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  9.  
  10. /**
  11.  * Class Person
  12.  *
  13.  * @ORM\Entity(repositoryClass="ImmoWebBundle\Entity\PersonRepository")
  14.  * @ORM\Table(name="persons")
  15.  * @ORM\HasLifecycleCallbacks
  16.  *
  17.  * @package ImmoWebBundle\Entity
  18.  */
  19. class Person implements AdvancedUserInterface, \Serializable
  20. {
  21.     use IdTrait, NameAndSlugTrait, TimestampTrait;
  22.  
  23.     const ROLE_ADMIN = 'ROLE_ADMIN';
  24.     const ROLE_USER = 'ROLE_USER';
  25.  
  26.     /**
  27.      * @ORM\Column(type="string", length=100, unique=true)
  28.      * @Assert\NotBlank()
  29.      * @Assert\Email()
  30.      */
  31.     protected $emailAddress;
  32.  
  33.     /**
  34.      * @ORM\Column(type="string", length=64, nullable=true)
  35.      */
  36.     protected $password;
  37.  
  38.     /**
  39.      * @Assert\NotBlank()
  40.      * @Assert\Length(max=4096)
  41.      */
  42.     protected $plainPassword;
  43.  
  44.     /**
  45.      * @ORM\Column(type="string", length=15)
  46.      */
  47.     protected $role = self::ROLE_USER;
  48.  
  49.     /**
  50.      * @ORM\Column(type="boolean")
  51.      */
  52.     protected $active = true;
  53.  
  54.     /**
  55.      * Set emailAddress
  56.      *
  57.      * @param string $emailAddress
  58.      *
  59.      * @return Person
  60.      */
  61.     public function setEmailAddress($emailAddress)
  62.     {
  63.  
  64.         $this->emailAddress = $emailAddress;
  65.  
  66.         return $this;
  67.     }
  68.  
  69.     /**
  70.      * Get emailAddress
  71.      *
  72.      * @return string
  73.      */
  74.     public function getEmailAddress()
  75.     {
  76.  
  77.         return $this->emailAddress;
  78.     }
  79.  
  80.     /**
  81.      * Set password
  82.      *
  83.      * @param string $password
  84.      *
  85.      * @return Person
  86.      */
  87.     public function setPassword($password)
  88.     {
  89.  
  90.         $this->password = password_hash($password, PASSWORD_BCRYPT);
  91.  
  92.         return $this;
  93.     }
  94.  
  95.     /**
  96.      * Get password
  97.      *
  98.      * @return string
  99.      */
  100.     public function getPassword()
  101.     {
  102.  
  103.         return $this->password;
  104.     }
  105.  
  106.     /**
  107.      * @return mixed
  108.      */
  109.     public function getPlainPassword()
  110.     {
  111.  
  112.         return $this->plainPassword;
  113.     }
  114.  
  115.     /**
  116.      * @param mixed $plainPassword
  117.      *
  118.      * @return $this
  119.      */
  120.     public function setPlainPassword($plainPassword)
  121.     {
  122.  
  123.         $this->plainPassword = $plainPassword;
  124.  
  125.         return $this;
  126.     }
  127.  
  128.     /**
  129.      * Set role
  130.      *
  131.      * @param string $role
  132.      *
  133.      * @return $this
  134.      */
  135.     public function setRole($role)
  136.     {
  137.  
  138.         $this->role = $role;
  139.  
  140.         return $this;
  141.     }
  142.  
  143.     /**
  144.      * Get role
  145.      *
  146.      * @return string
  147.      */
  148.     public function getRole()
  149.     {
  150.  
  151.         return $this->role;
  152.     }
  153.  
  154.     public function serialize()
  155.     {
  156.  
  157.         return serialize(array(
  158.             $this->id,
  159.             $this->slug,
  160.             $this->password
  161.         ));
  162.     }
  163.  
  164.     public function unserialize($serialized)
  165.     {
  166.  
  167.         list (
  168.             $this->id,
  169.             $this->slug,
  170.             $this->password
  171.         ) = unserialize($serialized);
  172.     }
  173.  
  174.     public function getRoles()
  175.     {
  176.  
  177.         return [$this->getRole()];
  178.     }
  179.  
  180.     public function getSalt()
  181.     {
  182.  
  183.         return null;
  184.     }
  185.  
  186.     public function getUsername()
  187.     {
  188.  
  189.         return $this->emailAddress;
  190.     }
  191.  
  192.     public function eraseCredentials()
  193.     {
  194.         // TODO: Implement eraseCredentials() method.
  195.     }
  196.  
  197.     public function isAccountNonExpired()
  198.     {
  199.  
  200.         return true;
  201.     }
  202.  
  203.     public function isAccountNonLocked()
  204.     {
  205.  
  206.         return true;
  207.     }
  208.  
  209.     public function isCredentialsNonExpired()
  210.     {
  211.  
  212.         return true;
  213.     }
  214.  
  215.     public function isEnabled()
  216.     {
  217.  
  218.         return $this->active;
  219.     }
  220.  
  221.     /**
  222.      * Set active
  223.      *
  224.      * @param boolean $active
  225.      *
  226.      * @return Person
  227.      */
  228.     public function setActive($active)
  229.     {
  230.         $this->active = $active;
  231.  
  232.         return $this;
  233.     }
  234.  
  235.     /**
  236.      * Get active
  237.      *
  238.      * @return boolean
  239.      */
  240.     public function getActive()
  241.     {
  242.         return $this->active;
  243.     }
  244. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement