Support existing sessions within OCS API calls
This commit is contained in:
parent
a1038c271c
commit
581cd9bb9c
|
@ -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';
|
||||
if (self::$logoutRequired) {
|
||||
OC_User::logout();
|
||||
}
|
||||
|
||||
self::respond($response, $format);
|
||||
}
|
||||
|
@ -236,9 +239,22 @@ class OC_API {
|
|||
* @return string|false (username, or false on failure)
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue