Subversion Repositories Applications.papyrus

Rev

Rev 1173 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1173 Rev 1713
Line 16... Line 16...
16
 * @package    Auth
16
 * @package    Auth
17
 * @author     Martin Jansen <mj@php.net>
17
 * @author     Martin Jansen <mj@php.net>
18
 * @author     Adam Ashley <aashley@php.net>
18
 * @author     Adam Ashley <aashley@php.net>
19
 * @copyright  2001-2006 The PHP Group
19
 * @copyright  2001-2006 The PHP Group
20
 * @license    http://www.php.net/license/3_01.txt  PHP License 3.01
20
 * @license    http://www.php.net/license/3_01.txt  PHP License 3.01
21
 * @version    CVS: $Id: DBLite.php,v 1.1 2006-12-14 15:04:28 jp_milcent Exp $
21
 * @version    CVS: $Id: DBLite.php,v 1.2 2007-11-19 15:11:00 jp_milcent Exp $
22
 * @link       http://pear.php.net/package/Auth
22
 * @link       http://pear.php.net/package/Auth
23
 * @since      File available since Release 1.3.0
23
 * @since      File available since Release 1.3.0
24
 */
24
 */
Line 25... Line 25...
25
 
25
 
Line 43... Line 43...
43
 * @package    Auth
43
 * @package    Auth
44
 * @author     Martin Jansen <mj@php.net>
44
 * @author     Martin Jansen <mj@php.net>
45
 * @author     Adam Ashley <aashley@php.net>
45
 * @author     Adam Ashley <aashley@php.net>
46
 * @copyright  2001-2006 The PHP Group
46
 * @copyright  2001-2006 The PHP Group
47
 * @license    http://www.php.net/license/3_01.txt  PHP License 3.01
47
 * @license    http://www.php.net/license/3_01.txt  PHP License 3.01
48
 * @version    Release: 1.4.3  File: $Revision: 1.1 $
48
 * @version    Release: 1.5.4  File: $Revision: 1.2 $
49
 * @link       http://pear.php.net/package/Auth
49
 * @link       http://pear.php.net/package/Auth
50
 * @since      Class available since Release 1.3.0
50
 * @since      Class available since Release 1.3.0
51
 */
51
 */
