cvs: pear /Perm_LiveUser/Auth/Container DB.php MDB.php MDB2.php

From: Date: Mon, 07 Jun 2004 16:09:49 +0000
Subject: cvs: pear /Perm_LiveUser/Auth/Container DB.php MDB.php MDB2.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-20307@lists.php.net to get a copy of this message
arnaud Mon Jun 7 12:09:49 2004 EDT Modified files: /pear/Perm_LiveUser/Auth/Container DB.php MDB.php MDB2.php Log: * fix regarding #1554, table columns are now separated in three groups: required, optional, and custom. This will enable easy fetching and inserting data in the database. Mainly useful for the admin classes but the client part needs to reflect those changes as well. * parent constructor wasn't called * cosmetics

http://cvs.php.net/diff.php/pear/Perm_LiveUser/Auth/Container/DB.php?r1=1.47&r2=1.48&ty=u Index: pear/Perm_LiveUser/Auth/Container/DB.php diff -u pear/Perm_LiveUser/Auth/Container/DB.php:1.47 pear/Perm_LiveUser/Auth/Container/DB.php:1.48 --- pear/Perm_LiveUser/Auth/Container/DB.php:1.47 Sat Apr 24 13:28:41 2004 +++ pear/Perm_LiveUser/Auth/Container/DB.php Mon Jun 7 12:09:48 2004 @@ -47,7 +47,7 @@ * 'allowDuplicateHandles' => 1); * * @author Markus Wolff <wolff@21st.de> - * @version $Id: DB.php,v 1.47 2004/04/24 17:28:41 lsmith Exp $ + * @version $Id: DB.php,v 1.48 2004/06/07 16:09:48 arnaud Exp $ * @package LiveUser * @category authentication */ @@ -90,14 +90,22 @@ * 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 MDB2. + * * @var array * @access public */ - var $authTableCols = array('user_id' => 'auth_user_id', - 'handle' => 'handle', - 'passwd' => 'passwd', - 'lastlogin' => 'lastlogin', - 'is_active' => 'is_active'); + var $authTableCols = array( + 'required' => array( + 'auth_user_id' => array('name' => 'auth_user_id', 'type' => ''), + 'handle' => array('name' => 'handle', 'type' => ''), + 'passwd' => array('name' => 'passwd', 'type' => ''), + ), + 'optional' => array( + 'lastlogin' => array('name' => 'lastlogin', 'type' => ''), + 'is_active' => array('name' => 'is_active', 'type' => '') + ) + ); /** * LiveUser_Auth_Container_DB::LiveUser_Auth_Container_DB() @@ -106,8 +114,9 @@ * * @param mixed */ - function &LiveUser_Auth_Container_DB(&$connectOptions) + function LiveUser_Auth_Container_DB(&$connectOptions) { + $this->LiveUser_Auth_Common($connectOptions); if (is_array($connectOptions)) { $this->LiveUser_Auth_Common($connectOptions); if (isset($connectOptions['connection']) && @@ -159,10 +168,10 @@ return false; } - if (isset($this->authTableCols['lastlogin'])) { + if (isset($this->authTableCols['optional']['lastlogin'])) { $sql = 'UPDATE ' . $this->authTable.' - SET ' . $this->authTableCols['lastlogin'] . '=' . $this->dbc->quoteSmart(date('Y-m-d H:i:s', $this->currentLogin)) . ' - WHERE ' . $this->authTableCols['user_id'] . '=' . $this->dbc->quoteSmart($this->authUserId); + SET ' . $this->authTableCols['optional']['lastlogin'] . '=' . $this->dbc->quoteSmart(date('Y-m-d H:i:s', $this->currentLogin)) . ' + WHERE ' . $this->authTableCols['required']['auth_user_id'] . '=' . $this->dbc->quoteSmart($this->authUserId); $res = $this->dbc->query($sql); return $res; @@ -198,22 +207,26 @@ $success = false; $fields = array(); - foreach ($this->authTableCols AS $key => $value) { - $fields[] = $value . ' AS ' . $key; + foreach ($this->authTableCols as $key => $value) { + if (sizeof($value) > 0) { + foreach ($fields as $alias => $field_data) { + $fields[] = $field_data['name'] . ' AS ' . $alias; + } + } } if ($passwd !== false) { // If $passwd is set, try to find the first user with the given // handle and password. - $sql = 'SELECT '.implode(',', $fields).' + $sql = 'SELECT ' . implode(',', $fields) . ' FROM ' . $this->authTable.' - WHERE ' . $this->authTableCols['handle'] . '=' . $this->dbc->quoteSmart($handle) . ' - AND ' . $this->authTableCols['passwd'] . '=' . $this->dbc->quoteSmart($this->encryptPW($passwd)); + WHERE ' . $this->authTableCols['required']['handle'] . '=' . $this->dbc->quoteSmart($handle) . ' + AND ' . $this->authTableCols['required']['passwd'] . '=' . $this->dbc->quoteSmart($this->encryptPW($passwd)); } else { // If only $handle is set, try to find the first matching user $sql = 'SELECT ' . implode(',', $fields).' FROM ' . $this->authTable . ' - WHERE ' . $this->authTableCols['handle'] . '=' . $this->dbc->quoteSmart($handle); + WHERE ' . $this->authTableCols['required']['handle'] . '=' . $this->dbc->quoteSmart($handle); } // Query database @@ -227,7 +240,7 @@ $this->handle = $udata['handle']; $this->passwd = $this->decryptPW($udata['passwd']); $this->isActive = ((!isset($udata['is_active']) || $udata['is_active'] == 'Y') ? true : false); - $this->authUserId = $udata['user_id']; + $this->authUserId = $udata['auth_user_id']; $this->lastLogin = !empty($udata['lastlogin']) ? strtotime($udata['lastlogin']):''; @@ -271,20 +284,20 @@ } if ($checkHandle !== false && $checkPW === false) { // only search for the first user with the given handle - $sql = 'SELECT ' . $this->authTableCols['user_id'] . ' + $sql = 'SELECT ' . $this->authTableCols['required']['auth_user_id'] . ' FROM ' . $this->authTable . ' - WHERE ' . $this->authTableCols['handle'] . '=' . $this->dbc->quoteSmart($checkHandle); + WHERE ' . $this->authTableCols['required']['handle'] . '=' . $this->dbc->quoteSmart($checkHandle); } elseif ($checkHandle === false && $checkPW !== false) { // only search for the first user with the given password - $sql = 'SELECT ' . $this->authTableCols['user_id'] . ' + $sql = 'SELECT ' . $this->authTableCols['required']['auth_user_id'] . ' FROM ' . $this->authTable . ' - WHERE ' . $this->authTableCols['passwd'] . '=' . $this->dbc->quoteSmart($this->encryptPW($checkPW)); + WHERE ' . $this->authTableCols['required']['passwd'] . '=' . $this->dbc->quoteSmart($this->encryptPW($checkPW)); } else { // check for a user with both handle and password matching - $sql = 'SELECT ' . $this->authTableCols['user_id'].' + $sql = 'SELECT ' . $this->authTableCols['required']['auth_user_id'].' FROM ' . $this->authTable.' - WHERE ' . $this->authTableCols['handle'] . '=' . $this->dbc->quoteSmart($checkHandle) . ' - AND ' . $this->authTableCols['passwd'] . '=' . $this->dbc->quoteSmart($this->encryptPW($checkPW)); + WHERE ' . $this->authTableCols['required']['handle'] . '=' . $this->dbc->quoteSmart($checkHandle) . ' + AND ' . $this->authTableCols['required']['passwd'] . '=' . $this->dbc->quoteSmart($this->encryptPW($checkPW)); } $result = $this->dbc->getOne($sql); http://cvs.php.net/diff.php/pear/Perm_LiveUser/Auth/Container/MDB.php?r1=1.28&r2=1.29&ty=u Index: pear/Perm_LiveUser/Auth/Container/MDB.php diff -u pear/Perm_LiveUser/Auth/Container/MDB.php:1.28 pear/Perm_LiveUser/Auth/Container/MDB.php:1.29 --- pear/Perm_LiveUser/Auth/Container/MDB.php:1.28 Thu May 6 15:09:58 2004 +++ pear/Perm_LiveUser/Auth/Container/MDB.php Mon Jun 7 12:09:49 2004 @@ -48,7 +48,7 @@ * 'allowDuplicateHandles' => 1); * * @author Markus Wolff <wolff@21st.de> - * @version $Id: MDB.php,v 1.28 2004/05/06 19:09:58 lsmith Exp $ + * @version $Id: MDB.php,v 1.29 2004/06/07 16:09:49 arnaud Exp $ * @package LiveUser * @category authentication */ @@ -101,11 +101,17 @@ * @var array * @access public */ - var $authTableCols = array('user_id' => array('name' => 'auth_user_id', 'type' => 'text'), - 'handle' => array('name' => 'handle', 'type' => 'text'), - 'passwd' => array('name' => 'passwd', 'type' => 'text'), - 'lastlogin' => array('name' => 'lastlogin', 'type' => 'timestamp'), - 'is_active' => array('name' => 'is_active', 'type' => 'boolean')); + 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'), + ), + 'optional' => array( + 'lastlogin' => array('name' => 'lastlogin', 'type' => 'timestamp'), + 'is_active' => array('name' => 'is_active', 'type' => 'boolean') + ) + ); /** * LiveUser_Auth_Container_MDB::LiveUser_Auth_Container_MDB() @@ -116,6 +122,7 @@ */ function &LiveUser_Auth_Container_MDB(&$connectOptions) { + $this->LiveUser_Auth_Common($connectOptions); if (is_array($connectOptions)) { $this->LiveUser_Auth_Common($connectOptions); if (isset($connectOptions['connection']) && @@ -175,12 +182,12 @@ return false; } - if (isset($this->authTableCols['lastlogin'])) { + if (isset($this->authTableCols['optional']['lastlogin'])) { $sql = 'UPDATE ' . $this->authTable.' - SET '.$this->authTableCols['lastlogin']['name'] - .'='.$this->dbc->getValue($this->authTableCols['lastlogin']['type'], MDB_Date::unix2Mdbstamp($this->currentLogin)) . ' - WHERE '.$this->authTableCols['user_id']['name'] - .'='.$this->dbc->getValue($this->authTableCols['user_id']['type'], $this->authUserId); + 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); $res = $this->dbc->query($sql); return $res; } else { @@ -215,23 +222,27 @@ $success = false; $fields = array(); - foreach ($this->authTableCols AS $key => $value) { - $fields[] = $value['name'] . ' AS ' . $key; - $types[] = $value['type']; + foreach ($this->authTableCols as $key => $value) { + if (sizeof($value) > 0) { + foreach ($fields as $alias => $field_data) { + $fields[] = $field_data['name'] . ' AS ' . $alias; + $types[] = $field_data['type']; + } + } } if ($passwd !== false) { // If $passwd is set, try to find the first user with the given // handle and password. - $sql = 'SELECT '.implode(',', $fields).' - FROM '.$this->authTable.' - WHERE '.$this->authTableCols['handle']['name'].'='.$this->dbc->getValue($this->authTableCols['handle']['type'], $handle).' - AND '.$this->authTableCols['passwd']['name'].'='.$this->dbc->getValue($this->authTableCols['passwd']['type'], $this->encryptPW($passwd)); + $sql = 'SELECT ' . implode(',', $fields) . ' + FROM ' . $this->authTable . ' + WHERE ' . $this->authTableCols['required']['handle']['name'] . '=' . $this->dbc->getValue($this->authTableCols['handle']['type'], $handle).' + AND ' . $this->authTableCols['required']['passwd']['name'] . '=' . $this->dbc->getValue($this->authTableCols['passwd']['type'], $this->encryptPW($passwd)); } else { // If only $handle is set, try to find the first matching user - $sql = 'SELECT '.implode(',', $fields).' - FROM '.$this->authTable.' - WHERE '.$this->authTableCols['handle']['name'].'='.$this->dbc->getValue($this->authTableCols['handle']['type'], $handle); + $sql = 'SELECT ' . implode(',', $fields).' + FROM ' . $this->authTable.' + WHERE ' . $this->authTableCols['required']['handle']['name'] . '=' . $this->dbc->getValue($this->authTableCols['handle']['type'], $handle); } // Query database @@ -244,7 +255,7 @@ $this->handle = $result['handle']; $this->passwd = $this->decryptPW($result['passwd']); $this->isActive = ((!isset($result['is_active']) || $result['is_active']) ? true : false); - $this->authUserId = $result['user_id']; + $this->authUserId = $result['auth_user_id']; $this->lastLogin = !empty($result['lastlogin'])? MDB_Date::mdbstamp2Unix($result['lastlogin']):''; @@ -291,23 +302,23 @@ if ($checkHandle !== false && $checkPW === false) { // only search for the first user with the given handle - $sql = 'SELECT ' . $this->authTableCols['user_id']['name'] . ' + $sql = 'SELECT ' . $this->authTableCols['required']['auth_user_id']['name'] . ' FROM ' . $this->authTable . ' - WHERE ' . $this->authTableCols['handle']['name'] . '=' . $this->dbc->getValue($this->authTableCols['handle']['type'], $checkHandle); + WHERE ' . $this->authTableCols['required']['handle']['name'] . '=' . $this->dbc->getValue($this->authTableCols['required']['handle']['type'], $checkHandle); } elseif ($checkHandle === false && $checkPW !== false) { // only search for the first user with the given password - $sql = 'SELECT ' . $this->authTableCols['user_id']['name'] . ' + $sql = 'SELECT ' . $this->authTableCols['required']['auth_user_id']['name'] . ' FROM ' . $this->authTable . ' - WHERE ' . $this->authTableCols['handle']['name'] . '=' . $this->dbc->getValue($this->authTableCols['passwd']['type'], $this->encryptPW($checkPW)); + WHERE ' . $this->authTableCols['required']['handle']['name'] . '=' . $this->dbc->getValue($this->authTableCols['required']['passwd']['type'], $this->encryptPW($checkPW)); } else { // check for a user with both handle and password matching - $sql = 'SELECT ' . $this->authTableCols['user_id']['name'] . ' + $sql = 'SELECT ' . $this->authTableCols['required']['auth_user_id']['name'] . ' FROM ' . $this->authTable . ' - WHERE ' . $this->authTableCols['handle']['name'] . '=' . $this->dbc->getValue($this->authTableCols['handle']['type'], $checkHandle) . ' - AND ' . $this->authTableCols['passwd']['name'] . '=' . $this->dbc->getValue($this->authTableCols['passwd']['type'], $this->encryptPW($checkPW)); + WHERE ' . $this->authTableCols['required']['handle']['name'] . '=' . $this->dbc->getValue($this->authTableCols['required']['handle']['type'], $checkHandle) . ' + AND ' . $this->authTableCols['required']['passwd']['name'] . '=' . $this->dbc->getValue($this->authTableCols['required']['passwd']['type'], $this->encryptPW($checkPW)); } - $result = $this->dbc->queryOne($sql, $this->authTableCols['user_id']['type']); + $result = $this->dbc->queryOne($sql, $this->authTableCols['required']['auth_user_id']['type']); if (MDB::isError($result)) { return $result; http://cvs.php.net/diff.php/pear/Perm_LiveUser/Auth/Container/MDB2.php?r1=1.7&r2=1.8&ty=u Index: pear/Perm_LiveUser/Auth/Container/MDB2.php diff -u pear/Perm_LiveUser/Auth/Container/MDB2.php:1.7 pear/Perm_LiveUser/Auth/Container/MDB2.php:1.8 --- pear/Perm_LiveUser/Auth/Container/MDB2.php:1.7 Thu May 6 15:09:58 2004 +++ pear/Perm_LiveUser/Auth/Container/MDB2.php Mon Jun 7 12:09:49 2004 @@ -48,7 +48,7 @@ * 'allowDuplicateHandles' => 1); * * @author Markus Wolff <wolff@21st.de> - * @version $Id: MDB2.php,v 1.7 2004/05/06 19:09:58 lsmith Exp $ + * @version $Id: MDB2.php,v 1.8 2004/06/07 16:09:49 arnaud Exp $ * @package LiveUser * @category authentication */ @@ -94,11 +94,17 @@ * @var array * @access public */ - var $authTableCols = array('user_id' => array('name' => 'auth_user_id', 'type' => 'text'), - 'handle' => array('name' => 'handle', 'type' => 'text'), - 'passwd' => array('name' => 'passwd', 'type' => 'text'), - 'lastlogin' => array('name' => 'lastlogin', 'type' => 'timestamp'), - 'is_active' => array('name' => 'is_active', 'type' => 'boolean')); + 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'), + ), + 'optional' => array( + 'lastlogin' => array('name' => 'lastlogin', 'type' => 'timestamp'), + 'is_active' => array('name' => 'is_active', 'type' => 'boolean') + ) + ); /** * LiveUser_Auth_Container_MDB2::LiveUser_Auth_Container_MDB2() @@ -109,6 +115,7 @@ */ function &LiveUser_Auth_Container_MDB2(&$connectOptions) { + $this->LiveUser_Auth_Common($connectOptions); if (is_array($connectOptions)) { $this->LiveUser_Auth_Common($connectOptions); if (isset($connectOptions['connection']) && @@ -168,12 +175,12 @@ return false; } - if (isset($this->authTableCols['lastlogin'])) { + if (isset($this->authTableCols['optional']['lastlogin'])) { $sql = 'UPDATE ' . $this->authTable.' - SET '.$this->authTableCols['lastlogin']['name'] - .'='.$this->dbc->quote(MDB2_Date::unix2Mdbstamp($this->currentLogin), $this->authTableCols['lastlogin']['type']) . ' - WHERE '.$this->authTableCols['user_id']['name'] - .'='.$this->dbc->quote($this->authUserId, $this->authTableCols['user_id']['type']); + 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']); $res = $this->dbc->query($sql); return $res; } else { @@ -208,23 +215,25 @@ $success = false; $fields = array(); - foreach ($this->authTableCols AS $key => $value) { - $fields[] = $value['name'] . ' AS ' . $key; - $types[] = $value['type']; + foreach ($this->authTableCols['required'] as $key => $value) { + foreach ($fields as $alias => $field_data) { + $fields[] = $field_data['name'] . ' AS ' . $alias; + $types[] = $field_data['type']; + } } if ($passwd !== false) { // If $passwd is set, try to find the first user with the given // handle and password. - $sql = 'SELECT '.implode(',', $fields).' - FROM '.$this->authTable.' - WHERE '.$this->authTableCols['handle']['name'].'='.$this->dbc->quote($handle, $this->authTableCols['handle']['type']).' - AND '.$this->authTableCols['passwd']['name'].'='.$this->dbc->quote($this->encryptPW($passwd), $this->authTableCols['passwd']['type']); + $sql = 'SELECT ' . implode(',', $fields) . ' + FROM ' . $this->authTable . ' + WHERE ' . $this->authTableCols['required']['handle']['name'] . '=' . $this->dbc->quote($handle, $this->authTableCols['handle']['type']).' + AND ' . $this->authTableCols['required']['passwd']['name'] . '=' . $this->dbc->quote($this->encryptPW($passwd), $this->authTableCols['passwd']['type']); } else { // If only $handle is set, try to find the first matching user - $sql = 'SELECT '.implode(',', $fields).' - FROM '.$this->authTable.' - WHERE '.$this->authTableCols['handle']['name'].'='.$this->dbc->quote($handle, $this->authTableCols['handle']['type']); + $sql = 'SELECT ' . implode(',', $fields).' + FROM ' . $this->authTable.' + WHERE ' . $this->authTableCols['required']['handle']['name'].'='.$this->dbc->quote($handle, $this->authTableCols['handle']['type']); } // Query database @@ -237,7 +246,7 @@ $this->handle = $result['handle']; $this->passwd = $this->decryptPW($result['passwd']); $this->isActive = ((!isset($result['is_active']) || $result['is_active']) ? true : false); - $this->authUserId = $result['user_id']; + $this->authUserId = $result['auth_user_id']; $this->lastLogin = !empty($result['lastlogin'])? MDB2_Date::mdbstamp2Unix($result['lastlogin']):''; @@ -284,23 +293,23 @@ if ($checkHandle !== false && $checkPW === false) { // only search for the first user with the given handle - $sql = 'SELECT ' . $this->authTableCols['user_id']['name'] . ' + $sql = 'SELECT ' . $this->authTableCols['required']['auth_user_id']['name'] . ' FROM ' . $this->authTable . ' - WHERE ' . $this->authTableCols['handle']['name'] . '=' . $this->dbc->quote($checkHandle, $this->authTableCols['handle']['type']); + WHERE ' . $this->authTableCols['required']['handle']['name'] . '=' . $this->dbc->quote($checkHandle, $this->authTableCols['required']['handle']['type']); } elseif ($checkHandle === false && $checkPW !== false) { // only search for the first user with the given password - $sql = 'SELECT ' . $this->authTableCols['user_id']['name'] . ' + $sql = 'SELECT ' . $this->authTableCols['required']['auth_user_id']['name'] . ' FROM ' . $this->authTable . ' - WHERE ' . $this->authTableCols['handle']['name'] . '=' . $this->dbc->quote($this->encryptPW($checkPW), $this->authTableCols['passwd']['type']); + WHERE ' . $this->authTableCols['required']['handle']['name'] . '=' . $this->dbc->quote($this->encryptPW($checkPW), $this->authTableCols['required']['passwd']['type']); } else { // check for a user with both handle and password matching - $sql = 'SELECT ' . $this->authTableCols['user_id']['name'] . ' + $sql = 'SELECT ' . $this->authTableCols['required']['auth_user_id']['name'] . ' FROM ' . $this->authTable . ' - WHERE ' . $this->authTableCols['handle']['name'] . '=' . $this->dbc->quote($checkHandle, $this->authTableCols['handle']['type']) . ' - AND ' . $this->authTableCols['passwd']['name'] . '=' . $this->dbc->quote($this->encryptPW($checkPW), $this->authTableCols['passwd']['type']); + WHERE ' . $this->authTableCols['required']['handle']['name'] . '=' . $this->dbc->quote($checkHandle, $this->authTableCols['required']['handle']['type']) . ' + AND ' . $this->authTableCols['required']['passwd']['name'] . '=' . $this->dbc->quote($this->encryptPW($checkPW), $this->authTableCols['required']['passwd']['type']); } - $result = $this->dbc->queryOne($sql, $this->authTableCols['user_id']['type']); + $result = $this->dbc->queryOne($sql, $this->authTableCols['required']['auth_user_id']['type']); if (MDB2::isError($result)) { return $result;
« previous php.pear.cvs (#20307) next »