Source for file Admin.php
Documentation is available at Admin.php
// LiveUser: A framework for authentication and authorization in PHP applications
// Copyright (C) 2002-2003 Markus Wolff
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
require_once 'LiveUser.php';
* Error related constants definition
define('LIVEUSER_ADMIN_ERROR', -1 );
define('LIVEUSER_ADMIN_ERROR_FILTER', -2 );
define('LIVEUSER_ADMIN_ERROR_DATA', -3 );
define('LIVEUSER_ADMIN_ERROR_QUERY_BUILDER', -4 );
define('LIVEUSER_ADMIN_ERROR_ALREADY_ASSIGNED', -5 );
define('LIVEUSER_ADMIN_ERROR_NOT_SUPPORTED', -6 );
* Attempt at a unified admin class
* $admin = new LiveUser_Admin::factory($conf);
* $found = $admin->getUser(3);
* var_dump($admin->perm->getRights());
* @see LiveUser::factory()
* @author Arnaud Limbourg
* @version $Id: Admin.php,v 1.19 2004/12/18 22:05:27 lsmith Exp $
* Name of the current selected auth container
* Array containing the auth objects.
var $_authContainers = array ();
* Error codes to message mapping array
var $_errorMessages = array (
LIVEUSER_ADMIN_ERROR => 'An error occurred %msg%',
LIVEUSER_ADMIN_ERROR_FILTER => 'There\'s something obscure with the filter array, key %key%',
LIVEUSER_ADMIN_ERROR_DATA => 'There\'s something obscure with the data array, key %key%',
LIVEUSER_ADMIN_ERROR_QUERY_BUILDER => 'Couldn\'t create the query, reason: %reason%',
LIVEUSER_ADMIN_ERROR_ALREADY_ASSIGNED => 'That given %field1% has already been assigned to %field2%',
LIVEUSER_ADMIN_ERROR_NOT_SUPPORTED => 'This method is not supported'
* used for error logging by ErrorStack
$this->_stack = &PEAR_ErrorStack ::singleton ('LiveUser_Admin');
if ($GLOBALS['_LIVEUSER_DEBUG']) {
$winlog = &Log ::factory ('win', 'LiveUser_Admin');
$this->_log->addChild ($winlog);
$this->_stack->setErrorMessageTemplate ($this->_errorMessages);
* This method lazy loads PEAR::Log
$this->_log = &Log ::factory ('composite');
$this->_stack->setLogger ($this->_log);
* Add error logger for use by Errorstack.
* Be aware that if you need add a log
* at the beginning of your code if you
* want it to be effective. A log will only
* be taken into account after it's added.
* $lu_object = &LiveUser_Admin::singleton($conf);
* $logger = &Log::factory('mail', 'bug@example.com',
* 'myapp_debug_mail_log', array('from' => 'application_bug@example.com'));
* $lu_object->addErrorLog($logger);
* @param Log logger instance
* @return boolean true on success or false on failure
return $this->_log->addChild ($log);
if (isset ($obj->_options ['autoInit']) && $obj->_options ['autoInit']) {
* Merges the current configuration array with configuration array pases
* along with the method call.
* @param array configuration array
* @return boolean true upon success, false otherwise
$this->_conf = LiveUser ::arrayMergeClobber ($this->_conf, $conf);
* Sets the current auth container to the one with the given auth container name
* Upon success it will return true. You can then
* access the auth backend container by using the
* auth property of this class.
* e.g.: $admin->auth->addUser();
* @param string auth container name
* @return boolean true upon success, false otherwise
if (!isset ($this->_authContainers[$authName])
|| !is_object($this->_authContainers[$authName])
if (!isset ($this->_conf['authContainers'][$authName])) {
$auth = &LiveUser ::authFactory (
$this->_conf['authContainers'][$authName],
array ('msg' => 'Could not create auth container instance'));
$this->_authContainers[$authName] = &$auth;
$this->auth = &$this->_authContainers[$authName];
* Sets the perm container
* Upon success it will return true. You can then
* access the perm backend container by using the
* perm properties of this class.
* e.g.: $admin->perm->addUser();
* @return boolean true upon success, false otherwise
$this->perm = &LiveUser ::permFactory (
$this->_conf['permContainer'],
* Tries to find a user in any of the auth container.
* Upon success it will return true. You can then
* access the backend container by using the auth
* and perm properties of this class.
* e.g.: $admin->perm->updateAuthUserId();
* @param mixed user auth id
* @param string auth container name
* @return boolean true upon success, false otherwise
reset($this->_conf['authContainers']);
$authName = key($this->_conf['authContainers']);
foreach ($this->_conf['authContainers'] as $key => $value) {
if (!isset ($this->_authContainers[$key]) ||
$this->_authContainers[$key] = &LiveUser ::authFactory (
$match = $this->_authContainers[$key]->getUsers (
array ('auth_user_id' => $authId)
return (!$perm_res || !$auth_res) ? false : true;
* Tries to add a user to both containers.
* If the optional $id parameter is passed it will be used
* In any case the auth and perm id will be equal when using this method.
* If this behaviour doesn't suit your needs please consider
* using directly the concerned method. This method is just
* implement to simplify things a bit and should satisfy most
* Note type is optional for DB, thus it's needed for MDB and MDB2,
* we recommend that you use type even though you use DB, so if you change to MDB[2],
* it will be no problem for you.
* usage example for addUser:
* $optional = array('is_active' => true);
* $user_id = $admin->addUser('johndoe', 'dummypass', $optional);
* Untested: it most likely doesn't work.
* @param string user handle (username)
* @param string user password
* @param array values for the optional fields
* @param array values for the custom fields
* @param integer permission user type
* @return mixed userid or false
function addUser($handle, $password, $optionalFields = array (), $customFields = array (),
$id = null , $type = LIVEUSER_USER_TYPE_ID )
$authId = $this->auth->addUser ($handle, $password, $optionalFields,
'auth_user_id' => $authId,
return $this->perm->addUser ($data);
$this->_stack->push (LIVEUSER_ADMIN_ERROR, 'exception', array ('msg' => 'Perm or Auth container couldn\t be started.'));
* Tried to changes user data for both containers.
* Note type is optional for DB, thus it's needed for MDB and MDB2,
* we recommend that you use type even though you use DB, so if you change to MDB[2],
* it will be no problem for you.
* usage example for updateUser:
* $optional = array('is_active' => false);
* $admin->updateUser($user_id, 'johndoe', 'dummypass');
* Untested: it most likely doesn't work.
* @param integer permission user id
* @param string user handle (username)
* @param string user password
* @param array values for the optional fields
* @param array values for the custom fields
* @param integer permission user type
* @return mixed error object or true
function updateUser($permId, $handle, $password, $optionalFields = array (),
$customFields = array (), $type = LIVEUSER_USER_TYPE_ID )
$authData = $this->perm->getUsers (array (
'filters' => array ('perm_user_id' => $permId),
'fields' => array ('auth_user_id'))
$authData = reset($authData);
$auth = $this->auth->updateUser ($authData['auth_user_id'], $handle, $password,
$optionalFields, $customFields);
$filters = array ('perm_user_id' => $permId);
return $this->perm->updateUser ($data, $filters);
$this->_stack->push (LIVEUSER_ADMIN_ERROR, 'exception', array ('msg' => 'Perm or Auth container couldn\t be started.'));
* Removes user from both containers
* Untested: it most likely doesn't work.
* @return mixed error object or true
$authData = $this->perm->getUsers (array (
'filters' => array ('perm_user_id' => $permId),
'fields' => array ('auth_user_id'))
$authData = reset($authData);
$result = $this->auth->removeUser ($authData['auth_user_id']);
$filters = array ('perm_user_id' => $permId);
return $this->perm->removeUser ($filters);
$this->_stack->push (LIVEUSER_ADMIN_ERROR, 'exception', array ('msg' => 'Perm or Auth container couldn\t be started.'));
* Searches users with given filters and returns
* all users found with their handle, passwd, auth_user_id
* lastlogin, is_active and the customFields if they are specified
* Untested: it most likely doesn't work.
* @param array filters to apply to fetched data
* @param string if not null 'ORDER BY $order' will be appended to the query
* @param boolean will return an associative array with the auth_user_id
* as the key by using DB::getAssoc() instead of DB::getAll()
* @return mixed error object or array
function searchUsers($filters = array (), $order = null , $rekey = false )
$search = $this->auth->getUsers ($filters, $order, $rekey);
foreach ($search as $key => $user) {
$permFilter['auth_user_id'] = $user['auth_user_id'];
$permData = $this->perm->getUsers (array ('filters' => $permFilter));
$search[$key] = LiveUser ::arrayMergeClobber (reset($permData), $user);
$this->_stack->push (LIVEUSER_ADMIN_ERROR, 'exception', array ('msg' => 'Perm or Auth container couldn\t be started.'));
* Finds and gets userinfo by his userID, customFields can
* Untested: it most likely doesn't work.
* @param mixed Perm User ID
* @return mixed Array with userinfo if found else error object
function getUser($permId, $permFilter = array (), $authFilter = array (),
$permFilter['perm_user_id'] = $permId;
$permData = $this->perm->getUsers (array ('filters' => $permFilter));
'name' => $this->auth->authTableCols ['required']['auth_user_id']['name'],
'value' => $permData['auth_user_id'],
'type' => $this->auth->authTableCols ['required']['auth_user_id']['type'],
$authData = $this->auth->getUsers ($authFilter);
if ($authData === false ) {
return LiveUser ::arrayMergeClobber ($permData, $authData);
$this->_stack->push (LIVEUSER_ADMIN_ERROR, 'exception', array ('msg' => 'Perm or Auth container couldn\t be started.'));
* Wrapper method to get the Error Stack
* @return array an array of the errors
return $this->_stack->getErrors ();
Documentation generated on Mon, 11 Mar 2019 14:00:08 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|