From: Michael Date: Tue, 8 Jun 2021 08:56:01 +0000 (+0000) Subject: Rearranged function order X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=95cac04540804fe6c71010ff87404a4cb21e7939;p=friendica.git Rearranged function order --- diff --git a/src/Security/BasicAuth.php b/src/Security/BasicAuth.php index fe42e61e91..e55700bf9e 100644 --- a/src/Security/BasicAuth.php +++ b/src/Security/BasicAuth.php @@ -38,6 +38,25 @@ class BasicAuth */ protected static $current_token = []; + /** + * Get current user id, returns 0 if $login is set to false and not logged in. + * When $login is true, the execution will stop when not logged in. + * + * @param bool $login Perform a login request if "true" + * + * @return int User ID + */ + public static function getCurrentUserID(bool $login = true) + { + if (empty(self::$current_user_id)) { + api_login(DI::app(), $login); + + self::$current_user_id = api_user(); + } + + return (int)self::$current_user_id; + } + /** * Fetch a dummy application token * @@ -66,23 +85,4 @@ class BasicAuth return self::$current_token; } - - /** - * Get current user id, returns 0 if $login is set to false and not logged in. - * When $login is true, the execution will stop when not logged in. - * - * @param bool $login Perform a login request if "true" - * - * @return int User ID - */ - public static function getCurrentUserID(bool $login = true) - { - if (empty(self::$current_user_id)) { - api_login(DI::app(), $login); - - self::$current_user_id = api_user(); - } - - return (int)self::$current_user_id; - } } diff --git a/src/Security/OAuth.php b/src/Security/OAuth.php index 0056280947..64a942bba7 100644 --- a/src/Security/OAuth.php +++ b/src/Security/OAuth.php @@ -46,32 +46,22 @@ class OAuth protected static $current_token = []; /** - * Check if the provided scope does exist - * - * @param string $scope the requested scope (read, write, follow, push) + * Get current user id, returns 0 if not logged in * - * @return bool "true" if the scope is allowed + * @return int User ID */ - public static function isAllowedScope(string $scope) + public static function getCurrentUserID() { - $token = self::getCurrentApplicationToken(); - - if (empty($token)) { - Logger::notice('Empty application token'); - return false; - } - - if (!isset($token[$scope])) { - Logger::warning('The requested scope does not exist', ['scope' => $scope, 'application' => $token]); - return false; - } - - if (empty($token[$scope])) { - Logger::warning('The requested scope is not allowed', ['scope' => $scope, 'application' => $token]); - return false; + if (empty(self::$current_user_id)) { + $token = self::getCurrentApplicationToken(); + if (!empty($token['uid'])) { + self::$current_user_id = $token['uid']; + } else { + self::$current_user_id = 0; + } } - return true; + return (int)self::$current_user_id; } /** @@ -89,22 +79,32 @@ class OAuth } /** - * Get current user id, returns 0 if not logged in + * Check if the provided scope does exist * - * @return int User ID + * @param string $scope the requested scope (read, write, follow, push) + * + * @return bool "true" if the scope is allowed */ - public static function getCurrentUserID() + public static function isAllowedScope(string $scope) { - if (empty(self::$current_user_id)) { - $token = self::getCurrentApplicationToken(); - if (!empty($token['uid'])) { - self::$current_user_id = $token['uid']; - } else { - self::$current_user_id = 0; - } + $token = self::getCurrentApplicationToken(); + + if (empty($token)) { + Logger::notice('Empty application token'); + return false; } - return (int)self::$current_user_id; + if (!isset($token[$scope])) { + Logger::warning('The requested scope does not exist', ['scope' => $scope, 'application' => $token]); + return false; + } + + if (empty($token[$scope])) { + Logger::warning('The requested scope is not allowed', ['scope' => $scope, 'application' => $token]); + return false; + } + + return true; } /**