Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace Owl\Document;
- use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
- use Owl\Framework\Security\Acl\ActorInterface;
- use Owl\Security\AuthorizationCommandInterface;
- /**
- * @ODM\Document(collection="users")
- */
- class User implements ActorInterface
- {
- /**
- * @ODM\Id
- */
- private $id;
- /**
- * @ODM\String
- */
- protected $username;
- /**
- * @ODM\String
- */
- protected $password;
- /**
- * @ODM\Collection
- */
- protected $roles;
- /**
- * @ODM\Date
- */
- protected $lastLogin;
- /**
- * @return mixed
- */
- public function getUsername()
- {
- return $this->username;
- }
- public function changeCredentials($username, $password)
- {
- $this->username = $username;
- $this->password = sha1($password);
- }
- public function authorize(AuthorizationCommandInterface $authorization)
- {
- $authorization->execute($this);
- $this->lastLogin = new \DateTimeImmutable();
- }
- /**
- * @return mixed
- */
- public function getPassword()
- {
- return $this->password;
- }
- public function getRoles()
- {
- return $this->roles;
- }
- public function hasRole($name)
- {
- return in_array($name, $this->roles);
- }
- public function addRole($name)
- {
- $this->roles[] = $name;
- }
- public function removeRole($name)
- {
- if(($index = array_search($name, $this->roles)) !== false) {
- unset($this->roles[$index]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement