Rearranged function order
This commit is contained in:
parent
11c8dfe73a
commit
95cac04540
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,6 +45,39 @@ class OAuth
|
|||
*/
|
||||
protected static $current_token = [];
|
||||
|
||||
/**
|
||||
* Get current user id, returns 0 if not logged in
|
||||
*
|
||||
* @return int User ID
|
||||
*/
|
||||
public static function getCurrentUserID()
|
||||
{
|
||||
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 (int)self::$current_user_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current application token
|
||||
*
|
||||
* @return array token
|
||||
*/
|
||||
public static function getCurrentApplicationToken()
|
||||
{
|
||||
if (empty(self::$current_token)) {
|
||||
self::$current_token = self::getTokenByBearer();
|
||||
}
|
||||
|
||||
return self::$current_token;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the provided scope does exist
|
||||
*
|
||||
|
@ -74,39 +107,6 @@ class OAuth
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current application token
|
||||
*
|
||||
* @return array token
|
||||
*/
|
||||
public static function getCurrentApplicationToken()
|
||||
{
|
||||
if (empty(self::$current_token)) {
|
||||
self::$current_token = self::getTokenByBearer();
|
||||
}
|
||||
|
||||
return self::$current_token;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current user id, returns 0 if not logged in
|
||||
*
|
||||
* @return int User ID
|
||||
*/
|
||||
public static function getCurrentUserID()
|
||||
{
|
||||
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 (int)self::$current_user_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the user token via the Bearer token
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue
Block a user