getUser() public method

Get a user.
public getUser ( string | integer $userId ) : Bolt\Storage\Entity\Users | false
$userId string | integer Either the user's ID, username, or email address.
return Bolt\Storage\Entity\Users | false
Esempio n. 1
0
 /**
  * Get a user, specified by ID, username or email address.
  *
  * @param integer|string $userId
  *
  * @return array|false
  */
 public function getUser($userId)
 {
     if ($userEntity = $this->repository->getUser($userId)) {
         $userEntity->setPassword('**dontchange**');
         return $userEntity->toArray();
     }
     return false;
 }
Esempio n. 2
0
 /**
  * Get a user, specified by ID, username or email address.
  *
  * @param integer|string $userId
  *
  * @return array|false
  */
 public function getUser($userId)
 {
     // Make sure users have been 'got' already.
     $this->getUsers();
     // In most cases by far, we'll request an ID, and we can return it here.
     if (array_key_exists($userId, $this->users)) {
         return $this->users[$userId];
     }
     // Fallback: See if we can get it by username or email address.
     if ($userEntity = $this->repository->getUser($userId)) {
         $userEntity->setPassword('**dontchange**');
         return $userEntity->toArray();
     }
     return false;
 }
Esempio n. 3
0
 /**
  * Get a user, specified by ID, username or email address.
  *
  * @param integer|string $userId
  *
  * @return array|false
  */
 public function getUser($userId)
 {
     // Make sure users have been 'got' already.
     $this->getUsers();
     // In most cases by far, we'll request an ID, and we can return it here.
     if (array_key_exists($userId, $this->users)) {
         return $this->users[$userId];
     }
     // Fallback: See if we can get it by username or email address.
     try {
         if ($userEntity = $this->repository->getUser($userId)) {
             return $userEntity->toArray();
         }
     } catch (TableNotFoundException $e) {
         return false;
     }
     return false;
 }
Esempio n. 4
0
 /**
  * Check the user authentication cookie against what is stored in the
  * database.
  *
  * @param string $authCookie
  *
  * @return boolean
  */
 protected function checkSessionDatabase($authCookie)
 {
     $userAgent = $this->cookieOptions['browseragent'] ? $this->userAgent : null;
     if (!($authTokenEntity = $this->repositoryAuthtoken->getToken($authCookie, $this->remoteIP, $userAgent))) {
         return false;
     }
     if (!($databaseUser = $this->repositoryUsers->getUser($authTokenEntity->getUsername()))) {
         return false;
     }
     // Update session data
     $sessionAuth = new Token\Token($databaseUser, $authTokenEntity);
     $this->session->set('authentication', $sessionAuth);
     // Check if user is _still_ allowed to log on.
     if (!$this->permissions->isAllowed('login', $sessionAuth->getUser()->toArray(), null) || !$sessionAuth->isEnabled()) {
         $this->systemLogger->error('User ' . $sessionAuth->getUser()->getUserName() . ' has been disabled and can not login.', ['event' => 'authentication']);
         return false;
     }
     return $this->checkSessionKeys($sessionAuth);
 }