diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2013-10-21 18:58:46 +0200 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2013-10-21 18:58:46 +0200 |
commit | 581cd9bb9c9307894f60d900e82d9a0df83818fc (patch) | |
tree | fa293ed1a4457d780435065d7721e3cd3527b5c7 /lib/private/api.php | |
parent | a1038c271c9df14acf616ea42f713c4d4a9d195c (diff) | |
download | nextcloud-server-581cd9bb9c9307894f60d900e82d9a0df83818fc.tar.gz nextcloud-server-581cd9bb9c9307894f60d900e82d9a0df83818fc.zip |
Support existing sessions within OCS API calls
Diffstat (limited to 'lib/private/api.php')
-rw-r--r-- | lib/private/api.php | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/lib/private/api.php b/lib/private/api.php index 31f3f968d9b..26091657b31 100644 --- a/lib/private/api.php +++ b/lib/private/api.php @@ -46,6 +46,7 @@ class OC_API { * api actions */ protected static $actions = array(); + private static $logoutRequired = false; /** * registers an api call @@ -115,7 +116,9 @@ class OC_API { $formats = array('json', 'xml'); $format = !empty($_GET['format']) && in_array($_GET['format'], $formats) ? $_GET['format'] : 'xml'; - OC_User::logout(); + if (self::$logoutRequired) { + OC_User::logout(); + } self::respond($response, $format); } @@ -235,10 +238,23 @@ class OC_API { * http basic auth * @return string|false (username, or false on failure) */ - private static function loginUser(){ + private static function loginUser(){ + // basic auth $authUser = isset($_SERVER['PHP_AUTH_USER']) ? $_SERVER['PHP_AUTH_USER'] : ''; $authPw = isset($_SERVER['PHP_AUTH_PW']) ? $_SERVER['PHP_AUTH_PW'] : ''; - return OC_User::login($authUser, $authPw) ? $authUser : false; + $return = OC_User::login($authUser, $authPw); + if ($return === true) { + self::$logoutRequired = true; + return $authUser; + } + + // reuse existing login + $loggedIn = OC_User::isLoggedIn(); + if ($loggedIn === true) { + return OC_User::getUser(); + } + + return false; } /** |