Get user from database.
@param User|string|integer $user User ID.
@return User
@throws Exception
491879
protected function getUser($user)
    {
        $userClass = $this->checkUserClass();
        if (is_numeric($user)) {
            $user = $userClass::find()->id($user)->one();
        } elseif (is_string($user) && strlen($user)) {
            $user = $userClass::find()->guid($user)->one();
        }
        if (!$user || $user->getIsNewRecord()) {
            throw new Exception('User Not Registered.');
        }
        return $user;
    }
817882
protected function getUser()
    {
        trigger_error('DrupalSubContextBase::getUser() is deprecated. Use RawDrupalContext::getUserManager()->getCurrentUser() instead.', E_USER_DEPRECATED);

        $user = $this->getUserManager()->getCurrentUser();

        if (empty($user)) {
            throw new \Exception('No user is logged in.');
        }

        return $user;
    }
988966
public function getUserByUsername($username)
    {
        try {
            $user = $this->userRepo->loadUserByUsername($username);
        } catch (\Exception $e) {
            $user = null;
        }

        return $user;
    }
839038
public static function getById($uid)
    {    
		if ($uid == USER_ANONYMOUS) return new User\Anonymous();
        $fields = self::getDbConnection()->fetchAssoc( 'SELECT * FROM '.User::TABLE.' WHERE id = ?', array( $uid ) );
        if (!$fields) throw new \Exception('User:'.$uid.' is not found'); 
        return self::fetch($fields);    
  	}
812923
public function getByUsername ($username)
    {
        $entity = $this->er->findOneBy(array('username' => $username));

        if (NULL == $entity) {
            throw new Exception("User not found: username=$username");
        }

        return $this->getModel($entity);
    }
361846
public function getSettingsByUser($user)
    {
        $userId = $user;
        $userEntity = null;
        if ($user instanceof EntityInterface) {
            $userId = $user->getId();
            $userEntity = $user;
        }
        if (isset($this->settingsByUser[$userId])) {
            return $this->settingsByUser[$user];
        }
        if (empty($userEntity)) {
            $UserRepository = $this->getUserRepository();
            $userEntity = $UserRepository->find($userId);
        }
        
        if (isset($userEntity)) {
            $settingsData = $userEntity->getSettings();
            $this->settingsByUser[$userId] = new SettingsEntity($this);
            $this->settingsByUser[$userId]->setData($settingsData)->spawnAsEntities();
            return $this->settingsByUser[$userId];
        }
        return null;
    }
291344
protected function getUserEntity() : ?User
    {
        if (!$this->userEntity && $this->userId)
        {
            $this->userEntity = $this->userRepository->findOneById($this->userId);
        }

        return $this->userEntity;
    }
1320824
public function setUser($user)
    {
        if (\is_object($user)) {
            $this->userObject = $user;
            $this->user       = $user->getId();
        } else {
            $this->userObject = null;
            $this->user       = $user;
        }

        return $this;
    }
207776
public function getUser()
    {
        if (null === $token = $this->securityContext->getToken()) {
            return;
        }

        if (!is_object($user = $token->getUser())) {
            return;
        }

        return $user;
    }
1160632
public function login($username, $password)
    {
        $user = $this->getUserByField("username", $username);

        if ($password === null) {
            throw new Exception("Empty password field.");
        }

        if ($user->id === null) {
            throw new Exception("Error, not valid credentials.");
        }

        if ($user->deleted !== null) {
            throw new Exception("User deleted.");
        }

        if ((int)$user->enabled === 0) {
            throw new Exception("Error, disabled account.");
        }

        if ($this->validatePassword($password, $user->password)) {
            $this->session->set("user", $user);
            return true;
        }
        throw new Exception("Error, not valid credentials.");
    }
1017064
function getUser($sid) {
		if ($this->user == null) {
			$this->user = $this->getUserFromSession($sid);
		}
        return $this->user;
    }
870678
public function _getPasswordFromDB($user)
    {
        $sql  = 'SELECT * FROM users WHERE code = :uname AND state >=1';
        $stmt = $this->db->prepare($sql);
        $stmt->execute(array(':uname' => $token->getUserName()));
        $row = $stmt->fetch(PDO::FETCH_ASSOC);
        return $row['password'];

    }
889958
protected function getUserId($user)
    {
        if (is_null($user))
        {
            $user = auth()->user();
        }

        if ($user instanceof Model)
        {
            $user = $user->getKey();
        }

        return $user;
    }
834056
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 ($userId && 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->getRepository()->getUser($userId)) {
                return $userEntity->toArray();
            }
        } catch (TableNotFoundException $e) {
            return false;
        }

        return false;
    }
158748
public function loadUser($user)
    {

        $ok = false;
        if (!empty($user->getRecordId())) {
            $id = $user->getRecordId();
            $sql = 'SELECT user_pk, resource_link_pk, lti_user_id, lti_result_sourcedid, created, updated ' .
                   "FROM {$this->dbTableNamePrefix}" . DataConnector::USER_RESULT_TABLE_NAME . ' ' .
                   'WHERE (user_pk = :id)';
            $query = $this->db->prepare($sql);
            $query->bindValue('id', $id, PDO::PARAM_INT);
        } else {
            $id = $user->getResourceLink()->getRecordId();
            $uid = $user->getId(ToolProvider\ToolProvider::ID_SCOPE_ID_ONLY);
            $sql = 'SELECT user_pk, resource_link_pk, lti_user_id, lti_result_sourcedid, created, updated ' .
                   "FROM {$this->dbTableNamePrefix}" . DataConnector::USER_RESULT_TABLE_NAME . ' ' .
                   'WHERE (resource_link_pk = :id) AND (lti_user_id = :uid)';
            $query = $this->db->prepare($sql);
            $query->bindValue('id', $id, PDO::PARAM_INT);
            $query->bindValue('uid', $uid, PDO::PARAM_STR);
        }
        if ($query->execute()) {
            $row = $query->fetch(PDO::FETCH_ASSOC);
            if ($row !== false) {
                $row = array_change_key_case($row);
                $user->setRecordId(intval($row['user_pk']));
                $user->setResourceLinkId(intval($row['resource_link_pk']));
                $user->ltiUserId = $row['lti_user_id'];
                $user->ltiResultSourcedId = $row['lti_result_sourcedid'];
                $user->created = strtotime($row['created']);
                $user->updated = strtotime($row['updated']);
                $ok = true;
            }
        }

        return $ok;

    }
1238394
public static function getUser($user_id)
    {
        $sql = new Pluf_SQL('login=%s', array($user_id));
        return Pluf::factory('User')->getOne($sql->gen());
    }
883770
public function getUserMail(User $user)
    {
        $userMail = current($user->getPropertyValues(GenerisRdf::PROPERTY_USER_MAIL));
        
        if (!$userMail || !filter_var($userMail, FILTER_VALIDATE_EMAIL)) {
            throw new Exception('User email is not valid.');
        }
        
        return $userMail;
    }