Get current user
@todo needs to be refactored
@note we shouldn't have to make another db call here?
510155
public function currentUser()
    {
        try {
            if (!array_key_exists('tokenstorage',$_SESSION)) {
                throw new \Exception('Token storage not found.');
            }
            $storage = $_SESSION['tokenstorage'];
            $username = $storage->getToken()->getUsername();
            // echo print_r($storage->getToken()->getId(), true);
            $users = $this->erdikoUser->getByParams(['email' => $username]);
            if (!count($users)) {
                throw new \Exception('User not found.');
            }
            $user = $users[0];
        } catch (\Exception $e) {
            $user = $this->erdikoUser->getGeneral();
        }
        return $user;
    }
317468
static function current()
    {
        $current = false;

        if (is_user_logged_in()) {
            $current = new static();
            $user = wp_get_current_user();

            // $current->wp_user = $user;
            
            foreach($user->data as $name => $value) {
                $current->$name = $value;
            }   
        }

        return $current;
    }
216961
def get_user(self, username):
        

        sql = '''SELECT * FROM user WHERE username = ?'''
        self._db_curs.execute(sql, (username, ))
        user = self._db_curs.fetchone()
        return user
258880
function() {
      if (Parse.User._currentUser) {
        return Parse.User._currentUser;
      }

      if (Parse.User._currentUserMatchesDisk) {
        
        return Parse.User._currentUser;
      }

      // Load the user from local storage.
      Parse.User._currentUserMatchesDisk = true;

      var userData = Parse.localStorage.getItem(Parse._getParsePath(
          Parse.User._CURRENT_USER_KEY));
      if (!userData) {
        
        return null;
      }
      Parse.User._currentUser = Parse.Object._create("_User");
      Parse.User._currentUser._isCurrentUser = true;

      var json = JSON.parse(userData);
      Parse.User._currentUser.id = json._id;
      delete json._id;
      Parse.User._currentUser._sessionToken = json._sessionToken;
      delete json._sessionToken;
      Parse.User._currentUser._finishFetch(json);

      Parse.User._currentUser._synchronizeAllAuthData();
      Parse.User._currentUser._refreshCache();
      Parse.User._currentUser._opSetQueue = [{}];
      return Parse.User._currentUser;
    }
1077276
def get_current_user(custom_headers:nil)
      response = get_current_user_async(custom_headers:custom_headers).value!
      response.body unless response.nil?
    end
1041910
public function user()
    {
        // If we've already retrieved the user for the current request we can just
        // return it back immediately. We do not want to fetch the user data on
        // every call to this method because that would be tremendously slow.
        if (! is_null($this->user)) {
            return $this->user;
        }

        $user = null;

        $token = $this->getTokenForRequest();

        if (! empty($token)) {
            $user = $this->provider->retrieveByCredentials(
                array($this->storageKey => $token)
            );
        }

        return $this->user = $user;
    }
482373
def current_user(self):
        
        if not hasattr(self, '_serverInfo') or 'username' not in self._serverInfo:

            url = self._get_url('serverInfo')
            r = self._session.get(url, headers=self._options['headers'])

            r_json = json_loads(r)
            if 'x-ausername' in r.headers:
                r_json['username'] = r.headers['x-ausername']
            else:
                r_json['username'] = None
            self._serverInfo = r_json
            # del r_json['self']  # this isn't really an addressable resource
        return self._serverInfo['username']
759193
@GET
    @Path("user")
    @Produces(MediaType.APPLICATION_JSON)
    @HttpCache
    public List<RUserDto> getUsers()
    {
        DbConn cnx = null;
        try
        {
            cnx = Helpers.getDbSession();
            return MetaService.getUsers(cnx);
        }
        finally
        {
            Helpers.closeQuietly(cnx);
        }
    }
259948
public User getCurrentUser() throws ProvisioningApiException {

		try {
			GetUsersSuccessResponse resp = usersApi.getCurrentUser();

			if (!resp.getStatus().getCode().equals(0)) {
				throw new ProvisioningApiException("Error getting current user. Code: " + resp.getStatus().getCode());
			}
            return new User((Map<String, Object>)resp.getData().getUser());

        } catch(ApiException e) {
        	throw new ProvisioningApiException("Error getting current user", e);
        }
	}
531029
def user(id)
      if id
        cached_user = users.detect {|u| u[:id] == id }
        user = cached_user || fetch_user(id)
        self.users << user
        user
      end
    end
