summaryrefslogtreecommitdiffstats
path: root/lib/private/api.php
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2013-10-21 18:58:46 +0200
committerThomas Müller <thomas.mueller@tmit.eu>2013-10-21 18:58:46 +0200
commit581cd9bb9c9307894f60d900e82d9a0df83818fc (patch)
treefa293ed1a4457d780435065d7721e3cd3527b5c7 /lib/private/api.php
parenta1038c271c9df14acf616ea42f713c4d4a9d195c (diff)
downloadnextcloud-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.php22
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;
}
/**