示例#1
0
文件: api.php 项目: nem0xff/core
 /**
  * http basic auth
  * @return string|false (username, or false on failure)
  */
 private static function loginUser()
 {
     if (self::$isLoggedIn === true) {
         return \OC_User::getUser();
     }
     // reuse existing login
     $loggedIn = OC_User::isLoggedIn();
     if ($loggedIn === true) {
         $ocsApiRequest = isset($_SERVER['HTTP_OCS_APIREQUEST']) ? $_SERVER['HTTP_OCS_APIREQUEST'] === 'true' : false;
         if ($ocsApiRequest) {
             // initialize the user's filesystem
             \OC_Util::setUpFS(\OC_User::getUser());
             self::$isLoggedIn = true;
             return OC_User::getUser();
         }
         return false;
     }
     // basic auth - because OC_User::login will create a new session we shall only try to login
     // if user and pass are set
     if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) {
         $authUser = $_SERVER['PHP_AUTH_USER'];
         $authPw = $_SERVER['PHP_AUTH_PW'];
         $return = OC_User::login($authUser, $authPw);
         if ($return === true) {
             self::$logoutRequired = true;
             // initialize the user's filesystem
             \OC_Util::setUpFS(\OC_User::getUser());
             self::$isLoggedIn = true;
             return \OC_User::getUser();
         }
     }
     return false;
 }
示例#2
0
 /**
  * http basic auth
  * @return string|false (username, or false on failure)
  */
 private static function loginUser()
 {
     if (self::$isLoggedIn === true) {
         return \OC_User::getUser();
     }
     // reuse existing login
     $loggedIn = OC_User::isLoggedIn();
     if ($loggedIn === true) {
         $ocsApiRequest = isset($_SERVER['HTTP_OCS_APIREQUEST']) ? $_SERVER['HTTP_OCS_APIREQUEST'] === 'true' : false;
         if ($ocsApiRequest) {
             // initialize the user's filesystem
             \OC_Util::setUpFS(\OC_User::getUser());
             self::$isLoggedIn = true;
             return OC_User::getUser();
         }
         return false;
     }
     // basic auth - because OC_User::login will create a new session we shall only try to login
     // if user and pass are set
     if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) {
         $authUser = $_SERVER['PHP_AUTH_USER'];
         $authPw = $_SERVER['PHP_AUTH_PW'];
         try {
             $return = OC_User::login($authUser, $authPw);
         } catch (\OC\User\LoginException $e) {
             return false;
         }
         if ($return === true) {
             self::$logoutRequired = true;
             // initialize the user's filesystem
             \OC_Util::setUpFS(\OC_User::getUser());
             self::$isLoggedIn = true;
             /**
              * Add DAV authenticated. This should in an ideal world not be
              * necessary but the iOS App reads cookies from anywhere instead
              * only the DAV endpoint.
              * This makes sure that the cookies will be valid for the whole scope
              * @see https://github.com/owncloud/core/issues/22893
              */
             \OC::$server->getSession()->set(\OCA\DAV\Connector\Sabre\Auth::DAV_AUTHENTICATED, \OC::$server->getUserSession()->getUser()->getUID());
             return \OC_User::getUser();
         }
     }
     return false;
 }
示例#3
0
 /**
  * http basic auth
  * @return string|false (username, or false on failure)
  */
 private static function loginUser()
 {
     // reuse existing login
     $loggedIn = OC_User::isLoggedIn();
     $ocsApiRequest = isset($_SERVER['HTTP_OCS_APIREQUEST']) ? $_SERVER['HTTP_OCS_APIREQUEST'] === 'true' : false;
     if ($loggedIn === true && $ocsApiRequest) {
         // initialize the user's filesystem
         \OC_Util::setUpFS(\OC_User::getUser());
         return OC_User::getUser();
     }
     // 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);
     if ($return === true) {
         self::$logoutRequired = true;
         // initialize the user's filesystem
         \OC_Util::setUpFS(\OC_User::getUser());
         return $authUser;
     }
     return false;
 }
示例#4
0
 /**
  * http basic auth
  * @return string|false (username, or false on failure)
  */
 private static function loginUser()
 {
     if (self::$isLoggedIn === true) {
         return \OC_User::getUser();
     }
     // reuse existing login
     $loggedIn = \OC::$server->getUserSession()->isLoggedIn();
     if ($loggedIn === true) {
         if (\OC::$server->getTwoFactorAuthManager()->needsSecondFactor()) {
             // Do not allow access to OCS until the 2FA challenge was solved successfully
             return false;
         }
         $ocsApiRequest = isset($_SERVER['HTTP_OCS_APIREQUEST']) ? $_SERVER['HTTP_OCS_APIREQUEST'] === 'true' : false;
         if ($ocsApiRequest) {
             // initialize the user's filesystem
             \OC_Util::setupFS(\OC_User::getUser());
             self::$isLoggedIn = true;
             return OC_User::getUser();
         }
         return false;
     }
     // basic auth - because OC_User::login will create a new session we shall only try to login
     // if user and pass are set
     $userSession = \OC::$server->getUserSession();
     $request = \OC::$server->getRequest();
     try {
         $loginSuccess = $userSession->tryTokenLogin($request);
         if (!$loginSuccess) {
             $loginSuccess = $userSession->tryBasicAuthLogin($request);
         }
     } catch (\OC\User\LoginException $e) {
         return false;
     }
     if ($loginSuccess === true) {
         self::$logoutRequired = true;
         // initialize the user's filesystem
         \OC_Util::setupFS(\OC_User::getUser());
         self::$isLoggedIn = true;
         return \OC_User::getUser();
     }
     return false;
 }