]> git.mxchange.org Git - friendica.git/commitdiff
Rearranged function order
authorMichael <heluecht@pirati.ca>
Tue, 8 Jun 2021 08:56:01 +0000 (08:56 +0000)
committerMichael <heluecht@pirati.ca>
Tue, 8 Jun 2021 08:56:01 +0000 (08:56 +0000)
src/Security/BasicAuth.php
src/Security/OAuth.php

index fe42e61e91d17c7444ce4df7970b38b729ac7e72..e55700bf9e8c350f8c3c069dc842da024001711f 100644 (file)
@@ -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;
-       }
 }
index 005628094756d5cb018a7023ac6e645ef3bfba93..64a942bba73eacd14bb93b50bbcebccb2c09b2ef 100644 (file)
@@ -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;
        }
 
        /**