52
class Auth_Container_DBLite extends Auth_Container
52
class Auth_Container_DBLite extends Auth_Container
53
{
53
{
Line 91... Line 91...
91
        $this->options['passwordcol'] = 'password';
91
        $this->options['passwordcol'] = 'password';
92
        $this->options['dsn']         = '';
92
        $this->options['dsn']         = '';
93
        $this->options['db_fields']   = '';
93
        $this->options['db_fields']   = '';
94
        $this->options['cryptType']   = 'md5';
94
        $this->options['cryptType']   = 'md5';
95
        $this->options['db_options']  = array();
95
        $this->options['db_options']  = array();
-
 
96
        $this->options['db_where']    = '';
96
        $this->options['auto_quote']  = true;
97
        $this->options['auto_quote']  = true;
Line 97... Line 98...
97
 
98
 
98
        if (is_array($dsn)) {
99
        if (is_array($dsn)) {
99
            $this->_parseOptions($dsn);
100
            $this->_parseOptions($dsn);
Line 115... Line 116...
115
     * @param  string DSN string
116
     * @param  string DSN string
116
     * @return mixed  Object on error, otherwise bool
117
     * @return mixed  Object on error, otherwise bool
117
     */
118
     */
118
    function _connect(&$dsn)
119
    function _connect(&$dsn)
119
    {
120
    {
-
 
121
        $this->log('Auth_Container_DBLite::_connect() called.', AUTH_LOG_DEBUG);
120
        if (is_string($dsn) || is_array($dsn)) {
122
        if (is_string($dsn) || is_array($dsn)) {
121
            $this->db =& DB::connect($dsn, $this->options['db_options']);
123
            $this->db =& DB::connect($dsn, $this->options['db_options']);
122
        } elseif (is_subclass_of($dsn, "db_common")) {
124
        } elseif (is_subclass_of($dsn, "db_common")) {
123
            $this->db =& $dsn;
125
            $this->db =& $dsn;
124
        } else {
126
        } else {
Line 216... Line 218...
216
            }
218
            }
217
        }
219
        }
Line 218... Line 220...
218
 
220
 
219
        return '';
221
        return '';
220
    }
222
    }
221
    
223
 
222
    // }}}
224
    // }}}
Line 223... Line 225...
223
    // {{{ fetchData()
225
    // {{{ fetchData()
224
 
226
 
Line 235... Line 237...
235
     * @param   string Password
237
     * @param   string Password
236
     * @return  mixed  Error object or boolean
238
     * @return  mixed  Error object or boolean
237
     */
239
     */
238
    function fetchData($username, $password)
240
    function fetchData($username, $password)
239
    {
241
    {
-
 
242
        $this->log('Auth_Container_DBLite::fetchData() called.', AUTH_LOG_DEBUG);
240
        // Prepare for a database query
243
        // Prepare for a database query
241
        $err = $this->_prepare();
244
        $err = $this->_prepare();
242
        if ($err !== true) {
245
        if ($err !== true) {
243
            return PEAR::raiseError($err->getMessage(), $err->getCode());
246
            return PEAR::raiseError($err->getMessage(), $err->getCode());
244
        }
247
        }
Line 253... Line 256...
253
 
256
 
254
            if (strlen($fields = $this->_quoteDBFields()) > 0) {
257
            if (strlen($fields = $this->_quoteDBFields()) > 0) {
255
                $sql_from .= ', '.$fields;
258
                $sql_from .= ', '.$fields;
256
            }
259
            }
257
        }
260
        }
258
        
261
 
259
        $query = "SELECT ".$sql_from.
262
        $query = "SELECT ".$sql_from.
260
                " FROM ".$this->options['final_table'].
263
                " FROM ".$this->options['final_table'].
-
 
264
                " WHERE ".$this->options['final_usernamecol']." = ".$this->db->quoteSmart($username);
-
 
265
 
-
 
266
        // check if there is an optional parameter db_where
-
 
267
        if ($this->options['db_where'] != '') {
-
 
268
            // there is one, so add it to the query
-
 
269
            $query .= " AND ".$this->options['db_where'];
-
 
270
        }
-
 
271
 
-
 
272
        $this->log('Running SQL against DB: '.$query, AUTH_LOG_DEBUG);
261
                " WHERE ".$this->options['final_usernamecol']." = ".$this->db->quoteSmart($username);
273
 
Line 262... Line 274...
262
        $res = $this->db->getRow($query, null, DB_FETCHMODE_ASSOC);
274
        $res = $this->db->getRow($query, null, DB_FETCHMODE_ASSOC);
263
 
275
 
264
        if (DB::isError($res)) {
276
        if (DB::isError($res)) {
Line 275... Line 287...
275
            foreach ($res as $key => $value) {
287
            foreach ($res as $key => $value) {
276
                if ($key == $this->options['passwordcol'] ||
288
                if ($key == $this->options['passwordcol'] ||
277
                    $key == $this->options['usernamecol']) {
289
                    $key == $this->options['usernamecol']) {
278
                    continue;
290
                    continue;
279
                }
291
                }
-
 
292
 
-
 
293
                $this->log('Storing additional field: '.$key, AUTH_LOG_DEBUG);
-
 
294
 
280
                // Use reference to the auth object if exists
295
                // Use reference to the auth object if exists
281
                // This is because the auth session variable can change so a static call to setAuthData does not make sence
296
                // This is because the auth session variable can change so a static call to setAuthData does not make sence
282
                if (is_object($this->_auth_obj)) {
297
                if (is_object($this->_auth_obj)) {
283
                    $this->_auth_obj->setAuthData($key, $value);
298
                    $this->_auth_obj->setAuthData($key, $value);
284
                } else {
299
                } else {