303932
function getUserInfoRecursive(callback) {
                getUserInfoRetryCount++;

                if (getUserInfoRetryCount > getUserInfoRetry) {
                    getUserInfoTimeout && clearTimeout(getUserInfoTimeout);

                    getUserInfoRetryCount = 0;

                    fireEvent('error', {
                        code: 6101,
                        message: CHAT_ERRORS[6101],
                        error: null
                    });
                }
                else {
                    getUserInfoTimeout && clearTimeout(getUserInfoTimeout);

                    getUserInfoTimeout = setTimeout(function() {
                        getUserInfoRecursive(callback);
                    }, getUserInfoRetryCount * 10000);

                    return sendMessage({
                        chatMessageVOType: chatMessageVOTypes.USER_INFO,
                        typeCode: params.typeCode
                    }, {
                        onResult: function(result) {
                            var returnData = {
                                hasError: result.hasError,
                                cache: false,
                                errorMessage: result.errorMessage,
                                errorCode: result.errorCode
                            };

                            if (!returnData.hasError) {
                                getUserInfoTimeout && clearTimeout(getUserInfoTimeout);

                                var messageContent = result.result;
                                var currentUser = formatDataToMakeUser(messageContent);

                                /**
                                 * Add current user into cache database #cache
                                 */
                                if (canUseCache) {
                                    if (db) {
                                        db.users
                                            .where('id')
                                            .equals(currentUser.id)
                                            .toArray()
                                            .then(function(users) {
                                                if (users.length > 0 && users[0].id > 0) {
                                                    db.users
                                                        .update(currentUser.id, {
                                                            cellphoneNumber: currentUser.cellphoneNumber,
                                                            email: currentUser.email,
                                                            image: currentUser.image,
                                                            name: currentUser.name
                                                        })
                                                        .catch(function(error) {
                                                            fireEvent('error', {
                                                                code: error.code,
                                                                message: error.message,
                                                                error: error
                                                            });
                                                        });
                                                }
                                                else {
                                                    db.users.put(currentUser)
                                                        .catch(function(error) {
                                                            fireEvent('error', {
                                                                code: error.code,
                                                                message: error.message,
                                                                error: error
                                                            });
                                                        });
                                                }
                                            });
                                    }
                                    else {
                                        fireEvent('error', {
                                            code: 6601,
                                            message: CHAT_ERRORS[6601],
                                            error: null
                                        });
                                    }
                                }

                                resultData = {
                                    user: currentUser
                                };

                                returnData.result = resultData;
                                getUserInfoRetryCount = 0;

                                callback && callback(returnData);

                                /**
                                 * Delete callback so if server pushes response
                                 * before cache, cache won't send data again
                                 */
                                callback = undefined;
                            }
                        }
                    });
                }
            }
665554
def user(user, &block)
      logger.debug "Got user: #{user}"

      @data[:user], @data[:host] = user.to_s.split '@'
      @data[:host] ||= '%'

      instance_eval(&block) if block_given?
    end
630379
public function currentUser()
    {

        // Already initialized
        if (!is_null(static::$currentUser)) {
            return static::$currentUser;
        }

        // Find the current user
        if (!isset($_SESSION['Staq']['loggedUser'])) {
            $user = FALSE;
        } else {
            $user = $this->getUserEntity()->fetchById($_SESSION['Staq']['loggedUser']);
            if (!$user->exists()) {
                $user = FALSE;
            }
        }
        static::$currentUser = $user;
        return static::$currentUser;
    }
1062350
def get_current_user_ids(self, db_read=None):
        
        db_read = db_read or self.db_read

        return self.user_ids.using(db_read)
736803
def current_user
      core_id = Origen::Users::User.current_user_id
      user = app_users.find { |user| user.core_id == core_id }
      user || User.new(core_id)
    end
1046736
protected function getCurrentUser()
    {
        if (!$this->tokenStorage) {
            return;
        }

        if (!$this->tokenStorage->getToken()) {
            return;
        }

        $user = $this->tokenStorage->getToken()->getUser();

        if ($user instanceof UserInterface) {
            return $user;
        }

        return;
    }
38907
function LoadCurrent()
    {
        $this->user = null;
        $userID = null;
        if (isset($_SESSION[self::$sessionParam]))
             $userID = $_SESSION[self::$sessionParam];
        
        if ($userID)
        {
            $user = new User($userID);
            if ($user->Exists())
                $this->user = $user;
        }
        return $this->user !== null;
    }