cvs: pear /Perm_LiveUser LoginManager.php
| From: | Arnaud Limbourg | Date: | Sat, 07 Dec 2002 18:06:17 +0000 |
| Subject: | cvs: pear /Perm_LiveUser LoginManager.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-7767@lists.php.net to get a copy of this message | ||
arnaud Sat Dec 7 13:06:17 2002 EDT
Modified files:
/pear/Perm_LiveUser LoginManager.php
Log:
* slight API change on checkRight
* cosmetic
Index: pear/Perm_LiveUser/LoginManager.php diff -u pear/Perm_LiveUser/LoginManager.php:1.18 pear/Perm_LiveUser/LoginManager.php:1.19 --- pear/Perm_LiveUser/LoginManager.php:1.18 Fri Nov 29 09:34:31 2002 +++ pear/Perm_LiveUser/LoginManager.php Sat Dec 7 13:06:17 2002 @@ -22,7 +22,7 @@ 'XML' => '_readConfigFileXML'); // Include PEAR base class definition -require_once('PEAR.php'); +require_once 'PEAR.php'; /** * Class LoginManager @@ -58,7 +58,7 @@ * Bjoern Schotte, Kristian Koehntopp, Antonio Guerra * * @author Markus Wolff <wolff@21st.de> - * @version $Id: LoginManager.php,v 1.18 2002/11/29 14:34:31 arnaud Exp $ + * @version $Id: LoginManager.php,v 1.19 2002/12/07 18:06:17 arnaud Exp $ **/ class LoginManager extends PEAR { @@ -67,47 +67,47 @@ * @var object **/ var $user = null; - + /** * The permission container object * @var object **/ var $_perm = null; - + /** * The session name to be used for all sessions * @var string **/ var $sessionName; - + /** * The name of the session variable in which the user object * will be stored * @var string **/ var $sessionVarName; - + /** * The variable name for the user handle that comes from a * HTML login form * @var string **/ var $handleParamName; - + /** * The variable name for the password that comes from a * HTML login form * @var string **/ var $passwdParamName; - + /** * The input channel in which to look for login information. * Can be POST for form input or GET for URL input. * @var string [GET|POST] **/ var $loginInputType; - + /** * Name of the GET-Parameter that is being monitored for logging * out. If present, the user object in the session will be @@ -115,14 +115,14 @@ * @var string **/ var $logoutParamName; - + /** * The name for the cookie to store user information in (used * for the "remember me" function). * @var string **/ var $cookieName; - + /** * This flag determines if "remember me" cookies are allowed. If * not, the LoginManager won't even look for a cookie, so login @@ -132,7 +132,7 @@ * @var integer [0|1] **/ var $allowCookies; - + /** * The name of the "remember me" checkbox on a HTML form. If this * is provided via the channel defined in loginInputType (GET or POST), @@ -142,32 +142,32 @@ * @var string **/ var $cookieParamName; - + /** * The lifetime of the "remember me" cookie in days. Note that the * cookie lifetime will be refreshed every time the user logs in. * @var integer **/ var $cookieLifetime; - + /** * The domain for the "remember me" cookie. Example: "21st.de" * @var string **/ var $cookieDomain; - + /** * The path for the "remember me" cookie. Example: "/" * @var string **/ var $cookiePath; - + /** * The URL to redirect to when the user logs out * @var string **/ var $logoutRedirectURL; - + /** * Nested array with the auth containers that shall be queried for user * information. Format: array(1 => array("option1" => "value", ...)) @@ -185,7 +185,7 @@ * @var array **/ var $authContainers = array(); - + /** * Name of the session variable that is used to store information on the * backend in which the user data resides. This is needed to include the @@ -193,62 +193,67 @@ * @var string **/ var $authContainerTypeVar; - + /** * Array of settings for the permission container to use for retrieving - * user rights. If set to FALSE, no permission container will be used. + * user rights. If set to FALSE, no permission container will be used. * If that is the case, all calls to checkRight() will return FALSE. * The array element 'type' must be present for the LoginManager to be able * to include the correct class definition (example: "DB_Complex"). * @var mixed **/ var $permContainer; - + /** * Determines whether or not to destroy the entire session on logout * @var boolean - **/ + */ var $destroySessionOnLogout; - + /** * Function to be called when the user is not logged in. - * + * * @var string */ var $_loginFunction; /** * Is the login function to be used or not - * + * * @var boolean */ var $_callLoginFunction; + /** + * The area on which we are working. + * + * @var mixed + */ + var $_currentArea; - /** * LoginManager::LoginManager() * * Class constructor. Optionally, a valid filepath to an XML configuration * file can be passed. * - * @param string $configFile - * @param string $cacheXML + * @param string $configFile + * @param boolean $options + * @param string $type * @access public - **/ - function LoginManager($configFile = "", $options = false, $type = '') + */ + function LoginManager($configFile = '', $options = false, $type = '') { // Make some basic default settings (in case the config file doesn't // cover everything or doesn't exist $this->_setDefaults(); - + // Read config file (eventually overrides default settings if ($configFile != '') { $this->readConfigFile($configFile, $options, $type); } } - - + /** * Sets some default values * @@ -256,27 +261,27 @@ */ function _setDefaults() { - $this->sessionVarName = "ludata"; + $this->sessionVarName = 'ludata'; $this->sessionName = session_name(); - $this->authContainerTypeVar = "authContainerType"; + $this->authContainerTypeVar = 'authContainerType'; $this->permContainer = false; - $this->handleParamName = "handle"; - $this->passwdParamName = "passwd"; - $this->loginInputType = "POST"; - $this->logoutParamName = "logout"; - $this->cookieName = "loginData"; + $this->handleParamName = 'handle'; + $this->passwdParamName = 'passwd'; + $this->loginInputType = 'POST'; + $this->logoutParamName = 'logout'; + $this->cookieName = 'loginData'; $this->allowCookies = false; - $this->cookieParamName = "useCookie"; + $this->cookieParamName = 'useCookie'; $this->cookieLifetime = 30; - $this->cookieDomain = "localhost"; - $this->cookiePath = "/"; - $this->logoutRedirectURL = ""; + $this->cookieDomain = 'localhost'; + $this->cookiePath = '/'; + $this->logoutRedirectURL = ''; $this->destroySessionOnLogout = true; $this->_callLoginFunction = false; - $this->_loginFunction = ""; + $this->_loginFunction = ''; } - - + + /** * LoginManager::init() * @@ -286,7 +291,6 @@ * Returns true if a user object was successfully retrieved or created. * Otherwise, false is returned. * - * * @return boolean * @access public * @@ -298,29 +302,29 @@ session_name($this->sessionName); // If there's no session yet, start it now session_start(); - + // Determine if user wanted to log out $this->processLogout(); - + // Include needed permission container class if (is_array($this->permContainer)) { $filename = dirname(__FILE__); $filename .= '/Perm/Container/'; - $filename .= $this->permContainer['type'].'.php'; + $filename .= $this->permContainer['type'] . '.php'; if (is_file($filename)) { - include_once($filename); + include_once $filename; } else { - $this->permContainer = FALSE; + $this->permContainer = false; } } - + // Try to fetch user object from session if (!$this->retrieveUserObject()) { if (is_null($this->user)){ $this->tryLogin(); } } - + // Return boolean that indicates whether a user object has been created // or retrieved from session if (is_object($this->user) && $this->user->handle != '') { @@ -329,39 +333,37 @@ return false; } } - - - + /** * Tries to log the user in * by trying all the Auth containers * defined in the configuration file * until there is a success or failure - * + * * @access private */ function tryLogin() { - $handle = ''; - $passwd = ''; - $check_passwd = false; + $handle = ''; + $passwd = ''; + $check_passwd = false; if (isset($_COOKIE[$this->cookieName])) { $handle = $_COOKIE[$this->cookieName]; $passwd = ''; } elseif (isset($_POST[$this->handleParamName]) && isset($_POST[$this->passwdParamName])) { - $check_passwd = true; + $check_passwd = true; // Note: Add check for magic quotes!!! - $handle = stripslashes($_POST[$this->handleParamName]); - $passwd = stripslashes($_POST[$this->passwdParamName]); + $handle = stripslashes($_POST[$this->handleParamName]); + $passwd = stripslashes($_POST[$this->passwdParamName]); } - + if (strlen($handle)>0) { $counter = 0; $userFound = false; $backend_cnt = count($this->authContainers); $backends = &$this->authContainers; - + //loop into auth containers while ($userFound == false && $backend_cnt > $counter) { $classname = 'LiveUser_Auth_Container_'.$backends[$counter]['type']; @@ -376,11 +378,11 @@ $userFound = true; $this->user = $user; $this->user->backendArrayIndex = $counter; - + // Create permission object if (is_array($this->permContainer)) { $permClass = 'LiveUser_Perm_Container_'.$this->permContainer['type']; - include_once(dirname(__FILE__).'/Perm/Container/'.$this->permContainer['type'].'.php'); + include_once dirname(__FILE__) . '/Perm/Container/' . $this->permContainer['type'] . '.php'; if (isset($this->permContainer['connection'])) { $this->_perm = &new $permClass($this->permContainer['connection']); } else { @@ -388,7 +390,7 @@ } $this->_perm->init($this->user->user_id); } - + $this->freeze($counter); } elseif ($user->handle != "") { $userFound = true; @@ -399,60 +401,60 @@ $counter++; } // End loop into backends } elseif ($this->_callLoginFunction && function_exists($this->_loginFunction)) { - call_user_func($this->_loginFunction); + call_user_func($this->_loginFunction); } } - + /** * LoginManager::unfreeze() - * + * * Gets auth and perm container objects back from session and tries * to give them an active database/whatever connection again - * + * * @access private */ function unfreeze() { $this->user = unserialize($_SESSION[$this->sessionVarName]['auth']); - + if (isset($_SESSION[$this->sessionVarName]['perm'])) { $this->_perm = unserialize($_SESSION[$this->sessionVarName]['perm']); } - + // Use the same backend connection as for the first login $i = $this->user->backendArrayIndex; - + //need deeper tests if (isset($this->authContainers[$i]['connection'])) { $this->user->unfreeze($this->authContainers[$i]['connection']); } else { $this->user->unfreeze($this->authContainers[$i]); } - + if (isset($this->permContainer['connection']) && is_object($this->_perm)) { $this->_perm->unfreeze($this->permContainer['connection']); } elseif (is_object($this->_perm)) { $this->_perm->unfreeze($this->permContainer); } } - + /** * LoginManager::freeze() - * + * * Calls the container objects´ freeze methods which should close * their database connections. After that, the container objects are * being serialized and stored in the session. - * - * @param integer + * + * @param integer $counter * @access private - **/ + */ function freeze($counter) { $this->user->freeze(); if (is_object($this->_perm)) { $this->_perm->freeze(); } - + // Bind objects to session $_SESSION[$this->sessionVarName] = array(); $_SESSION[$this->sessionVarName]['auth'] = serialize($this->user); @@ -460,17 +462,17 @@ $_SESSION[$this->sessionVarName]['perm'] = serialize($this->_perm); } $_SESSION[$this->authContainerTypeVar] = $this->authContainers[$counter]['type']; - + $this->setRememberCookie(); } - + /** * LoginManager::setRememberCookie() - * + * * If cookies are allowed, this method checks if the user wanted * a cookie to be set so he doesn´t have to enter handle and password * for his next login. If true, it will set the cookie. - * + * * @access private */ function setRememberCookie() @@ -485,7 +487,7 @@ } } } - + /** * LoginManager::retrieveUserObject() * @@ -498,7 +500,7 @@ function retrieveUserObject() { $success = false; - + if (isset($_SESSION[$this->sessionVarName]['auth'])) { $classFile = dirname(__FILE__); $classFile .= '/Auth/Container/'; @@ -513,7 +515,7 @@ } return $success; } - + /** * LoginManager::processLogout() * @@ -525,32 +527,32 @@ // Has the user tried to logout? if (isset($_GET[$this->logoutParamName]) || isset($_POST[$this->logoutParamName])) { - + // Yes indeed, destroy the session object now! unset($_SESSION[$this->sessionVarName]); - + // If there's a cookie, kill that one too... if (isset($_COOKIE[$this->cookieName])) { $cookieKillTime = time()-86400; setcookie($this->cookieName,"",$cookieKillTime, $this->cookiePath,$this->cookieDomain); } - + // If the session should be destroyed, do so now... if ($this->destroySessionOnLogout == true) { session_destroy(); } - + // Finally, set the LoginManager's internal user object back to NULL $this->user = null; - + // If there's a URL to redirect to on logout, do so - if ($this->logoutRedirectURL != "") { + if ($this->logoutRedirectURL != '') { header("Location: $this->logoutRedirectURL"); } } } - + /** * LoginManager::readConfigFile() * @@ -569,7 +571,7 @@ $tokens = explode('.', $configFile); $type = strtoupper($tokens[count($tokens)-1]); } - + if (in_array($type, array_keys($GLOBALS['LIVEUSER_CONFIG_TYPE']))) { $methodName = $GLOBALS['LIVEUSER_CONFIG_TYPE'][$type]; return $this->$methodName($configFile, $options); @@ -631,10 +633,10 @@ // $enableCache is set to true. if (is_file($configFile)) { // Include PEAR::XML_Tree class definition - require_once('XML/Tree.php'); - $tree = new XML_Tree($configFile); + require_once 'XML/Tree.php'; + $tree =& new XML_Tree($configFile); $t = &$tree->getTreeFromFile(); - + // Iterate through all nodes below the root node foreach ($t->children as $node) { // Check the node name and set the appropriate class property @@ -721,26 +723,59 @@ $this->_perm->application = $appName; } } - + /** * LoginManager::checkRight() * * Wrapper method for the permission object's own checkRight method. * - * @param string $areaName - * @param string $rightName + * @param string $rights a right name or an array of rights + * @param string $autharea name of the area * @return boolean * @access public */ - function checkRight($areaName, $rightName) + function checkRight($rights, $autharea = false) { if (is_object($this->_perm)) { - return ($this->_perm->checkRight($areaName, $rightName)); + $hasright = false; + + if (is_array($rights)) { + foreach($rights as $currentright) { + if ($this->checkRight($currentright, $autharea)) { + $hasright = true; + } else { + $hasright = false; + break; + } + } + } else { + if ($autharea === false) { + $autharea = $this->_currentArea; + } + + // Remember: $rights is a single value at this point! + $hasright = $this->_perm->checkRight($rights, $autharea); + } + + return $hasright; } else { return false; } } - + + /** + * Sets the current Area ID + * for which we wish to check + * rights against. + * + * @access public + * @param int $area the area + */ + function setCurrentArea($area) + { + $this->_currentArea = $area; + } // end func setCurrentArea + /** * LoginManager::checkRightLevel() * @@ -761,7 +796,7 @@ return false; } } - + /** * LoginManager::isLoggedIn() * @@ -780,7 +815,7 @@ return false; } } - + /** * LoginManager::isInactive() * @@ -814,7 +849,7 @@ * If an empty string or a * non-existent function is passed * it deactivates the call. - * + * * @access public * @param string $functionName the name of the function to be called */
Index: pear/Perm_LiveUser/LoginManager.php diff -u pear/Perm_LiveUser/LoginManager.php:1.18 pear/Perm_LiveUser/LoginManager.php:1.19 --- pear/Perm_LiveUser/LoginManager.php:1.18 Fri Nov 29 09:34:31 2002 +++ pear/Perm_LiveUser/LoginManager.php Sat Dec 7 13:06:17 2002 @@ -22,7 +22,7 @@ 'XML' => '_readConfigFileXML'); // Include PEAR base class definition -require_once('PEAR.php'); +require_once 'PEAR.php'; /** * Class LoginManager @@ -58,7 +58,7 @@ * Bjoern Schotte, Kristian Koehntopp, Antonio Guerra * * @author Markus Wolff <wolff@21st.de> - * @version $Id: LoginManager.php,v 1.18 2002/11/29 14:34:31 arnaud Exp $ + * @version $Id: LoginManager.php,v 1.19 2002/12/07 18:06:17 arnaud Exp $ **/ class LoginManager extends PEAR { @@ -67,47 +67,47 @@ * @var object **/ var $user = null; - + /** * The permission container object * @var object **/ var $_perm = null; - + /** * The session name to be used for all sessions * @var string **/ var $sessionName; - + /** * The name of the session variable in which the user object * will be stored * @var string **/ var $sessionVarName; - + /** * The variable name for the user handle that comes from a * HTML login form * @var string **/ var $handleParamName; - + /** * The variable name for the password that comes from a * HTML login form * @var string **/ var $passwdParamName; - + /** * The input channel in which to look for login information. * Can be POST for form input or GET for URL input. * @var string [GET|POST] **/ var $loginInputType; - + /** * Name of the GET-Parameter that is being monitored for logging * out. If present, the user object in the session will be @@ -115,14 +115,14 @@ * @var string **/ var $logoutParamName; - + /** * The name for the cookie to store user information in (used * for the "remember me" function). * @var string **/ var $cookieName; - + /** * This flag determines if "remember me" cookies are allowed. If * not, the LoginManager won't even look for a cookie, so login @@ -132,7 +132,7 @@ * @var integer [0|1] **/ var $allowCookies; - + /** * The name of the "remember me" checkbox on a HTML form. If this * is provided via the channel defined in loginInputType (GET or POST), @@ -142,32 +142,32 @@ * @var string **/ var $cookieParamName; - + /** * The lifetime of the "remember me" cookie in days. Note that the * cookie lifetime will be refreshed every time the user logs in. * @var integer **/ var $cookieLifetime; - + /** * The domain for the "remember me" cookie. Example: "21st.de" * @var string **/ var $cookieDomain; - + /** * The path for the "remember me" cookie. Example: "/" * @var string **/ var $cookiePath; - + /** * The URL to redirect to when the user logs out * @var string **/ var $logoutRedirectURL; - + /** * Nested array with the auth containers that shall be queried for user * information. Format: array(1 => array("option1" => "value", ...)) @@ -185,7 +185,7 @@ * @var array **/ var $authContainers = array(); - + /** * Name of the session variable that is used to store information on the * backend in which the user data resides. This is needed to include the @@ -193,62 +193,67 @@ * @var string **/ var $authContainerTypeVar; - + /** * Array of settings for the permission container to use for retrieving - * user rights. If set to FALSE, no permission container will be used. + * user rights. If set to FALSE, no permission container will be used. * If that is the case, all calls to checkRight() will return FALSE. * The array element 'type' must be present for the LoginManager to be able * to include the correct class definition (example: "DB_Complex"). * @var mixed **/ var $permContainer; - + /** * Determines whether or not to destroy the entire session on logout * @var boolean - **/ + */ var $destroySessionOnLogout; - + /** * Function to be called when the user is not logged in. - * + * * @var string */ var $_loginFunction; /** * Is the login function to be used or not - * + * * @var boolean */ var $_callLoginFunction; + /** + * The area on which we are working. + * + * @var mixed + */ + var $_currentArea; - /** * LoginManager::LoginManager() * * Class constructor. Optionally, a valid filepath to an XML configuration * file can be passed. * - * @param string $configFile - * @param string $cacheXML + * @param string $configFile + * @param boolean $options + * @param string $type * @access public - **/ - function LoginManager($configFile = "", $options = false, $type = '') + */ + function LoginManager($configFile = '', $options = false, $type = '') { // Make some basic default settings (in case the config file doesn't // cover everything or doesn't exist $this->_setDefaults(); - + // Read config file (eventually overrides default settings if ($configFile != '') { $this->readConfigFile($configFile, $options, $type); } } - - + /** * Sets some default values * @@ -256,27 +261,27 @@ */ function _setDefaults() { - $this->sessionVarName = "ludata"; + $this->sessionVarName = 'ludata'; $this->sessionName = session_name(); - $this->authContainerTypeVar = "authContainerType"; + $this->authContainerTypeVar = 'authContainerType'; $this->permContainer = false; - $this->handleParamName = "handle"; - $this->passwdParamName = "passwd"; - $this->loginInputType = "POST"; - $this->logoutParamName = "logout"; - $this->cookieName = "loginData"; + $this->handleParamName = 'handle'; + $this->passwdParamName = 'passwd'; + $this->loginInputType = 'POST'; + $this->logoutParamName = 'logout'; + $this->cookieName = 'loginData'; $this->allowCookies = false; - $this->cookieParamName = "useCookie"; + $this->cookieParamName = 'useCookie'; $this->cookieLifetime = 30; - $this->cookieDomain = "localhost"; - $this->cookiePath = "/"; - $this->logoutRedirectURL = ""; + $this->cookieDomain = 'localhost'; + $this->cookiePath = '/'; + $this->logoutRedirectURL = ''; $this->destroySessionOnLogout = true; $this->_callLoginFunction = false; - $this->_loginFunction = ""; + $this->_loginFunction = ''; } - - + + /** * LoginManager::init() * @@ -286,7 +291,6 @@ * Returns true if a user object was successfully retrieved or created. * Otherwise, false is returned. * - * * @return boolean * @access public * @@ -298,29 +302,29 @@ session_name($this->sessionName); // If there's no session yet, start it now session_start(); - + // Determine if user wanted to log out $this->processLogout(); - + // Include needed permission container class if (is_array($this->permContainer)) { $filename = dirname(__FILE__); $filename .= '/Perm/Container/'; - $filename .= $this->permContainer['type'].'.php'; + $filename .= $this->permContainer['type'] . '.php'; if (is_file($filename)) { - include_once($filename); + include_once $filename; } else { - $this->permContainer = FALSE; + $this->permContainer = false; } } - + // Try to fetch user object from session if (!$this->retrieveUserObject()) { if (is_null($this->user)){ $this->tryLogin(); } } - + // Return boolean that indicates whether a user object has been created // or retrieved from session if (is_object($this->user) && $this->user->handle != '') { @@ -329,39 +333,37 @@ return false; } } - - - + /** * Tries to log the user in * by trying all the Auth containers * defined in the configuration file * until there is a success or failure - * + * * @access private */ function tryLogin() { - $handle = ''; - $passwd = ''; - $check_passwd = false; + $handle = ''; + $passwd = ''; + $check_passwd = false; if (isset($_COOKIE[$this->cookieName])) { $handle = $_COOKIE[$this->cookieName]; $passwd = ''; } elseif (isset($_POST[$this->handleParamName]) && isset($_POST[$this->passwdParamName])) { - $check_passwd = true; + $check_passwd = true; // Note: Add check for magic quotes!!! - $handle = stripslashes($_POST[$this->handleParamName]); - $passwd = stripslashes($_POST[$this->passwdParamName]); + $handle = stripslashes($_POST[$this->handleParamName]); + $passwd = stripslashes($_POST[$this->passwdParamName]); } - + if (strlen($handle)>0) { $counter = 0; $userFound = false; $backend_cnt = count($this->authContainers); $backends = &$this->authContainers; - + //loop into auth containers while ($userFound == false && $backend_cnt > $counter) { $classname = 'LiveUser_Auth_Container_'.$backends[$counter]['type']; @@ -376,11 +378,11 @@ $userFound = true; $this->user = $user; $this->user->backendArrayIndex = $counter; - + // Create permission object if (is_array($this->permContainer)) { $permClass = 'LiveUser_Perm_Container_'.$this->permContainer['type']; - include_once(dirname(__FILE__).'/Perm/Container/'.$this->permContainer['type'].'.php'); + include_once dirname(__FILE__) . '/Perm/Container/' . $this->permContainer['type'] . '.php'; if (isset($this->permContainer['connection'])) { $this->_perm = &new $permClass($this->permContainer['connection']); } else { @@ -388,7 +390,7 @@ } $this->_perm->init($this->user->user_id); } - + $this->freeze($counter); } elseif ($user->handle != "") { $userFound = true; @@ -399,60 +401,60 @@ $counter++; } // End loop into backends } elseif ($this->_callLoginFunction && function_exists($this->_loginFunction)) { - call_user_func($this->_loginFunction); + call_user_func($this->_loginFunction); } } - + /** * LoginManager::unfreeze() - * + * * Gets auth and perm container objects back from session and tries * to give them an active database/whatever connection again - * + * * @access private */ function unfreeze() { $this->user = unserialize($_SESSION[$this->sessionVarName]['auth']); - + if (isset($_SESSION[$this->sessionVarName]['perm'])) { $this->_perm = unserialize($_SESSION[$this->sessionVarName]['perm']); } - + // Use the same backend connection as for the first login $i = $this->user->backendArrayIndex; - + //need deeper tests if (isset($this->authContainers[$i]['connection'])) { $this->user->unfreeze($this->authContainers[$i]['connection']); } else { $this->user->unfreeze($this->authContainers[$i]); } - + if (isset($this->permContainer['connection']) && is_object($this->_perm)) { $this->_perm->unfreeze($this->permContainer['connection']); } elseif (is_object($this->_perm)) { $this->_perm->unfreeze($this->permContainer); } } - + /** * LoginManager::freeze() - * + * * Calls the container objects´ freeze methods which should close * their database connections. After that, the container objects are * being serialized and stored in the session. - * - * @param integer + * + * @param integer $counter * @access private - **/ + */ function freeze($counter) { $this->user->freeze(); if (is_object($this->_perm)) { $this->_perm->freeze(); } - + // Bind objects to session $_SESSION[$this->sessionVarName] = array(); $_SESSION[$this->sessionVarName]['auth'] = serialize($this->user); @@ -460,17 +462,17 @@ $_SESSION[$this->sessionVarName]['perm'] = serialize($this->_perm); } $_SESSION[$this->authContainerTypeVar] = $this->authContainers[$counter]['type']; - + $this->setRememberCookie(); } - + /** * LoginManager::setRememberCookie() - * + * * If cookies are allowed, this method checks if the user wanted * a cookie to be set so he doesn´t have to enter handle and password * for his next login. If true, it will set the cookie. - * + * * @access private */ function setRememberCookie() @@ -485,7 +487,7 @@ } } } - + /** * LoginManager::retrieveUserObject() * @@ -498,7 +500,7 @@ function retrieveUserObject() { $success = false; - + if (isset($_SESSION[$this->sessionVarName]['auth'])) { $classFile = dirname(__FILE__); $classFile .= '/Auth/Container/'; @@ -513,7 +515,7 @@ } return $success; } - + /** * LoginManager::processLogout() * @@ -525,32 +527,32 @@ // Has the user tried to logout? if (isset($_GET[$this->logoutParamName]) || isset($_POST[$this->logoutParamName])) { - + // Yes indeed, destroy the session object now! unset($_SESSION[$this->sessionVarName]); - + // If there's a cookie, kill that one too... if (isset($_COOKIE[$this->cookieName])) { $cookieKillTime = time()-86400; setcookie($this->cookieName,"",$cookieKillTime, $this->cookiePath,$this->cookieDomain); } - + // If the session should be destroyed, do so now... if ($this->destroySessionOnLogout == true) { session_destroy(); } - + // Finally, set the LoginManager's internal user object back to NULL $this->user = null; - + // If there's a URL to redirect to on logout, do so - if ($this->logoutRedirectURL != "") { + if ($this->logoutRedirectURL != '') { header("Location: $this->logoutRedirectURL"); } } } - + /** * LoginManager::readConfigFile() * @@ -569,7 +571,7 @@ $tokens = explode('.', $configFile); $type = strtoupper($tokens[count($tokens)-1]); } - + if (in_array($type, array_keys($GLOBALS['LIVEUSER_CONFIG_TYPE']))) { $methodName = $GLOBALS['LIVEUSER_CONFIG_TYPE'][$type]; return $this->$methodName($configFile, $options); @@ -631,10 +633,10 @@ // $enableCache is set to true. if (is_file($configFile)) { // Include PEAR::XML_Tree class definition - require_once('XML/Tree.php'); - $tree = new XML_Tree($configFile); + require_once 'XML/Tree.php'; + $tree =& new XML_Tree($configFile); $t = &$tree->getTreeFromFile(); - + // Iterate through all nodes below the root node foreach ($t->children as $node) { // Check the node name and set the appropriate class property @@ -721,26 +723,59 @@ $this->_perm->application = $appName; } } - + /** * LoginManager::checkRight() * * Wrapper method for the permission object's own checkRight method. * - * @param string $areaName - * @param string $rightName + * @param string $rights a right name or an array of rights + * @param string $autharea name of the area * @return boolean * @access public */ - function checkRight($areaName, $rightName) + function checkRight($rights, $autharea = false) { if (is_object($this->_perm)) { - return ($this->_perm->checkRight($areaName, $rightName)); + $hasright = false; + + if (is_array($rights)) { + foreach($rights as $currentright) { + if ($this->checkRight($currentright, $autharea)) { + $hasright = true; + } else { + $hasright = false; + break; + } + } + } else { + if ($autharea === false) { + $autharea = $this->_currentArea; + } + + // Remember: $rights is a single value at this point! + $hasright = $this->_perm->checkRight($rights, $autharea); + } + + return $hasright; } else { return false; } } - + + /** + * Sets the current Area ID + * for which we wish to check + * rights against. + * + * @access public + * @param int $area the area + */ + function setCurrentArea($area) + { + $this->_currentArea = $area; + } // end func setCurrentArea + /** * LoginManager::checkRightLevel() * @@ -761,7 +796,7 @@ return false; } } - + /** * LoginManager::isLoggedIn() * @@ -780,7 +815,7 @@ return false; } } - + /** * LoginManager::isInactive() * @@ -814,7 +849,7 @@ * If an empty string or a * non-existent function is passed * it deactivates the call. - * + * * @access public * @param string $functionName the name of the function to be called */