From 5e7086adc93c501b6fcef8650d6552e95a1b6b28 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Fri, 10 Aug 2012 12:17:13 +0200 Subject: [PATCH] Move login handling to OC class --- index.php | 20 +------------------- lib/base.php | 37 ++++++++++++++++++++++++++++--------- 2 files changed, 29 insertions(+), 28 deletions(-) diff --git a/index.php b/index.php index 12a4d4918d..331d7fae8e 100755 --- a/index.php +++ b/index.php @@ -21,26 +21,8 @@ * */ - $RUNTIME_NOAPPS = TRUE; //no apps, yet require_once('lib/base.php'); -if (!OC::handleRequest()) { -// Not handled -> we display the login page: - OC_App::loadApps(array('prelogin')); - $error = false; - // remember was checked after last login - if (OC::tryRememberLogin()) { - // nothing more to do - - // Someone wants to log in : - } elseif (OC::tryFormLogin()) { - $error = true; - - // The user is already authenticated using Apaches AuthType Basic... very usable in combination with LDAP - } elseif(OC::tryBasicAuthLogin()) { - $error = true; - } - OC_Util::displayLoginPage($error); -} +OC::handleRequest(); diff --git a/lib/base.php b/lib/base.php index 5132a82292..b200da77ba 100644 --- a/lib/base.php +++ b/lib/base.php @@ -389,18 +389,18 @@ class OC{ } /** - * @brief Try to handle request - * @return true when the request is handled here + * @brief Handle the request */ public static function handleRequest() { // Handle WebDAV if($_SERVER['REQUEST_METHOD']=='PROPFIND'){ header('location: '.OC_Helper::linkToRemote('webdav')); - return true; + return; } + // Handle app css files if(substr(OC::$REQUESTEDFILE,-3) == 'css') { self::loadCSSFile(); - return true; + return; } // Someone is logged in : if(OC_User::isLoggedIn()) { @@ -415,9 +415,10 @@ class OC{ self::loadfile(); } } - return true; + return; } - return false; + // Not handled and not logged in + self::handleLogin(); } protected static function loadapp() { @@ -461,7 +462,25 @@ class OC{ } } - public static function tryRememberLogin() { + protected static function handleLogin() { + OC_App::loadApps(array('prelogin')); + $error = false; + // remember was checked after last login + if (OC::tryRememberLogin()) { + // nothing more to do + + // Someone wants to log in : + } elseif (OC::tryFormLogin()) { + $error = true; + + // The user is already authenticated using Apaches AuthType Basic... very usable in combination with LDAP + } elseif (OC::tryBasicAuthLogin()) { + $error = true; + } + OC_Util::displayLoginPage($error); + } + + protected static function tryRememberLogin() { if(!isset($_COOKIE["oc_remember_login"]) || !isset($_COOKIE["oc_token"]) || !isset($_COOKIE["oc_username"]) @@ -484,7 +503,7 @@ class OC{ return true; } - public static function tryFormLogin() { + protected static function tryFormLogin() { if(!isset($_POST["user"]) || !isset($_POST['password']) || !isset($_SESSION['sectoken']) @@ -510,7 +529,7 @@ class OC{ return true; } - public static function tryBasicAuthLogin() { + protected static function tryBasicAuthLogin() { if (!isset($_SERVER["PHP_AUTH_USER"]) || !isset($_SERVER["PHP_AUTH_PW"])){ return false;