Advertisement
Guest User

Untitled

a guest
Jan 31st, 2016
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.59 KB | None | 0 0
  1. <?php
  2. namespace Owl\Document;
  3.  
  4. use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
  5. use Owl\Framework\Security\Acl\ActorInterface;
  6. use Owl\Security\AuthorizationCommandInterface;
  7.  
  8. /**
  9.  * @ODM\Document(collection="users")
  10.  */
  11. class User implements ActorInterface
  12. {
  13.     /**
  14.      * @ODM\Id
  15.      */
  16.     private $id;
  17.  
  18.     /**
  19.      * @ODM\String
  20.      */
  21.     protected $username;
  22.  
  23.     /**
  24.      * @ODM\String
  25.      */
  26.     protected $password;
  27.  
  28.     /**
  29.      * @ODM\Collection
  30.      */
  31.     protected $roles;
  32.  
  33.     /**
  34.      * @ODM\Date
  35.      */
  36.     protected $lastLogin;
  37.  
  38.     /**
  39.      * @return mixed
  40.      */
  41.     public function getUsername()
  42.     {
  43.         return $this->username;
  44.     }
  45.  
  46.     public function changeCredentials($username, $password)
  47.     {
  48.         $this->username = $username;
  49.         $this->password = sha1($password);
  50.     }
  51.  
  52.     public function authorize(AuthorizationCommandInterface $authorization)
  53.     {
  54.         $authorization->execute($this);
  55.         $this->lastLogin = new \DateTimeImmutable();
  56.  
  57.     }
  58.  
  59.     /**
  60.      * @return mixed
  61.      */
  62.     public function getPassword()
  63.     {
  64.         return $this->password;
  65.     }
  66.  
  67.     public function getRoles()
  68.     {
  69.         return $this->roles;
  70.     }
  71.  
  72.     public function hasRole($name)
  73.     {
  74.         return in_array($name, $this->roles);
  75.     }
  76.  
  77.     public function addRole($name)
  78.     {
  79.         $this->roles[] = $name;
  80.     }
  81.  
  82.     public function removeRole($name)
  83.     {
  84.         if(($index = array_search($name, $this->roles)) !== false) {
  85.             unset($this->roles[$index]);
  86.         }
  87.     }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement