cvs: pear /LiveUser/Auth Common.php DB.php MDB.php MDB2.php PEARAuth.php Session.php XML.php
| From: | Lukas Smith | Date: | Tue, 07 Jun 2005 14:41:18 +0000 |
| Subject: | cvs: pear /LiveUser/Auth Common.php DB.php MDB.php MDB2.php PEARAuth.php Session.php XML.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-32409@lists.php.net to get a copy of this message | ||
lsmith Tue Jun 7 10:41:18 2005 EDT
Modified files:
/pear/LiveUser/Auth Common.php DB.php MDB.php MDB2.php PEARAuth.php
Session.php XML.php
Log:
- migraded to new config layout due to the admin auth container using the admin storage classes
http://cvs.php.net/diff.php/pear/LiveUser/Auth/Common.php?r1=1.21&r2=1.22&ty=u Index: pear/LiveUser/Auth/Common.php diff -u pear/LiveUser/Auth/Common.php:1.21 pear/LiveUser/Auth/Common.php:1.22 --- pear/LiveUser/Auth/Common.php:1.21 Tue Jun 7 05:35:26 2005 +++ pear/LiveUser/Auth/Common.php Tue Jun 7 10:41:17 2005 @@ -40,7 +40,7 @@ * @author Bjoern Kraus <krausbn@php.net> * @copyright 2002-2005 Markus Wolff * @license http://www.gnu.org/licenses/lgpl.txt - * @version CVS: $Id: Common.php,v 1.21 2005/06/07 09:35:26 lsmith Exp $ + * @version CVS: $Id: Common.php,v 1.22 2005/06/07 14:41:17 lsmith Exp $ * @link http://pear.php.net/LiveUser */ @@ -258,25 +258,25 @@ var $externalValues = array(); /** - * Columns of the auth table. - * Associative array with the names of the auth table columns. - * The 'auth_user_id', 'handle' and 'passwd' fields have to be set. - * 'lastlogin' and 'is_active' are optional. - * It doesn't make sense to set only one of the time columns without the - * other. * - * The type attribute is only useful when using MDB or CAPTCHA. + * @access public + * @var array + */ + var $tables = array(); + + /** * + * @access public * @var array + */ + var $fields = array(); + + /** + * * @access public + * @var array */ - var $authTableCols = array( - 'required' => array( - 'auth_user_id' => array('name' => 'auth_user_id', 'type' => 'text'), - 'handle' => array('name' => 'handle', 'type' => 'text'), - 'passwd' => array('name' => 'passwd', 'type' => 'text'), - ), - ); + var $alias = array(); /** * Class constructor. Feel free to override in backend subclasses. @@ -311,6 +311,32 @@ } } } + + if (isset($conf['storage']) && is_array($conf['storage'])) { + $keys = array_keys($conf['storage']); + foreach ($keys as $key) { + if (isset($this->$key)) { + $this->$key =& $conf['storage'][$key]; + } + } + } + + require_once 'LiveUser/Auth/Storage/Globals.php'; + if (empty($this->tables)) { + $this->tables = $GLOBALS['_LiveUser']['auth']['tables']; + } else { + $this->tables = LiveUser::arrayMergeClobber($GLOBALS['_LiveUser']['auth']['tables'], $this->tables); + } + if (empty($this->fields)) { + $this->fields = $GLOBALS['_LiveUser']['auth']['fields']; + } else { + $this->fields = LiveUser::arrayMergeClobber($GLOBALS['_LiveUser']['auth']['fields'], $this->fields); + } + if (empty($this->alias)) { + $this->alias = $GLOBALS['_LiveUser']['auth']['alias']; + } else { + $this->alias = LiveUser::arrayMergeClobber($GLOBALS['_LiveUser']['auth']['alias'], $this->alias); + } } /** @@ -344,9 +370,6 @@ $propertyValues['storedExternalValues'] = $this->propertyValues['storedExternalValues']; } - $propertyValues['custom'] = isset($this->propertyValues['custom']) - ? $this->propertyValues['custom'] : null; - return $propertyValues; } @@ -361,11 +384,7 @@ function unfreeze($propertyValues) { foreach ($propertyValues as $key => $value) { - if (is_array($value)) { - $this->propertyValues[$key] = $value; - } else { - $this->{$key} = $value; - } + $this->{$key} = $value; } return $this->externalValuesMatch(); @@ -557,8 +576,6 @@ $lwhat = strtolower($what); if (isset($this->$what)) { $that = $this->$what; - } elseif (isset($this->propertyValues['custom'][$lwhat])) { - $that = $this->propertyValues['custom'][$lwhat]; } return $that; } http://cvs.php.net/diff.php/pear/LiveUser/Auth/DB.php?r1=1.16&r2=1.17&ty=u Index: pear/LiveUser/Auth/DB.php diff -u pear/LiveUser/Auth/DB.php:1.16 pear/LiveUser/Auth/DB.php:1.17 --- pear/LiveUser/Auth/DB.php:1.16 Thu May 5 14:08:12 2005 +++ pear/LiveUser/Auth/DB.php Tue Jun 7 10:41:17 2005 @@ -40,7 +40,7 @@ * @author Bjoern Kraus <krausbn@php.net> * @copyright 2002-2005 Markus Wolff * @license http://www.gnu.org/licenses/lgpl.txt - * @version CVS: $Id: DB.php,v 1.16 2005/05/05 18:08:12 lsmith Exp $ + * @version CVS: $Id: DB.php,v 1.17 2005/06/07 14:41:17 lsmith Exp $ * @link http://pear.php.net/LiveUser */ @@ -77,37 +77,29 @@ class LiveUser_Auth_DB extends LiveUser_Auth_Common { /** - * dsn to connect to + * dsn that was connected to * - * @var string + * @var object * @access private */ var $dsn = null; /** - * disconnect + * Database connection object. * - * @var boolean - * @access private - */ - var $disconnect = false; - - /** - * PEAR::DB connection object - * - * @var DB + * @var object * @access private */ var $dbc = null; /** - * Auth table - * Table where the auth data is stored. - * + * Table prefix + * Prefix for all db tables the container has. + * * @var string * @access public */ - var $authTable = 'liveuser_users'; + var $prefix = 'liveuser_'; /** * Load the storage container @@ -122,19 +114,19 @@ { parent::init($conf, $containerName); - if (is_array($conf)) { - if (isset($conf['connection']) && - DB::isConnection($conf['connection']) + if (is_array($conf['storage'])) { + if (isset($conf['storage']['connection']) + && DB::isConnection($conf['storage']['connection']) ) { - $this->dbc = &$conf['connection']; - } elseif (isset($conf['dsn'])) { - $this->dsn = $conf['dsn']; + $this->dbc = &$conf['storage']['connection']; + } elseif (isset($conf['storage']['dsn'])) { + $this->dsn = $conf['storage']['dsn']; $options = null; - if (isset($conf['options'])) { - $options = $conf['options']; + if (isset($conf['storage']['options'])) { + $options = $conf['storage']['options']; } $options['portability'] = DB_PORTABILITY_ALL; - $this->dbc =& DB::connect($conf['dsn'], $options); + $this->dbc =& DB::connect($conf['storage']['dsn'], $options); if (PEAR::isError($this->dbc)) { $this->_stack->push(LIVEUSER_ERROR_INIT_ERROR, 'error', array('container' => 'could not connect: '.$this->dbc->getMessage())); @@ -156,14 +148,14 @@ */ function _updateUserData() { - if (!isset($this->authTableCols['optional']['lastlogin'])) { + if (!isset($this->tables['users']['fields']['lastlogin'])) { return true; } - $sql = 'UPDATE ' . $this->authTable.' - SET ' . $this->authTableCols['optional']['lastlogin']['name'] . '=' . + $sql = 'UPDATE ' . $this->prefix . $this->alias['users'].' + SET ' . $this->alias['lastlogin'] . '=' . $this->dbc->quoteSmart(date('Y-m-d H:i:s', $this->currentLogin)) . ' - WHERE ' . $this->authTableCols['required']['auth_user_id']['name'] . '=' . + WHERE ' . $this->alias['auth_user_id'] . '=' . $this->dbc->quoteSmart($this->authUserId); $result = $this->dbc->query($sql); @@ -202,31 +194,25 @@ function readUserData($handle = '', $passwd = '', $authUserId = false) { $fields = array(); - foreach ($this->authTableCols as $value) { - if (sizeof($value) > 0) { - foreach ($value as $alias => $field_data) { - $fields[] = $field_data['name'] . ' AS ' . $alias; - } - } + foreach ($this->tables['users']['fields'] as $field => $req) { + $fields[] = $this->alias[$field] . ' AS ' . $field; } // Setting the default sql query. $sql = 'SELECT ' . implode(',', $fields) . ' - FROM ' . $this->authTable.' + FROM ' . $this->prefix . $this->alias['users'].' WHERE '; if ($authUserId) { - $sql .= $this->authTableCols['required']['auth_user_id']['name'] . '=' + $sql .= $this->alias['auth_user_id'] . '=' . $this->dbc->quoteSmart($this->authUserId); } else { - $sql .= $this->authTableCols['required']['handle']['name'] . '=' + $sql .= $this->alias['handle'] . '=' . $this->dbc->quoteSmart($handle); - if (isset($this->authTableCols['required']['passwd']) - && $this->authTableCols['required']['passwd'] - ) { + if ($this->tables['users']['fields']['passwd']) { // If $passwd is set, try to find the first user with the given // handle and password. - $sql .= ' AND ' . $this->authTableCols['required']['passwd']['name'] . '=' + $sql .= ' AND ' . $this->alias['passwd'] . '=' . $this->dbc->quoteSmart($this->encryptPW($passwd)); } } @@ -248,18 +234,31 @@ return false; } - $this->handle = $result['handle']; - $this->passwd = $this->decryptPW($result['passwd']); - $this->authUserId = $result['auth_user_id']; - $this->isActive = ((!isset($result['is_active']) || $result['is_active'] == 'Y') ? true : false); - $this->lastLogin = !empty($result['lastlogin']) ? - strtotime($result['lastlogin']) : ''; + $this->handle = $result['handle']; + unset($result['handle']); + $this->passwd = $this->decryptPW($result['passwd']); + unset($result['passwd']); + $this->authUserId = $result['auth_user_id']; + unset($result['auth_user_id']); + $this->isActive = ((!isset($result['is_active']) || $result['is_active']) ? true : false); + if (isset($result['is_active'])) { + unset($result['is_active']); + } + $this->lastLogin = isset($result['lastlogin']) ? strtotime($result['lastlogin']) : ''; + if (isset($result['lastlogin'])) { + unset($result['lastlogin']); + } $this->ownerUserId = isset($result['owner_user_id']) ? $result['owner_user_id'] : null; + if (isset($result['owner_user_id'])) { + unset($result['owner_user_id']); + } $this->ownerGroupid = isset($result['owner_group_id']) ? $result['owner_group_id'] : null; - if (isset($this->authTableCols['custom'])) { - foreach ($this->authTableCols['custom'] as $alias => $value) { - $alias = strtolower($alias); - $this->propertyValues['custom'][$alias] = $result[$alias]; + if (isset($result['owner_group_id'])) { + unset($result['owner_group_id']); + } + if (!empty($result)) { + foreach ($result as $name => $value) { + $this->{$name} = $value; } } @@ -275,7 +274,7 @@ */ function disconnect() { - if ($this->disconnect) { + if ($this->dsn) { $result = $this->dbc->disconnect(); if (PEAR::isError($result)) { $this->_stack->push( http://cvs.php.net/diff.php/pear/LiveUser/Auth/MDB.php?r1=1.17&r2=1.18&ty=u Index: pear/LiveUser/Auth/MDB.php diff -u pear/LiveUser/Auth/MDB.php:1.17 pear/LiveUser/Auth/MDB.php:1.18 --- pear/LiveUser/Auth/MDB.php:1.17 Thu May 5 15:53:48 2005 +++ pear/LiveUser/Auth/MDB.php Tue Jun 7 10:41:17 2005 @@ -40,7 +40,7 @@ * @author Bjoern Kraus <krausbn@php.net> * @copyright 2002-2005 Markus Wolff * @license http://www.gnu.org/licenses/lgpl.txt - * @version CVS: $Id: MDB.php,v 1.17 2005/05/05 19:53:48 lsmith Exp $ + * @version CVS: $Id: MDB.php,v 1.18 2005/06/07 14:41:17 lsmith Exp $ * @link http://pear.php.net/LiveUser */ @@ -78,37 +78,29 @@ class LiveUser_Auth_MDB extends LiveUser_Auth_Common { /** - * dsn to connect to + * dsn that was connected to * - * @var string + * @var object * @access private */ var $dsn = null; /** - * disconnect + * Database connection object. * - * @var boolean - * @access private - */ - var $disconnect = false; - - /** - * PEAR::MDB connection object - * - * @var MDB + * @var object * @access private */ var $dbc = null; /** - * Auth table - * Table where the auth data is stored. + * Table prefix + * Prefix for all db tables the container has. * * @var string * @access public */ - var $authTable = 'liveuser_users'; + var $prefix = 'liveuser_'; /** * Load the storage container @@ -123,26 +115,26 @@ { parent::init($conf, $containerName); - if (is_array($conf)) { - if (isset($conf['connection']) && - MDB::isConnection($conf['connection']) + if (is_array($conf['storage'])) { + if (isset($conf['storage']['connection']) + && MDB::isConnection($conf['storage']['connection']) ) { - $this->dbc = &$conf['connection']; - } elseif (isset($conf['dsn'])) { - $this->dsn = $conf['dsn']; + $this->dbc = &$conf['storage']['connection']; + } elseif (isset($conf['storage']['dsn'])) { + $this->dsn = $conf['storage']['dsn']; $function = null; - if (isset($conf['function'])) { - $function = $conf['function']; + if (isset($conf['storage']['function'])) { + $function = $conf['storage']['function']; } $options = null; - if (isset($conf['options'])) { - $options = $conf['options']; + if (isset($conf['storage']['options'])) { + $options = $conf['storage']['options']; } $options['optimize'] = 'portability'; if ($function == 'singleton') { - $this->dbc =& MDB::singleton($conf['dsn'], $options); + $this->dbc =& MDB::singleton($conf['storage']['dsn'], $options); } else { - $this->dbc =& MDB::connect($conf['dsn'], $options); + $this->dbc =& MDB::connect($conf['storage']['dsn'], $options); } if (PEAR::isError($this->dbc)) { $this->_stack->push(LIVEUSER_ERROR_INIT_ERROR, 'error', @@ -165,15 +157,15 @@ */ function _updateUserData() { - if (!isset($this->authTableCols['optional']['lastlogin'])) { + if (!isset($this->tables['users']['fields']['lastlogin'])) { return true; } - $sql = 'UPDATE ' . $this->authTable.' - SET ' . $this->authTableCols['optional']['lastlogin']['name'] - .'=' . $this->dbc->getValue($this->authTableCols['optional']['lastlogin']['type'], MDB_Date::unix2Mdbstamp($this->currentLogin)) . ' - WHERE ' . $this->authTableCols['required']['auth_user_id']['name'] - .'=' . $this->dbc->getValue($this->authTableCols['required']['auth_user_id']['type'], $this->authUserId); + $sql = 'UPDATE ' . $this->prefix . $this->alias['users'].' + SET ' . $this->alias['lastlogin'] + .'=' . $this->dbc->getValue($this->field['lastlogin'], MDB_Date::unix2Mdbstamp($this->currentLogin)) . ' + WHERE ' . $this->alias['auth_user_id'] + .'=' . $this->dbc->getValue($this->field['auth_user_id'], $this->authUserId); $result = $this->dbc->query($sql); @@ -211,33 +203,26 @@ function readUserData($handle = '', $passwd = '', $authUserId = false) { $fields = array(); - foreach ($this->authTableCols as $value) { - if (sizeof($value) > 0) { - foreach ($value as $alias => $field_data) { - $fields[] = $field_data['name'] . ' AS ' . $alias; - $types[] = $field_data['type']; - } - } + foreach ($this->tables['users']['fields'] as $field => $req) { + $fields[] = $this->alias[$field] . ' AS ' . $field; } // Setting the default query. $sql = 'SELECT ' . implode(',', $fields) . ' - FROM ' . $this->authTable . ' + FROM ' . $this->prefix . $this->alias['users'] . ' WHERE '; if ($authUserId) { - $sql .= $this->authTableCols['required']['auth_user_id']['name'] . '=' - . $this->dbc->getValue($this->authTableCols['required']['auth_user_id']['type'], $this->authUserId); + $sql .= $this->alias['auth_user_id'] . '=' + . $this->dbc->getValue($this->field['auth_user_id'], $this->authUserId); } else { - $sql .= $this->authTableCols['required']['handle']['name'] . '=' - . $this->dbc->getValue($this->authTableCols['required']['handle']['type'], $handle); + $sql .= $this->alias['handle'] . '=' + . $this->dbc->getValue($this->field['handle'], $handle); - if (isset($this->authTableCols['required']['passwd']) - && $this->authTableCols['required']['passwd'] - ) { + if ($this->tables['users']['fields']['passwd']) { // If $passwd is set, try to find the first user with the given // handle and password. - $sql .= ' AND ' . $this->authTableCols['required']['passwd']['name'] . '=' - . $this->dbc->getValue($this->authTableCols['required']['passwd']['type'], $this->encryptPW($passwd)); + $sql .= ' AND ' . $this->alias['passwd'] . '=' + . $this->dbc->getValue($this->field['passwd'], $this->encryptPW($passwd)); } } @@ -258,18 +243,31 @@ return false; } - $this->handle = $result['handle']; - $this->passwd = $this->decryptPW($result['passwd']); - $this->authUserId = $result['auth_user_id']; - $this->isActive = ((!isset($result['is_active']) || $result['is_active']) ? true : false); - $this->lastLogin = isset($result['lastlogin'])? - MDB_Date::mdbstamp2Unix($result['lastlogin']):''; + $this->handle = $result['handle']; + unset($result['handle']); + $this->passwd = $this->decryptPW($result['passwd']); + unset($result['passwd']); + $this->authUserId = $result['auth_user_id']; + unset($result['auth_user_id']); + $this->isActive = ((!isset($result['is_active']) || $result['is_active']) ? true : false); + if (isset($result['is_active'])) { + unset($result['is_active']); + } + $this->lastLogin = isset($result['lastlogin']) ? MDB_Date::mdbstamp2Unix($result['lastlogin']) : ''; + if (isset($result['lastlogin'])) { + unset($result['lastlogin']); + } $this->ownerUserId = isset($result['owner_user_id']) ? $result['owner_user_id'] : null; + if (isset($result['owner_user_id'])) { + unset($result['owner_user_id']); + } $this->ownerGroupid = isset($result['owner_group_id']) ? $result['owner_group_id'] : null; - if (isset($this->authTableCols['custom'])) { - foreach ($this->authTableCols['custom'] as $alias => $value) { - $alias = strtolower($alias); - $this->propertyValues['custom'][$alias] = $result[$alias]; + if (isset($result['owner_group_id'])) { + unset($result['owner_group_id']); + } + if (!empty($result)) { + foreach ($result as $name => $value) { + $this->{$name} = $value; } } @@ -285,7 +283,7 @@ */ function disconnect() { - if ($this->disconnect) { + if ($this->dsn) { $result = $this->dbc->disconnect(); if (PEAR::isError($result)) { $this->_stack->push( http://cvs.php.net/diff.php/pear/LiveUser/Auth/MDB2.php?r1=1.17&r2=1.18&ty=u Index: pear/LiveUser/Auth/MDB2.php diff -u pear/LiveUser/Auth/MDB2.php:1.17 pear/LiveUser/Auth/MDB2.php:1.18 --- pear/LiveUser/Auth/MDB2.php:1.17 Thu May 5 14:08:12 2005 +++ pear/LiveUser/Auth/MDB2.php Tue Jun 7 10:41:17 2005 @@ -40,7 +40,7 @@ * @author Bjoern Kraus <krausbn@php.net> * @copyright 2002-2005 Markus Wolff * @license http://www.gnu.org/licenses/lgpl.txt - * @version CVS: $Id: MDB2.php,v 1.17 2005/05/05 18:08:12 lsmith Exp $ + * @version CVS: $Id: MDB2.php,v 1.18 2005/06/07 14:41:17 lsmith Exp $ * @link http://pear.php.net/LiveUser */ @@ -78,37 +78,29 @@ class LiveUser_Auth_MDB2 extends LiveUser_Auth_Common { /** - * dsn to connect to + * dsn that was connected to * - * @var string + * @var object * @access private */ var $dsn = null; /** - * disconnect + * Database connection object. * - * @var boolean - * @access private - */ - var $disconnect = false; - - /** - * PEAR::MDB2 connection object - * - * @var MDB2 + * @var object * @access private */ var $dbc = null; /** - * Auth table - * Table where the auth data is stored. + * Table prefix + * Prefix for all db tables the container has. * * @var string * @access public */ - var $authTable = 'liveuser_users'; + var $prefix = 'liveuser_'; /** * Load the storage container @@ -123,26 +115,26 @@ { parent::init($conf, $containerName); - if (is_array($conf)) { - if (isset($conf['connection']) && - MDB2::isConnection($conf['connection']) + if (is_array($conf['storage'])) { + if (isset($conf['storage']['connection']) + && MDB2::isConnection($conf['storage']['connection']) ) { - $this->dbc = &$conf['connection']; - } elseif (isset($conf['dsn'])) { - $this->dsn = $conf['dsn']; + $this->dbc = &$conf['storage']['connection']; + } elseif (isset($conf['storage']['dsn'])) { + $this->dsn = $conf['storage']['dsn']; $function = null; - if (isset($conf['function'])) { - $function = $conf['function']; + if (isset($conf['storage']['function'])) { + $function = $conf['storage']['function']; } $options = null; - if (isset($conf['options'])) { - $options = $conf['options']; + if (isset($conf['storage']['options'])) { + $options = $conf['storage']['options']; } $options['portability'] = MDB2_PORTABILITY_ALL; if ($function == 'singleton') { - $this->dbc =& MDB2::singleton($conf['dsn'], $options); + $this->dbc =& MDB2::singleton($conf['storage']['dsn'], $options); } else { - $this->dbc =& MDB2::connect($conf['dsn'], $options); + $this->dbc =& MDB2::connect($conf['storage']['dsn'], $options); } if (PEAR::isError($this->dbc)) { $this->_stack->push(LIVEUSER_ERROR_INIT_ERROR, 'error', @@ -165,15 +157,15 @@ */ function _updateUserData() { - if (!isset($this->authTableCols['optional']['lastlogin'])) { + if (!isset($this->tables['users']['fields']['lastlogin'])) { return true; } - $sql = 'UPDATE ' . $this->authTable.' - SET ' . $this->authTableCols['optional']['lastlogin']['name'] - .'=' . $this->dbc->quote(MDB2_Date::unix2Mdbstamp($this->currentLogin), $this->authTableCols['optional']['lastlogin']['type']) . ' - WHERE ' . $this->authTableCols['required']['auth_user_id']['name'] - .'=' . $this->dbc->quote($this->authUserId, $this->authTableCols['required']['auth_user_id']['type']); + $sql = 'UPDATE ' . $this->prefix . $this->alias['users'].' + SET ' . $this->alias['lastlogin'] + .'=' . $this->dbc->quote(MDB2_Date::unix2Mdbstamp($this->currentLogin), $this->fields['lastlogin']) . ' + WHERE ' . $this->alias['auth_user_id'] + .'=' . $this->dbc->quote($this->authUserId, $this->field['auth_user_id']); $result = $this->dbc->query($sql); @@ -212,33 +204,26 @@ function readUserData($handle = '', $passwd = '', $authUserId = false) { $fields = array(); - foreach ($this->authTableCols as $value) { - if (sizeof($value) > 0) { - foreach ($value as $alias => $field_data) { - $fields[] = $field_data['name'] . ' AS ' . $alias; - $types[] = $field_data['type']; - } - } + foreach ($this->tables['users']['fields'] as $field => $req) { + $fields[] = $this->alias[$field] . ' AS ' . $field; } // Setting the default query. $sql = 'SELECT ' . implode(',', $fields) . ' - FROM ' . $this->authTable . ' + FROM ' . $this->prefix . $this->alias['users'] . ' WHERE '; if ($authUserId) { - $sql .= $this->authTableCols['required']['auth_user_id']['name'] . '=' - . $this->dbc->quote($this->authUserId, $this->authTableCols['required']['auth_user_id']['type']); + $sql .= $this->alias['auth_user_id'] . '=' + . $this->dbc->quote($this->authUserId, $this->field['auth_user_id']); } else { - $sql .= $this->authTableCols['required']['handle']['name'] . '=' - . $this->dbc->quote($handle, $this->authTableCols['required']['handle']['type']); + $sql .= $this->alias['handle'] . '=' + . $this->dbc->quote($handle, $this->field['handle']); - if (isset($this->authTableCols['required']['passwd']) - && $this->authTableCols['required']['passwd'] - ) { + if ($this->tables['users']['fields']['passwd']) { // If $passwd is set, try to find the first user with the given // handle and password. - $sql .= ' AND ' . $this->authTableCols['required']['passwd']['name'] . '=' - . $this->dbc->quote($this->encryptPW($passwd), $this->authTableCols['required']['passwd']['type']); + $sql .= ' AND ' . $this->alias['passwd'] . '=' + . $this->dbc->quote($this->encryptPW($passwd), $this->field['passwd']); } } @@ -259,21 +244,33 @@ return false; } - $this->handle = $result['handle']; - $this->passwd = $this->decryptPW($result['passwd']); - $this->authUserId = $result['auth_user_id']; - $this->isActive = ((!isset($result['is_active']) || $result['is_active']) ? true : false); - $this->lastLogin = isset($result['lastlogin'])? - MDB2_Date::mdbstamp2Unix($result['lastlogin']):''; + $this->handle = $result['handle']; + unset($result['handle']); + $this->passwd = $this->decryptPW($result['passwd']); + unset($result['passwd']); + $this->authUserId = $result['auth_user_id']; + unset($result['auth_user_id']); + $this->isActive = ((!isset($result['is_active']) || $result['is_active']) ? true : false); + if (isset($result['is_active'])) { + unset($result['is_active']); + } + $this->lastLogin = isset($result['lastlogin']) ? MDB2_Date::mdbstamp2Unix($result['lastlogin']) : ''; + if (isset($result['lastlogin'])) { + unset($result['lastlogin']); + } $this->ownerUserId = isset($result['owner_user_id']) ? $result['owner_user_id'] : null; + if (isset($result['owner_user_id'])) { + unset($result['owner_user_id']); + } $this->ownerGroupid = isset($result['owner_group_id']) ? $result['owner_group_id'] : null; - if (isset($this->authTableCols['custom'])) { - foreach ($this->authTableCols['custom'] as $alias => $value) { - $alias = strtolower($alias); - $this->propertyValues['custom'][$alias] = $result[$alias]; + if (isset($result['owner_group_id'])) { + unset($result['owner_group_id']); + } + if (!empty($result)) { + foreach ($result as $name => $value) { + $this->{$name} = $value; } } - return true; } @@ -286,7 +283,7 @@ */ function disconnect() { - if ($this->disconnect) { + if ($this->dsn) { $result = $this->dbc->disconnect(); if (PEAR::isError($result)) { $this->_stack->push( http://cvs.php.net/diff.php/pear/LiveUser/Auth/PEARAuth.php?r1=1.11&r2=1.12&ty=u Index: pear/LiveUser/Auth/PEARAuth.php diff -u pear/LiveUser/Auth/PEARAuth.php:1.11 pear/LiveUser/Auth/PEARAuth.php:1.12 --- pear/LiveUser/Auth/PEARAuth.php:1.11 Wed Apr 6 13:16:40 2005 +++ pear/LiveUser/Auth/PEARAuth.php Tue Jun 7 10:41:17 2005 @@ -40,7 +40,7 @@ * @author Bjoern Kraus <krausbn@php.net> * @copyright 2002-2005 Markus Wolff * @license http://www.gnu.org/licenses/lgpl.txt - * @version CVS: $Id: PEARAuth.php,v 1.11 2005/04/06 17:16:40 lsmith Exp $ + * @version CVS: $Id: PEARAuth.php,v 1.12 2005/06/07 14:41:17 lsmith Exp $ * @link http://pear.php.net/LiveUser */ @@ -129,20 +129,18 @@ $this->pearAuth->start(); $this->pearAuth->login(); - $success = false; - // If a user was found, read data into class variables and set // return value to true - if ($this->pearAuth->getAuth()) { - $this->handle = $this->pearAuth->getUsername(); - $this->passwd = $this->encryptPW($this->pearAuth->password); - $this->isActive = true; - $this->authUserId = $this->pearAuth->getUsername(); - $this->lastLogin = ''; - - $success = true; + if (!$this->pearAuth->getAuth()) { + return false } - return $success; + + $this->handle = $this->pearAuth->getUsername(); + $this->passwd = $this->encryptPW($this->pearAuth->password); + $this->isActive = true; + $this->authUserId = $this->pearAuth->getUsername(); + $this->lastLogin = ''; + return true; } } http://cvs.php.net/diff.php/pear/LiveUser/Auth/Session.php?r1=1.9&r2=1.10&ty=u Index: pear/LiveUser/Auth/Session.php diff -u pear/LiveUser/Auth/Session.php:1.9 pear/LiveUser/Auth/Session.php:1.10 --- pear/LiveUser/Auth/Session.php:1.9 Thu May 5 14:08:12 2005 +++ pear/LiveUser/Auth/Session.php Tue Jun 7 10:41:17 2005 @@ -40,7 +40,7 @@ * @author Bjoern Kraus <krausbn@php.net> * @copyright 2002-2005 Markus Wolff * @license http://www.gnu.org/licenses/lgpl.txt - * @version CVS: $Id: Session.php,v 1.9 2005/05/05 18:08:12 lsmith Exp $ + * @version CVS: $Id: Session.php,v 1.10 2005/06/07 14:41:17 lsmith Exp $ * @link http://pear.php.net/LiveUser */ @@ -129,11 +129,9 @@ if ($authUserId) { // where can we get the handle and passwd from? } else { - if (isset($this->authTableCols['required']['passwd']) - && $this->authTableCols['required']['passwd'] - ) { - if (!isset($_SESSION[$this->authTableCols['required']['passwd']['name']]) || - $_SESSION[$this->authTableCols['required']['passwd']['name']] !== $passwd + if ($this->tables['users']['fields']['passwd']) { + if (!isset($_SESSION[$this->alias['passwd']]) || + $_SESSION[$this->alias['passwd']] !== $passwd ) { return false; } http://cvs.php.net/diff.php/pear/LiveUser/Auth/XML.php?r1=1.18&r2=1.19&ty=u Index: pear/LiveUser/Auth/XML.php diff -u pear/LiveUser/Auth/XML.php:1.18 pear/LiveUser/Auth/XML.php:1.19 --- pear/LiveUser/Auth/XML.php:1.18 Thu May 5 15:53:48 2005 +++ pear/LiveUser/Auth/XML.php Tue Jun 7 10:41:17 2005 @@ -40,7 +40,7 @@ * @author Bjoern Kraus <krausbn@php.net> * @copyright 2002-2005 Markus Wolff * @license http://www.gnu.org/licenses/lgpl.txt - * @version CVS: $Id: XML.php,v 1.18 2005/05/05 19:53:48 lsmith Exp $ + * @version CVS: $Id: XML.php,v 1.19 2005/06/07 14:41:17 lsmith Exp $ * @link http://pear.php.net/LiveUser */ @@ -91,31 +91,6 @@ var $userObj = null; /** - * Columns of the auth table. - * Associative array with the names of the auth table columns. - * The 'auth_user_id', 'handle' and 'passwd' fields have to be set. - * 'lastlogin' and 'is_active' are optional. - * It doesn't make sense to set only one of the time columns without the - * other. - * - * The type attribute is only useful when using MDB or CAPTCHA. - * - * @access public - * @var array - */ - var $authTableCols = array( - 'required' => array( - 'auth_user_id' => array('name' => 'userId', 'type' => 'text'), - 'handle' => array('name' => 'handle', 'type' => 'text'), - 'passwd' => array('name' => 'password', 'type' => 'text'), - ), - 'optional' => array( - 'lastlogin' => array('name' => 'lastLogin', 'type' => 'timestamp'), - 'is_active' => array('name' => 'isActive', 'type' => 'boolean') - ) - ); - - /** * Load the storage container * * @param mixed &$conf Name of array containing the configuration. @@ -128,7 +103,7 @@ { parent::init($conf, $containerName); - if (is_array($conf)) { + if (is_array($conf['storage'])) { if (!is_file($this->file)) { if (!is_file(getenv('DOCUMENT_ROOT') . $this->file)) { $this->_stack->push(LIVEUSER_ERROR_INIT_ERROR, 'error', @@ -242,25 +217,24 @@ foreach ($this->tree->root->children as $user) { $result = array(); + $names = array_flip($this->alias); foreach ($user->children as $value) { - $result[$value->name] = $value->content; + if (isset($names[$value->name])) { + $result[$names[$value->name]] = $value->content; + } } if ($authUserId) { - if (isset($result[$this->authTableCols['required']['auth_user_id']['name']]) && - $authUserId === $result[$this->authTableCols['required']['auth_user_id']['name']] + if (isset($result['auth_user_id']) && + $authUserId === $result['auth_user_id'] ) { $success = true; break; } - } elseif (isset($result[$this->authTableCols['required']['handle']['name']]) && - $handle === $result[$this->authTableCols['required']['handle']['name']] - ) { - if (isset($this->authTableCols['required']['passwd']) - && $this->authTableCols['required']['passwd'] - ) { - if (isset($result[$this->authTableCols['required']['passwd']['name']]) && - $this->encryptPW($passwd) === $result[$this->authTableCols['required']['passwd']['name']] + } elseif (isset($result['handle']) && $handle === $result['handle']) { + if ($this->tables['users']['fields']['passwd']) { + if (isset($result['passwd']) && + $this->encryptPW($passwd) === $result['passwd'] ) { $success = true; break; @@ -281,23 +255,34 @@ return false; } - // If a user was found, read data into class variables and save - // the tree object for faster access in the other functions. - $this->handle = $result[$this->authTableCols['required']['handle']['name']]; - $this->passwd = $this->decryptPW($result[$this->authTableCols['required']['passwd']['name']]); - $this->authUserId = $result[$this->authTableCols['required']['auth_user_id']['name']]; - $this->isActive = ((isset($this->authTableCols['optional']['is_active']) && isset($result[$this->authTableCols['optional']['is_active']['name']])) - ? (bool)$result[$this->authTableCols['optional']['is_active']['name']] : false); - $this->lastLogin = ((isset($this->authTableCols['optional']['lastlogin']) && isset($result[$this->authTableCols['optional']['lastlogin']['name']])) - ? $result[$this->authTableCols['optional']['lastlogin']['name']] : null); - $this->ownerUserId = isset($result['ownerUserId']) ? $result['ownerUserId'] : null; - $this->ownerGroupid = isset($result['ownerGroupId']) ? $result['ownerGroupId'] : null; - if (isset($this->authTableCols['custom'])) { - foreach ($this->authTableCols['custom'] as $alias => $value) { - $alias = strtolower($alias); - $this->propertyValues['custom'][$alias] = $result[$alias]; + $this->handle = $result['handle']; + unset($result['handle']); + $this->passwd = $this->decryptPW($result['passwd']); + unset($result['passwd']); + $this->authUserId = $result['auth_user_id']; + unset($result['auth_user_id']); + $this->isActive = ((!isset($result['is_active']) || $result['is_active']) ? true : false); + if (isset($result['is_active'])) { + unset($result['is_active']); + } + $this->lastLogin = isset($result['lastlogin']) ? $result['lastlogin'] : ''; + if (isset($result['lastlogin'])) { + unset($result['lastlogin']); + } + $this->ownerUserId = isset($result['owner_user_id']) ? $result['owner_user_id'] : null; + if (isset($result['owner_user_id'])) { + unset($result['owner_user_id']); + } + $this->ownerGroupid = isset($result['owner_group_id']) ? $result['owner_group_id'] : null; + if (isset($result['owner_group_id'])) { + unset($result['owner_group_id']); + } + if (!empty($result)) { + foreach ($result as $name => $value) { + $this->{$name} = $value; } } + $this->userObj =& $this->tree->root->getElement(array($index)); return true;
http://cvs.php.net/diff.php/pear/LiveUser/Auth/Common.php?r1=1.21&r2=1.22&ty=u Index: pear/LiveUser/Auth/Common.php diff -u pear/LiveUser/Auth/Common.php:1.21 pear/LiveUser/Auth/Common.php:1.22 --- pear/LiveUser/Auth/Common.php:1.21 Tue Jun 7 05:35:26 2005 +++ pear/LiveUser/Auth/Common.php Tue Jun 7 10:41:17 2005 @@ -40,7 +40,7 @@ * @author Bjoern Kraus <krausbn@php.net> * @copyright 2002-2005 Markus Wolff * @license http://www.gnu.org/licenses/lgpl.txt - * @version CVS: $Id: Common.php,v 1.21 2005/06/07 09:35:26 lsmith Exp $ + * @version CVS: $Id: Common.php,v 1.22 2005/06/07 14:41:17 lsmith Exp $ * @link http://pear.php.net/LiveUser */ @@ -258,25 +258,25 @@ var $externalValues = array(); /** - * Columns of the auth table. - * Associative array with the names of the auth table columns. - * The 'auth_user_id', 'handle' and 'passwd' fields have to be set. - * 'lastlogin' and 'is_active' are optional. - * It doesn't make sense to set only one of the time columns without the - * other. * - * The type attribute is only useful when using MDB or CAPTCHA. + * @access public + * @var array + */ + var $tables = array(); + + /** * + * @access public * @var array + */ + var $fields = array(); + + /** + * * @access public + * @var array */ - var $authTableCols = array( - 'required' => array( - 'auth_user_id' => array('name' => 'auth_user_id', 'type' => 'text'), - 'handle' => array('name' => 'handle', 'type' => 'text'), - 'passwd' => array('name' => 'passwd', 'type' => 'text'), - ), - ); + var $alias = array(); /** * Class constructor. Feel free to override in backend subclasses. @@ -311,6 +311,32 @@ } } } + + if (isset($conf['storage']) && is_array($conf['storage'])) { + $keys = array_keys($conf['storage']); + foreach ($keys as $key) { + if (isset($this->$key)) { + $this->$key =& $conf['storage'][$key]; + } + } + } + + require_once 'LiveUser/Auth/Storage/Globals.php'; + if (empty($this->tables)) { + $this->tables = $GLOBALS['_LiveUser']['auth']['tables']; + } else { + $this->tables = LiveUser::arrayMergeClobber($GLOBALS['_LiveUser']['auth']['tables'], $this->tables); + } + if (empty($this->fields)) { + $this->fields = $GLOBALS['_LiveUser']['auth']['fields']; + } else { + $this->fields = LiveUser::arrayMergeClobber($GLOBALS['_LiveUser']['auth']['fields'], $this->fields); + } + if (empty($this->alias)) { + $this->alias = $GLOBALS['_LiveUser']['auth']['alias']; + } else { + $this->alias = LiveUser::arrayMergeClobber($GLOBALS['_LiveUser']['auth']['alias'], $this->alias); + } } /** @@ -344,9 +370,6 @@ $propertyValues['storedExternalValues'] = $this->propertyValues['storedExternalValues']; } - $propertyValues['custom'] = isset($this->propertyValues['custom']) - ? $this->propertyValues['custom'] : null; - return $propertyValues; } @@ -361,11 +384,7 @@ function unfreeze($propertyValues) { foreach ($propertyValues as $key => $value) { - if (is_array($value)) { - $this->propertyValues[$key] = $value; - } else { - $this->{$key} = $value; - } + $this->{$key} = $value; } return $this->externalValuesMatch(); @@ -557,8 +576,6 @@ $lwhat = strtolower($what); if (isset($this->$what)) { $that = $this->$what; - } elseif (isset($this->propertyValues['custom'][$lwhat])) { - $that = $this->propertyValues['custom'][$lwhat]; } return $that; } http://cvs.php.net/diff.php/pear/LiveUser/Auth/DB.php?r1=1.16&r2=1.17&ty=u Index: pear/LiveUser/Auth/DB.php diff -u pear/LiveUser/Auth/DB.php:1.16 pear/LiveUser/Auth/DB.php:1.17 --- pear/LiveUser/Auth/DB.php:1.16 Thu May 5 14:08:12 2005 +++ pear/LiveUser/Auth/DB.php Tue Jun 7 10:41:17 2005 @@ -40,7 +40,7 @@ * @author Bjoern Kraus <krausbn@php.net> * @copyright 2002-2005 Markus Wolff * @license http://www.gnu.org/licenses/lgpl.txt - * @version CVS: $Id: DB.php,v 1.16 2005/05/05 18:08:12 lsmith Exp $ + * @version CVS: $Id: DB.php,v 1.17 2005/06/07 14:41:17 lsmith Exp $ * @link http://pear.php.net/LiveUser */ @@ -77,37 +77,29 @@ class LiveUser_Auth_DB extends LiveUser_Auth_Common { /** - * dsn to connect to + * dsn that was connected to * - * @var string + * @var object * @access private */ var $dsn = null; /** - * disconnect + * Database connection object. * - * @var boolean - * @access private - */ - var $disconnect = false; - - /** - * PEAR::DB connection object - * - * @var DB + * @var object * @access private */ var $dbc = null; /** - * Auth table - * Table where the auth data is stored. - * + * Table prefix + * Prefix for all db tables the container has. + * * @var string * @access public */ - var $authTable = 'liveuser_users'; + var $prefix = 'liveuser_'; /** * Load the storage container @@ -122,19 +114,19 @@ { parent::init($conf, $containerName); - if (is_array($conf)) { - if (isset($conf['connection']) && - DB::isConnection($conf['connection']) + if (is_array($conf['storage'])) { + if (isset($conf['storage']['connection']) + && DB::isConnection($conf['storage']['connection']) ) { - $this->dbc = &$conf['connection']; - } elseif (isset($conf['dsn'])) { - $this->dsn = $conf['dsn']; + $this->dbc = &$conf['storage']['connection']; + } elseif (isset($conf['storage']['dsn'])) { + $this->dsn = $conf['storage']['dsn']; $options = null; - if (isset($conf['options'])) { - $options = $conf['options']; + if (isset($conf['storage']['options'])) { + $options = $conf['storage']['options']; } $options['portability'] = DB_PORTABILITY_ALL; - $this->dbc =& DB::connect($conf['dsn'], $options); + $this->dbc =& DB::connect($conf['storage']['dsn'], $options); if (PEAR::isError($this->dbc)) { $this->_stack->push(LIVEUSER_ERROR_INIT_ERROR, 'error', array('container' => 'could not connect: '.$this->dbc->getMessage())); @@ -156,14 +148,14 @@ */ function _updateUserData() { - if (!isset($this->authTableCols['optional']['lastlogin'])) { + if (!isset($this->tables['users']['fields']['lastlogin'])) { return true; } - $sql = 'UPDATE ' . $this->authTable.' - SET ' . $this->authTableCols['optional']['lastlogin']['name'] . '=' . + $sql = 'UPDATE ' . $this->prefix . $this->alias['users'].' + SET ' . $this->alias['lastlogin'] . '=' . $this->dbc->quoteSmart(date('Y-m-d H:i:s', $this->currentLogin)) . ' - WHERE ' . $this->authTableCols['required']['auth_user_id']['name'] . '=' . + WHERE ' . $this->alias['auth_user_id'] . '=' . $this->dbc->quoteSmart($this->authUserId); $result = $this->dbc->query($sql); @@ -202,31 +194,25 @@ function readUserData($handle = '', $passwd = '', $authUserId = false) { $fields = array(); - foreach ($this->authTableCols as $value) { - if (sizeof($value) > 0) { - foreach ($value as $alias => $field_data) { - $fields[] = $field_data['name'] . ' AS ' . $alias; - } - } + foreach ($this->tables['users']['fields'] as $field => $req) { + $fields[] = $this->alias[$field] . ' AS ' . $field; } // Setting the default sql query. $sql = 'SELECT ' . implode(',', $fields) . ' - FROM ' . $this->authTable.' + FROM ' . $this->prefix . $this->alias['users'].' WHERE '; if ($authUserId) { - $sql .= $this->authTableCols['required']['auth_user_id']['name'] . '=' + $sql .= $this->alias['auth_user_id'] . '=' . $this->dbc->quoteSmart($this->authUserId); } else { - $sql .= $this->authTableCols['required']['handle']['name'] . '=' + $sql .= $this->alias['handle'] . '=' . $this->dbc->quoteSmart($handle); - if (isset($this->authTableCols['required']['passwd']) - && $this->authTableCols['required']['passwd'] - ) { + if ($this->tables['users']['fields']['passwd']) { // If $passwd is set, try to find the first user with the given // handle and password. - $sql .= ' AND ' . $this->authTableCols['required']['passwd']['name'] . '=' + $sql .= ' AND ' . $this->alias['passwd'] . '=' . $this->dbc->quoteSmart($this->encryptPW($passwd)); } } @@ -248,18 +234,31 @@ return false; } - $this->handle = $result['handle']; - $this->passwd = $this->decryptPW($result['passwd']); - $this->authUserId = $result['auth_user_id']; - $this->isActive = ((!isset($result['is_active']) || $result['is_active'] == 'Y') ? true : false); - $this->lastLogin = !empty($result['lastlogin']) ? - strtotime($result['lastlogin']) : ''; + $this->handle = $result['handle']; + unset($result['handle']); + $this->passwd = $this->decryptPW($result['passwd']); + unset($result['passwd']); + $this->authUserId = $result['auth_user_id']; + unset($result['auth_user_id']); + $this->isActive = ((!isset($result['is_active']) || $result['is_active']) ? true : false); + if (isset($result['is_active'])) { + unset($result['is_active']); + } + $this->lastLogin = isset($result['lastlogin']) ? strtotime($result['lastlogin']) : ''; + if (isset($result['lastlogin'])) { + unset($result['lastlogin']); + } $this->ownerUserId = isset($result['owner_user_id']) ? $result['owner_user_id'] : null; + if (isset($result['owner_user_id'])) { + unset($result['owner_user_id']); + } $this->ownerGroupid = isset($result['owner_group_id']) ? $result['owner_group_id'] : null; - if (isset($this->authTableCols['custom'])) { - foreach ($this->authTableCols['custom'] as $alias => $value) { - $alias = strtolower($alias); - $this->propertyValues['custom'][$alias] = $result[$alias]; + if (isset($result['owner_group_id'])) { + unset($result['owner_group_id']); + } + if (!empty($result)) { + foreach ($result as $name => $value) { + $this->{$name} = $value; } } @@ -275,7 +274,7 @@ */ function disconnect() { - if ($this->disconnect) { + if ($this->dsn) { $result = $this->dbc->disconnect(); if (PEAR::isError($result)) { $this->_stack->push( http://cvs.php.net/diff.php/pear/LiveUser/Auth/MDB.php?r1=1.17&r2=1.18&ty=u Index: pear/LiveUser/Auth/MDB.php diff -u pear/LiveUser/Auth/MDB.php:1.17 pear/LiveUser/Auth/MDB.php:1.18 --- pear/LiveUser/Auth/MDB.php:1.17 Thu May 5 15:53:48 2005 +++ pear/LiveUser/Auth/MDB.php Tue Jun 7 10:41:17 2005 @@ -40,7 +40,7 @@ * @author Bjoern Kraus <krausbn@php.net> * @copyright 2002-2005 Markus Wolff * @license http://www.gnu.org/licenses/lgpl.txt - * @version CVS: $Id: MDB.php,v 1.17 2005/05/05 19:53:48 lsmith Exp $ + * @version CVS: $Id: MDB.php,v 1.18 2005/06/07 14:41:17 lsmith Exp $ * @link http://pear.php.net/LiveUser */ @@ -78,37 +78,29 @@ class LiveUser_Auth_MDB extends LiveUser_Auth_Common { /** - * dsn to connect to + * dsn that was connected to * - * @var string + * @var object * @access private */ var $dsn = null; /** - * disconnect + * Database connection object. * - * @var boolean - * @access private - */ - var $disconnect = false; - - /** - * PEAR::MDB connection object - * - * @var MDB + * @var object * @access private */ var $dbc = null; /** - * Auth table - * Table where the auth data is stored. + * Table prefix + * Prefix for all db tables the container has. * * @var string * @access public */ - var $authTable = 'liveuser_users'; + var $prefix = 'liveuser_'; /** * Load the storage container @@ -123,26 +115,26 @@ { parent::init($conf, $containerName); - if (is_array($conf)) { - if (isset($conf['connection']) && - MDB::isConnection($conf['connection']) + if (is_array($conf['storage'])) { + if (isset($conf['storage']['connection']) + && MDB::isConnection($conf['storage']['connection']) ) { - $this->dbc = &$conf['connection']; - } elseif (isset($conf['dsn'])) { - $this->dsn = $conf['dsn']; + $this->dbc = &$conf['storage']['connection']; + } elseif (isset($conf['storage']['dsn'])) { + $this->dsn = $conf['storage']['dsn']; $function = null; - if (isset($conf['function'])) { - $function = $conf['function']; + if (isset($conf['storage']['function'])) { + $function = $conf['storage']['function']; } $options = null; - if (isset($conf['options'])) { - $options = $conf['options']; + if (isset($conf['storage']['options'])) { + $options = $conf['storage']['options']; } $options['optimize'] = 'portability'; if ($function == 'singleton') { - $this->dbc =& MDB::singleton($conf['dsn'], $options); + $this->dbc =& MDB::singleton($conf['storage']['dsn'], $options); } else { - $this->dbc =& MDB::connect($conf['dsn'], $options); + $this->dbc =& MDB::connect($conf['storage']['dsn'], $options); } if (PEAR::isError($this->dbc)) { $this->_stack->push(LIVEUSER_ERROR_INIT_ERROR, 'error', @@ -165,15 +157,15 @@ */ function _updateUserData() { - if (!isset($this->authTableCols['optional']['lastlogin'])) { + if (!isset($this->tables['users']['fields']['lastlogin'])) { return true; } - $sql = 'UPDATE ' . $this->authTable.' - SET ' . $this->authTableCols['optional']['lastlogin']['name'] - .'=' . $this->dbc->getValue($this->authTableCols['optional']['lastlogin']['type'], MDB_Date::unix2Mdbstamp($this->currentLogin)) . ' - WHERE ' . $this->authTableCols['required']['auth_user_id']['name'] - .'=' . $this->dbc->getValue($this->authTableCols['required']['auth_user_id']['type'], $this->authUserId); + $sql = 'UPDATE ' . $this->prefix . $this->alias['users'].' + SET ' . $this->alias['lastlogin'] + .'=' . $this->dbc->getValue($this->field['lastlogin'], MDB_Date::unix2Mdbstamp($this->currentLogin)) . ' + WHERE ' . $this->alias['auth_user_id'] + .'=' . $this->dbc->getValue($this->field['auth_user_id'], $this->authUserId); $result = $this->dbc->query($sql); @@ -211,33 +203,26 @@ function readUserData($handle = '', $passwd = '', $authUserId = false) { $fields = array(); - foreach ($this->authTableCols as $value) { - if (sizeof($value) > 0) { - foreach ($value as $alias => $field_data) { - $fields[] = $field_data['name'] . ' AS ' . $alias; - $types[] = $field_data['type']; - } - } + foreach ($this->tables['users']['fields'] as $field => $req) { + $fields[] = $this->alias[$field] . ' AS ' . $field; } // Setting the default query. $sql = 'SELECT ' . implode(',', $fields) . ' - FROM ' . $this->authTable . ' + FROM ' . $this->prefix . $this->alias['users'] . ' WHERE '; if ($authUserId) { - $sql .= $this->authTableCols['required']['auth_user_id']['name'] . '=' - . $this->dbc->getValue($this->authTableCols['required']['auth_user_id']['type'], $this->authUserId); + $sql .= $this->alias['auth_user_id'] . '=' + . $this->dbc->getValue($this->field['auth_user_id'], $this->authUserId); } else { - $sql .= $this->authTableCols['required']['handle']['name'] . '=' - . $this->dbc->getValue($this->authTableCols['required']['handle']['type'], $handle); + $sql .= $this->alias['handle'] . '=' + . $this->dbc->getValue($this->field['handle'], $handle); - if (isset($this->authTableCols['required']['passwd']) - && $this->authTableCols['required']['passwd'] - ) { + if ($this->tables['users']['fields']['passwd']) { // If $passwd is set, try to find the first user with the given // handle and password. - $sql .= ' AND ' . $this->authTableCols['required']['passwd']['name'] . '=' - . $this->dbc->getValue($this->authTableCols['required']['passwd']['type'], $this->encryptPW($passwd)); + $sql .= ' AND ' . $this->alias['passwd'] . '=' + . $this->dbc->getValue($this->field['passwd'], $this->encryptPW($passwd)); } } @@ -258,18 +243,31 @@ return false; } - $this->handle = $result['handle']; - $this->passwd = $this->decryptPW($result['passwd']); - $this->authUserId = $result['auth_user_id']; - $this->isActive = ((!isset($result['is_active']) || $result['is_active']) ? true : false); - $this->lastLogin = isset($result['lastlogin'])? - MDB_Date::mdbstamp2Unix($result['lastlogin']):''; + $this->handle = $result['handle']; + unset($result['handle']); + $this->passwd = $this->decryptPW($result['passwd']); + unset($result['passwd']); + $this->authUserId = $result['auth_user_id']; + unset($result['auth_user_id']); + $this->isActive = ((!isset($result['is_active']) || $result['is_active']) ? true : false); + if (isset($result['is_active'])) { + unset($result['is_active']); + } + $this->lastLogin = isset($result['lastlogin']) ? MDB_Date::mdbstamp2Unix($result['lastlogin']) : ''; + if (isset($result['lastlogin'])) { + unset($result['lastlogin']); + } $this->ownerUserId = isset($result['owner_user_id']) ? $result['owner_user_id'] : null; + if (isset($result['owner_user_id'])) { + unset($result['owner_user_id']); + } $this->ownerGroupid = isset($result['owner_group_id']) ? $result['owner_group_id'] : null; - if (isset($this->authTableCols['custom'])) { - foreach ($this->authTableCols['custom'] as $alias => $value) { - $alias = strtolower($alias); - $this->propertyValues['custom'][$alias] = $result[$alias]; + if (isset($result['owner_group_id'])) { + unset($result['owner_group_id']); + } + if (!empty($result)) { + foreach ($result as $name => $value) { + $this->{$name} = $value; } } @@ -285,7 +283,7 @@ */ function disconnect() { - if ($this->disconnect) { + if ($this->dsn) { $result = $this->dbc->disconnect(); if (PEAR::isError($result)) { $this->_stack->push( http://cvs.php.net/diff.php/pear/LiveUser/Auth/MDB2.php?r1=1.17&r2=1.18&ty=u Index: pear/LiveUser/Auth/MDB2.php diff -u pear/LiveUser/Auth/MDB2.php:1.17 pear/LiveUser/Auth/MDB2.php:1.18 --- pear/LiveUser/Auth/MDB2.php:1.17 Thu May 5 14:08:12 2005 +++ pear/LiveUser/Auth/MDB2.php Tue Jun 7 10:41:17 2005 @@ -40,7 +40,7 @@ * @author Bjoern Kraus <krausbn@php.net> * @copyright 2002-2005 Markus Wolff * @license http://www.gnu.org/licenses/lgpl.txt - * @version CVS: $Id: MDB2.php,v 1.17 2005/05/05 18:08:12 lsmith Exp $ + * @version CVS: $Id: MDB2.php,v 1.18 2005/06/07 14:41:17 lsmith Exp $ * @link http://pear.php.net/LiveUser */ @@ -78,37 +78,29 @@ class LiveUser_Auth_MDB2 extends LiveUser_Auth_Common { /** - * dsn to connect to + * dsn that was connected to * - * @var string + * @var object * @access private */ var $dsn = null; /** - * disconnect + * Database connection object. * - * @var boolean - * @access private - */ - var $disconnect = false; - - /** - * PEAR::MDB2 connection object - * - * @var MDB2 + * @var object * @access private */ var $dbc = null; /** - * Auth table - * Table where the auth data is stored. + * Table prefix + * Prefix for all db tables the container has. * * @var string * @access public */ - var $authTable = 'liveuser_users'; + var $prefix = 'liveuser_'; /** * Load the storage container @@ -123,26 +115,26 @@ { parent::init($conf, $containerName); - if (is_array($conf)) { - if (isset($conf['connection']) && - MDB2::isConnection($conf['connection']) + if (is_array($conf['storage'])) { + if (isset($conf['storage']['connection']) + && MDB2::isConnection($conf['storage']['connection']) ) { - $this->dbc = &$conf['connection']; - } elseif (isset($conf['dsn'])) { - $this->dsn = $conf['dsn']; + $this->dbc = &$conf['storage']['connection']; + } elseif (isset($conf['storage']['dsn'])) { + $this->dsn = $conf['storage']['dsn']; $function = null; - if (isset($conf['function'])) { - $function = $conf['function']; + if (isset($conf['storage']['function'])) { + $function = $conf['storage']['function']; } $options = null; - if (isset($conf['options'])) { - $options = $conf['options']; + if (isset($conf['storage']['options'])) { + $options = $conf['storage']['options']; } $options['portability'] = MDB2_PORTABILITY_ALL; if ($function == 'singleton') { - $this->dbc =& MDB2::singleton($conf['dsn'], $options); + $this->dbc =& MDB2::singleton($conf['storage']['dsn'], $options); } else { - $this->dbc =& MDB2::connect($conf['dsn'], $options); + $this->dbc =& MDB2::connect($conf['storage']['dsn'], $options); } if (PEAR::isError($this->dbc)) { $this->_stack->push(LIVEUSER_ERROR_INIT_ERROR, 'error', @@ -165,15 +157,15 @@ */ function _updateUserData() { - if (!isset($this->authTableCols['optional']['lastlogin'])) { + if (!isset($this->tables['users']['fields']['lastlogin'])) { return true; } - $sql = 'UPDATE ' . $this->authTable.' - SET ' . $this->authTableCols['optional']['lastlogin']['name'] - .'=' . $this->dbc->quote(MDB2_Date::unix2Mdbstamp($this->currentLogin), $this->authTableCols['optional']['lastlogin']['type']) . ' - WHERE ' . $this->authTableCols['required']['auth_user_id']['name'] - .'=' . $this->dbc->quote($this->authUserId, $this->authTableCols['required']['auth_user_id']['type']); + $sql = 'UPDATE ' . $this->prefix . $this->alias['users'].' + SET ' . $this->alias['lastlogin'] + .'=' . $this->dbc->quote(MDB2_Date::unix2Mdbstamp($this->currentLogin), $this->fields['lastlogin']) . ' + WHERE ' . $this->alias['auth_user_id'] + .'=' . $this->dbc->quote($this->authUserId, $this->field['auth_user_id']); $result = $this->dbc->query($sql); @@ -212,33 +204,26 @@ function readUserData($handle = '', $passwd = '', $authUserId = false) { $fields = array(); - foreach ($this->authTableCols as $value) { - if (sizeof($value) > 0) { - foreach ($value as $alias => $field_data) { - $fields[] = $field_data['name'] . ' AS ' . $alias; - $types[] = $field_data['type']; - } - } + foreach ($this->tables['users']['fields'] as $field => $req) { + $fields[] = $this->alias[$field] . ' AS ' . $field; } // Setting the default query. $sql = 'SELECT ' . implode(',', $fields) . ' - FROM ' . $this->authTable . ' + FROM ' . $this->prefix . $this->alias['users'] . ' WHERE '; if ($authUserId) { - $sql .= $this->authTableCols['required']['auth_user_id']['name'] . '=' - . $this->dbc->quote($this->authUserId, $this->authTableCols['required']['auth_user_id']['type']); + $sql .= $this->alias['auth_user_id'] . '=' + . $this->dbc->quote($this->authUserId, $this->field['auth_user_id']); } else { - $sql .= $this->authTableCols['required']['handle']['name'] . '=' - . $this->dbc->quote($handle, $this->authTableCols['required']['handle']['type']); + $sql .= $this->alias['handle'] . '=' + . $this->dbc->quote($handle, $this->field['handle']); - if (isset($this->authTableCols['required']['passwd']) - && $this->authTableCols['required']['passwd'] - ) { + if ($this->tables['users']['fields']['passwd']) { // If $passwd is set, try to find the first user with the given // handle and password. - $sql .= ' AND ' . $this->authTableCols['required']['passwd']['name'] . '=' - . $this->dbc->quote($this->encryptPW($passwd), $this->authTableCols['required']['passwd']['type']); + $sql .= ' AND ' . $this->alias['passwd'] . '=' + . $this->dbc->quote($this->encryptPW($passwd), $this->field['passwd']); } } @@ -259,21 +244,33 @@ return false; } - $this->handle = $result['handle']; - $this->passwd = $this->decryptPW($result['passwd']); - $this->authUserId = $result['auth_user_id']; - $this->isActive = ((!isset($result['is_active']) || $result['is_active']) ? true : false); - $this->lastLogin = isset($result['lastlogin'])? - MDB2_Date::mdbstamp2Unix($result['lastlogin']):''; + $this->handle = $result['handle']; + unset($result['handle']); + $this->passwd = $this->decryptPW($result['passwd']); + unset($result['passwd']); + $this->authUserId = $result['auth_user_id']; + unset($result['auth_user_id']); + $this->isActive = ((!isset($result['is_active']) || $result['is_active']) ? true : false); + if (isset($result['is_active'])) { + unset($result['is_active']); + } + $this->lastLogin = isset($result['lastlogin']) ? MDB2_Date::mdbstamp2Unix($result['lastlogin']) : ''; + if (isset($result['lastlogin'])) { + unset($result['lastlogin']); + } $this->ownerUserId = isset($result['owner_user_id']) ? $result['owner_user_id'] : null; + if (isset($result['owner_user_id'])) { + unset($result['owner_user_id']); + } $this->ownerGroupid = isset($result['owner_group_id']) ? $result['owner_group_id'] : null; - if (isset($this->authTableCols['custom'])) { - foreach ($this->authTableCols['custom'] as $alias => $value) { - $alias = strtolower($alias); - $this->propertyValues['custom'][$alias] = $result[$alias]; + if (isset($result['owner_group_id'])) { + unset($result['owner_group_id']); + } + if (!empty($result)) { + foreach ($result as $name => $value) { + $this->{$name} = $value; } } - return true; } @@ -286,7 +283,7 @@ */ function disconnect() { - if ($this->disconnect) { + if ($this->dsn) { $result = $this->dbc->disconnect(); if (PEAR::isError($result)) { $this->_stack->push( http://cvs.php.net/diff.php/pear/LiveUser/Auth/PEARAuth.php?r1=1.11&r2=1.12&ty=u Index: pear/LiveUser/Auth/PEARAuth.php diff -u pear/LiveUser/Auth/PEARAuth.php:1.11 pear/LiveUser/Auth/PEARAuth.php:1.12 --- pear/LiveUser/Auth/PEARAuth.php:1.11 Wed Apr 6 13:16:40 2005 +++ pear/LiveUser/Auth/PEARAuth.php Tue Jun 7 10:41:17 2005 @@ -40,7 +40,7 @@ * @author Bjoern Kraus <krausbn@php.net> * @copyright 2002-2005 Markus Wolff * @license http://www.gnu.org/licenses/lgpl.txt - * @version CVS: $Id: PEARAuth.php,v 1.11 2005/04/06 17:16:40 lsmith Exp $ + * @version CVS: $Id: PEARAuth.php,v 1.12 2005/06/07 14:41:17 lsmith Exp $ * @link http://pear.php.net/LiveUser */ @@ -129,20 +129,18 @@ $this->pearAuth->start(); $this->pearAuth->login(); - $success = false; - // If a user was found, read data into class variables and set // return value to true - if ($this->pearAuth->getAuth()) { - $this->handle = $this->pearAuth->getUsername(); - $this->passwd = $this->encryptPW($this->pearAuth->password); - $this->isActive = true; - $this->authUserId = $this->pearAuth->getUsername(); - $this->lastLogin = ''; - - $success = true; + if (!$this->pearAuth->getAuth()) { + return false } - return $success; + + $this->handle = $this->pearAuth->getUsername(); + $this->passwd = $this->encryptPW($this->pearAuth->password); + $this->isActive = true; + $this->authUserId = $this->pearAuth->getUsername(); + $this->lastLogin = ''; + return true; } } http://cvs.php.net/diff.php/pear/LiveUser/Auth/Session.php?r1=1.9&r2=1.10&ty=u Index: pear/LiveUser/Auth/Session.php diff -u pear/LiveUser/Auth/Session.php:1.9 pear/LiveUser/Auth/Session.php:1.10 --- pear/LiveUser/Auth/Session.php:1.9 Thu May 5 14:08:12 2005 +++ pear/LiveUser/Auth/Session.php Tue Jun 7 10:41:17 2005 @@ -40,7 +40,7 @@ * @author Bjoern Kraus <krausbn@php.net> * @copyright 2002-2005 Markus Wolff * @license http://www.gnu.org/licenses/lgpl.txt - * @version CVS: $Id: Session.php,v 1.9 2005/05/05 18:08:12 lsmith Exp $ + * @version CVS: $Id: Session.php,v 1.10 2005/06/07 14:41:17 lsmith Exp $ * @link http://pear.php.net/LiveUser */ @@ -129,11 +129,9 @@ if ($authUserId) { // where can we get the handle and passwd from? } else { - if (isset($this->authTableCols['required']['passwd']) - && $this->authTableCols['required']['passwd'] - ) { - if (!isset($_SESSION[$this->authTableCols['required']['passwd']['name']]) || - $_SESSION[$this->authTableCols['required']['passwd']['name']] !== $passwd + if ($this->tables['users']['fields']['passwd']) { + if (!isset($_SESSION[$this->alias['passwd']]) || + $_SESSION[$this->alias['passwd']] !== $passwd ) { return false; } http://cvs.php.net/diff.php/pear/LiveUser/Auth/XML.php?r1=1.18&r2=1.19&ty=u Index: pear/LiveUser/Auth/XML.php diff -u pear/LiveUser/Auth/XML.php:1.18 pear/LiveUser/Auth/XML.php:1.19 --- pear/LiveUser/Auth/XML.php:1.18 Thu May 5 15:53:48 2005 +++ pear/LiveUser/Auth/XML.php Tue Jun 7 10:41:17 2005 @@ -40,7 +40,7 @@ * @author Bjoern Kraus <krausbn@php.net> * @copyright 2002-2005 Markus Wolff * @license http://www.gnu.org/licenses/lgpl.txt - * @version CVS: $Id: XML.php,v 1.18 2005/05/05 19:53:48 lsmith Exp $ + * @version CVS: $Id: XML.php,v 1.19 2005/06/07 14:41:17 lsmith Exp $ * @link http://pear.php.net/LiveUser */ @@ -91,31 +91,6 @@ var $userObj = null; /** - * Columns of the auth table. - * Associative array with the names of the auth table columns. - * The 'auth_user_id', 'handle' and 'passwd' fields have to be set. - * 'lastlogin' and 'is_active' are optional. - * It doesn't make sense to set only one of the time columns without the - * other. - * - * The type attribute is only useful when using MDB or CAPTCHA. - * - * @access public - * @var array - */ - var $authTableCols = array( - 'required' => array( - 'auth_user_id' => array('name' => 'userId', 'type' => 'text'), - 'handle' => array('name' => 'handle', 'type' => 'text'), - 'passwd' => array('name' => 'password', 'type' => 'text'), - ), - 'optional' => array( - 'lastlogin' => array('name' => 'lastLogin', 'type' => 'timestamp'), - 'is_active' => array('name' => 'isActive', 'type' => 'boolean') - ) - ); - - /** * Load the storage container * * @param mixed &$conf Name of array containing the configuration. @@ -128,7 +103,7 @@ { parent::init($conf, $containerName); - if (is_array($conf)) { + if (is_array($conf['storage'])) { if (!is_file($this->file)) { if (!is_file(getenv('DOCUMENT_ROOT') . $this->file)) { $this->_stack->push(LIVEUSER_ERROR_INIT_ERROR, 'error', @@ -242,25 +217,24 @@ foreach ($this->tree->root->children as $user) { $result = array(); + $names = array_flip($this->alias); foreach ($user->children as $value) { - $result[$value->name] = $value->content; + if (isset($names[$value->name])) { + $result[$names[$value->name]] = $value->content; + } } if ($authUserId) { - if (isset($result[$this->authTableCols['required']['auth_user_id']['name']]) && - $authUserId === $result[$this->authTableCols['required']['auth_user_id']['name']] + if (isset($result['auth_user_id']) && + $authUserId === $result['auth_user_id'] ) { $success = true; break; } - } elseif (isset($result[$this->authTableCols['required']['handle']['name']]) && - $handle === $result[$this->authTableCols['required']['handle']['name']] - ) { - if (isset($this->authTableCols['required']['passwd']) - && $this->authTableCols['required']['passwd'] - ) { - if (isset($result[$this->authTableCols['required']['passwd']['name']]) && - $this->encryptPW($passwd) === $result[$this->authTableCols['required']['passwd']['name']] + } elseif (isset($result['handle']) && $handle === $result['handle']) { + if ($this->tables['users']['fields']['passwd']) { + if (isset($result['passwd']) && + $this->encryptPW($passwd) === $result['passwd'] ) { $success = true; break; @@ -281,23 +255,34 @@ return false; } - // If a user was found, read data into class variables and save - // the tree object for faster access in the other functions. - $this->handle = $result[$this->authTableCols['required']['handle']['name']]; - $this->passwd = $this->decryptPW($result[$this->authTableCols['required']['passwd']['name']]); - $this->authUserId = $result[$this->authTableCols['required']['auth_user_id']['name']]; - $this->isActive = ((isset($this->authTableCols['optional']['is_active']) && isset($result[$this->authTableCols['optional']['is_active']['name']])) - ? (bool)$result[$this->authTableCols['optional']['is_active']['name']] : false); - $this->lastLogin = ((isset($this->authTableCols['optional']['lastlogin']) && isset($result[$this->authTableCols['optional']['lastlogin']['name']])) - ? $result[$this->authTableCols['optional']['lastlogin']['name']] : null); - $this->ownerUserId = isset($result['ownerUserId']) ? $result['ownerUserId'] : null; - $this->ownerGroupid = isset($result['ownerGroupId']) ? $result['ownerGroupId'] : null; - if (isset($this->authTableCols['custom'])) { - foreach ($this->authTableCols['custom'] as $alias => $value) { - $alias = strtolower($alias); - $this->propertyValues['custom'][$alias] = $result[$alias]; + $this->handle = $result['handle']; + unset($result['handle']); + $this->passwd = $this->decryptPW($result['passwd']); + unset($result['passwd']); + $this->authUserId = $result['auth_user_id']; + unset($result['auth_user_id']); + $this->isActive = ((!isset($result['is_active']) || $result['is_active']) ? true : false); + if (isset($result['is_active'])) { + unset($result['is_active']); + } + $this->lastLogin = isset($result['lastlogin']) ? $result['lastlogin'] : ''; + if (isset($result['lastlogin'])) { + unset($result['lastlogin']); + } + $this->ownerUserId = isset($result['owner_user_id']) ? $result['owner_user_id'] : null; + if (isset($result['owner_user_id'])) { + unset($result['owner_user_id']); + } + $this->ownerGroupid = isset($result['owner_group_id']) ? $result['owner_group_id'] : null; + if (isset($result['owner_group_id'])) { + unset($result['owner_group_id']); + } + if (!empty($result)) { + foreach ($result as $name => $value) { + $this->{$name} = $value; } } + $this->userObj =& $this->tree->root->getElement(array($index)); return true;