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
* Attempt at a unified admin class
* 'autoInit' => false/true,
* 'name' => 'liveuser session name',
* 'varname' => 'liveuser session var name'
* 'method' => 'get or post',
* 'username' => 'Form input containing user handle',
* 'password' => 'Form input containing password',
* 'remember' => '(optional) Form checkbox containing <Remember Me> info',
* 'function' => '(optional) Function to be called when accessing a page without logging in first',
* 'force' => 'Should the user be forced to login'
* 'trigger' => 'GET or POST var that triggers the logout process',
* 'redirect' => 'Page path to be redirected to after logout',
* 'function' => '(optional) Function to be called when accessing a page without logging in first',
* 'destroy' => 'Whether to destroy the session on logout'
* // The cookie options are optional. If they are specified, the Remember Me
* // feature is activated.
* 'name' => 'Name of Remember Me cookie',
* 'lifetime' => 'Cookie lifetime in days',
* 'path' => 'Cookie path',
* 'domain' => 'Cookie domain',
* 'secret' => 'Secret key used for cookie value encryption'
* 'authContainers' => array(
* 'connection' => 'db connection object, use this or dsn',
* 'dsn' => 'database dsn, use this or connection',
* 'allowDuplicateHandles' => 0,
* 'authTable' => 'liveuser_users',
* 'authTableCols' => array('user_id' => 'auth_user_id',
* 'lastlogin' => 'lastlogin'
* 'permContainer' => array(
* 'type' => 'DB_Complex',
* 'connection' => 'db connection object, use this or dsn',
* 'dsn' => 'database dsn, use this or connection',
* 'prefix' => 'liveuser_'
* $admin = new LiveUser_Admin($conf, 'FR');
* $found = $admin->getUser(3);
* var_dump($admin->perm->getRights());
* @author Arnaud Limbourg
* @version $Id: Admin.php,v 1.23 2004/04/25 17:12:08 dufuz Exp $
* Name of the current selected auth container
* Array containing the auth objects.
var $_authContainers = array ();
* @param array liveuser conf array
* @param string two letters language code
if (isset ($this->_conf['autoInit']) && $this->_conf['autoInit'] === true ) {
* 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
* creates an instance of an auth object
* @param mixed Array containing the configuration.
* @param string Name of the auth container.
* @return object Returns an object of an auth container
function &_authFactory ($conf, $name = null )
$classname = 'LiveUser_Admin_Auth_Container_' . $conf['type'];
$filename = 'LiveUser/Admin/Auth/Container/' . $conf['type'] . '.php';
@include_once($filename);
'Missing file: '. $filename);
$auth = &new $classname($conf, $name);
* creates an instance of an perm object
* @param mixed Name of array containing the configuration.
* @return object Returns an object of a perm container
function &_permFactory ($conf)
$classname = 'LiveUser_Admin_Perm_Container_' . $conf['type'];
$filename = 'LiveUser/Admin/Perm/Container/' . $conf['type'] . '.php';
@include_once($filename);
'Missing file: '. $filename);
$perm = &new $classname($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])) {
$this->_authContainers[$authName] =
&$this->_authFactory ($this->_conf['authContainers'][$authName], $authName);
$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 = &$this->_permFactory ($this->_conf['permContainer']);
$this->perm->authName = $this->_conf['permContainer']['type'];
$this->perm->setCurrentLanguage ($this->lang);
* 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
* @return boolean true upon success, false otherwise
reset($this->_conf['authContainers']);
$authName = key($this->_conf['authContainers']);
foreach ($this->_conf['authContainers'] as $k => $v) {
if (!isset ($this->_authContainers[$k]) ||
$this->_authContainers[$k] = &$this->_authFactory ($v, $k);
$match = $this->_authContainers[$k]->getUsers (array ('auth_user_id' => $authId));
* 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:
* array('name' => 'name', 'value' => 'asdf', 'type' => 'text'),
* array('name' => 'email', 'value' => 'fleh@example.com', 'type' => 'text')
* $user_id = $admin->addUser('johndoe', 'dummypass', true, null, null, null, $custom);
* Untested: it most likely doesn't work.
* @param string user handle (username)
* @param string user password
* @param boolean is account active ?
* @param integer ID of the owning user.
* @param integer ID of the owning group.
* @param array Array of custom fields to be added
* @return mixed userid or false
function addUser($handle, $password, $active = true , $id = null , $owner_user_id = null ,
$owner_group_id = null , $customFields = array ())
$authId = $this->auth->addUser ($handle, $password, $active, $owner_user_id,
$owner_group_id, $id, $customFields);
'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:
* array('name' => 'name', 'value' => 'asdfUpdated', 'type' => 'text'),
* array('name' => 'email', 'value' => 'fleh@example.comUpdated', 'type' => 'text')
* $admin->updateUser($user_id, 'johndoe', 'dummypass', true, null, null, $custom);
* Untested: it most likely doesn't work.
* @param string user handle (username)
* @param string user password
* @param boolean is account active ?
* @param integer ID of the owning user.
* @param integer ID of the owning group.
* @param array Array of custom fields to be updated
* @return mixed error object or true
function updateUser($authId, $handle, $password, $active = true , $owner_user_id = null ,
$owner_group_id = null , $customFields = array ())
$auth = $this->auth->updateUser ($authId, $handle, $password, $active,
$owner_user_id, $owner_group_id, $customFields);
'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
$this->auth->removeUser ($authId);
$permId = $this->perm->getPermUserId ($authId, $this->perm->authName );
$this->perm->removeUser ($permId);
'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 array custom fields you want to be returned. If not specified
* the basic set of fields is returned. The keys are the
* @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 (), $customFields = array (), $order = null ,
$search = $this->auth->getUsers ($filters, $customFields, $order, $rekey);
'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 array custom fields you want to be returned. If not specified
* the basic set of fields is returned. The keys are the
* @return mixed Array with userinfo if found else error object
function getUser($userId, $customFields = array ())
$user_auth_id = $this->auth->authTableCols ['user_id']['name'];
$type = $this->auth->authTableCols ['user_id']['type'];
$user_auth_id = $this->auth->authTableCols ['user_id'];
$filters = array ($user_auth_id =>
array ('op' => '=', 'value' => $userId, 'cond' => '', 'type' => $type)
$search = $this->auth->getUsers ($filters, $customFields);
'Perm or Auth container couldn\t be started.');
Documentation generated on Mon, 11 Mar 2019 10:16:10 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|