Subversion Repositories Applications.papyrus

Rev

Rev 1173 | Go to most recent revision | Show entire file | Regard 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     Lorenzo Alberton <l.alberton@quipo.it> 
17
 * @author     Lorenzo Alberton <l.alberton@quipo.it>
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: MDB2.php,v 1.1 2006-12-14 15:04:28 jp_milcent Exp $
21
 * @version    CVS: $Id: MDB2.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 42... Line 42...
42
 * @package    Auth
42
 * @package    Auth
43
 * @author     Lorenzo Alberton <l.alberton@quipo.it>
43
 * @author     Lorenzo Alberton <l.alberton@quipo.it>
44
 * @author     Adam Ashley <aashley@php.net>
44
 * @author     Adam Ashley <aashley@php.net>
45
 * @copyright  2001-2006 The PHP Group
45
 * @copyright  2001-2006 The PHP Group
46
 * @license    http://www.php.net/license/3_01.txt  PHP License 3.01
46
 * @license    http://www.php.net/license/3_01.txt  PHP License 3.01
47
 * @version    Release: 1.4.3  File: $Revision: 1.1 $
47
 * @version    Release: 1.5.4  File: $Revision: 1.2 $
48
 * @link       http://pear.php.net/package/Auth
48
 * @link       http://pear.php.net/package/Auth
49
 * @since      Class available since Release 1.3.0
49
 * @since      Class available since Release 1.3.0
50
 */
50
 */
51
class Auth_Container_MDB2 extends Auth_Container
51
class Auth_Container_MDB2 extends Auth_Container
52
{
52
{
Line 107... Line 107...
107
     * @param  mixed DSN string | array | mdb object
107
     * @param  mixed DSN string | array | mdb object
108
     * @return mixed  Object on error, otherwise bool
108
     * @return mixed  Object on error, otherwise bool
109
     */
109
     */
110
    function _connect($dsn)
110
    function _connect($dsn)
111
    {
111
    {
-
 
112
        $this->log('Auth_Container_MDB2::_connect() called.', AUTH_LOG_DEBUG);
112
        if (is_string($dsn) || is_array($dsn)) {
113
        if (is_string($dsn) || is_array($dsn)) {
113
            $this->db =& MDB2::connect($dsn, $this->options['db_options']);
114
            $this->db =& MDB2::connect($dsn, $this->options['db_options']);
114
        } elseif (is_subclass_of($dsn, 'MDB2_Driver_Common')) {
115
        } elseif (is_subclass_of($dsn, 'MDB2_Driver_Common')) {
115
            $this->db = $dsn;
116
            $this->db = $dsn;
116
        } elseif (is_object($dsn) && MDB2::isError($dsn)) {
117
        } elseif (is_object($dsn) && MDB2::isError($dsn)) {
Line 177... Line 178...
177
     * @return mixed  a MDB_result object or MDB_OK on success, a MDB
178
     * @return mixed  a MDB_result object or MDB_OK on success, a MDB
178
     *                or PEAR error on failure
179
     *                or PEAR error on failure
179
     */
180
     */
180
    function query($query)
181
    function query($query)
181
    {
182
    {
-
 
183
        $this->log('Auth_Container_MDB2::query() called.', AUTH_LOG_DEBUG);
182
        $err = $this->_prepare();
184
        $err = $this->_prepare();
183
        if ($err !== true) {
185
        if ($err !== true) {
184
            return $err;
186
            return $err;
185
        }
187
        }
186
        return $this->db->exec($query);
188
        return $this->db->exec($query);
Line 202... Line 204...
202
        $this->options['passwordcol'] = 'password';
204
        $this->options['passwordcol'] = 'password';
203
        $this->options['dsn']         = '';
205
        $this->options['dsn']         = '';
204
        $this->options['db_fields']   = '';
206
        $this->options['db_fields']   = '';
205
        $this->options['cryptType']   = 'md5';
207
        $this->options['cryptType']   = 'md5';
206
        $this->options['db_options']  = array();
208
        $this->options['db_options']  = array();
-
 
209
        $this->options['db_where']    = '';
207
        $this->options['auto_quote']  = true;
210
        $this->options['auto_quote']  = true;
208
    }
211
    }
Line 209... Line 212...
209
 
212
 
210
    // }}}
213
    // }}}
Line 281... Line 284...
281
     *                  challenge response password authentication
284
     *                  challenge response password authentication
282
     * @return  mixed  Error object or boolean
285
     * @return  mixed  Error object or boolean
283
     */
286
     */
284
    function fetchData($username, $password, $isChallengeResponse=false)
287
    function fetchData($username, $password, $isChallengeResponse=false)
285
    {
288
    {
-
 
289
        $this->log('Auth_Container_MDB2::fetchData() called.', AUTH_LOG_DEBUG);
286
        // Prepare for a database query
290
        // Prepare for a database query
287
        $err = $this->_prepare();
291
        $err = $this->_prepare();
288
        if ($err !== true) {
292
        if ($err !== true) {
289
            return PEAR::raiseError($err->getMessage(), $err->getCode());
293
            return PEAR::raiseError($err->getMessage(), $err->getCode());
290
        }
294
        }
Line 306... Line 310...
306
                         $this->options['final_table'],
310
                         $this->options['final_table'],
307
                         $this->options['final_usernamecol'],
311
                         $this->options['final_usernamecol'],
308
                         $this->db->quote($username, 'text')
312
                         $this->db->quote($username, 'text')
309
                         );
313
                         );
Line -... Line 314...
-
 
314
 
-
 
315
        // check if there is an optional parameter db_where
-
 
316
        if ($this->options['db_where'] != '') {
-
 
317
            // there is one, so add it to the query
-
 
318
            $query .= " AND ".$this->options['db_where'];
-
 
319
        }
-
 
320
 
-
 
321
        $this->log('Running SQL against MDB2: '.$query, AUTH_LOG_DEBUG);
310
 
322
 
311
        $res = $this->db->queryRow($query, null, MDB2_FETCHMODE_ASSOC);
323
        $res = $this->db->queryRow($query, null, MDB2_FETCHMODE_ASSOC);
312
        if (MDB2::isError($res) || PEAR::isError($res)) {
324
        if (MDB2::isError($res) || PEAR::isError($res)) {
313
            return PEAR::raiseError($res->getMessage(), $res->getCode());
325
            return PEAR::raiseError($res->getMessage(), $res->getCode());
314
        }
326
        }
Line 336... Line 348...
336
            foreach ($res as $key => $value) {
348
            foreach ($res as $key => $value) {
337
                if ($key == $this->options['passwordcol'] ||
349
                if ($key == $this->options['passwordcol'] ||
338
                    $key == $this->options['usernamecol']) {
350
                    $key == $this->options['usernamecol']) {
339
                    continue;
351
                    continue;
340
                }
352
                }
-
 
353
 
-
 
354
                $this->log('Storing additional field: '.$key, AUTH_LOG_DEBUG);
-
 
355
 
341
                // Use reference to the auth object if exists
356
                // Use reference to the auth object if exists
342
                // This is because the auth session variable can change so a static call to setAuthData does not make sense
357
                // This is because the auth session variable can change so a static call to setAuthData does not make sense
343
                $this->_auth_obj->setAuthData($key, $value);
358
                $this->_auth_obj->setAuthData($key, $value);
344
            }
359
            }
345
            return true;
360
            return true;
Line 358... Line 373...
358
     * @return mixed array|PEAR_Error
373
     * @return mixed array|PEAR_Error
359
     * @access public
374
     * @access public
360
     */
375
     */
361
    function listUsers()
376
    function listUsers()
362
    {
377
    {
-
 
378
        $this->log('Auth_Container_MDB2::listUsers() called.', AUTH_LOG_DEBUG);
363
        $err = $this->_prepare();
379
        $err = $this->_prepare();
364
        if ($err !== true) {
380
        if ($err !== true) {
365
            return PEAR::raiseError($err->getMessage(), $err->getCode());
381
            return PEAR::raiseError($err->getMessage(), $err->getCode());
366
        }
382
        }
Line 383... Line 399...
383
        $query = sprintf('SELECT %s FROM %s',
399
        $query = sprintf('SELECT %s FROM %s',
384
                         $sql_from,
400
                         $sql_from,
385
                         $this->options['final_table']
401
                         $this->options['final_table']
386
                         );
402
                         );
Line -... Line 403...
-
 
403
 
-
 
404
        // check if there is an optional parameter db_where
-
 
405
        if ($this->options['db_where'] != '') {
-
 
406
            // there is one, so add it to the query
-
 
407
            $query .= " WHERE ".$this->options['db_where'];
-
 
408
        }
-
 
409
 
-
 
410
        $this->log('Running SQL against MDB2: '.$query, AUTH_LOG_DEBUG);
387
 
411
 
388
        $res = $this->db->queryAll($query, null, MDB2_FETCHMODE_ASSOC);
412
        $res = $this->db->queryAll($query, null, MDB2_FETCHMODE_ASSOC);
389
        if (MDB2::isError($res)) {
413
        if (MDB2::isError($res)) {
390
            return PEAR::raiseError($res->getMessage(), $res->getCode());
414
            return PEAR::raiseError($res->getMessage(), $res->getCode());
391
        } else {
415
        } else {
392
            foreach ($res as $user) {
416
            foreach ($res as $user) {
393
                $user['username'] = $user[$this->options['usernamecol']];
417
                $user['username'] = $user[$this->options['usernamecol']];
394
                $retVal[] = $user;
418
                $retVal[] = $user;
395
            }
419
            }
-
 
420
        }
396
        }
421
        $this->log('Found '.count($retVal).' users.', AUTH_LOG_DEBUG);
397
        return $retVal;
422
        return $retVal;
Line 398... Line 423...
398
    }
423
    }
399
 
424
 
Line 410... Line 435...
410
     *
435
     *
411
     * @return mixed True on success, otherwise error object
436
     * @return mixed True on success, otherwise error object
412
     */
437
     */
413
    function addUser($username, $password, $additional = "")
438
    function addUser($username, $password, $additional = "")
414
    {
439
    {
-
 
440
        $this->log('Auth_Container_MDB2::addUser() called.', AUTH_LOG_DEBUG);
Line 415... Line 441...
415
 
441
 
416
        // Prepare for a database query
442
        // Prepare for a database query
417
        $err = $this->_prepare();
443
        $err = $this->_prepare();
418
        if ($err !== true) {
444
        if ($err !== true) {
Line 451... Line 477...
451
                         $this->db->quote($username, 'text'),
477
                         $this->db->quote($username, 'text'),
452
                         $this->db->quote($password, 'text'),
478
                         $this->db->quote($password, 'text'),
453
                         $additional_value
479
                         $additional_value
454
                         );
480
                         );
Line -... Line 481...
-
 
481
 
-
 
482
        $this->log('Running SQL against MDB2: '.$query, AUTH_LOG_DEBUG);
455
 
483
 
Line 456... Line 484...
456
        $res = $this->query($query);
484
        $res = $this->query($query);
457
 
485
 
458
        if (MDB2::isError($res)) {
486
        if (MDB2::isError($res)) {
Line 472... Line 500...
472
     *
500
     *
473
     * @return mixed True on success, otherwise error object
501
     * @return mixed True on success, otherwise error object
474
     */
502
     */
475
    function removeUser($username)
503
    function removeUser($username)
476
    {
504
    {
-
 
505
        $this->log('Auth_Container_MDB2::removeUser() called.', AUTH_LOG_DEBUG);
477
        // Prepare for a database query
506
        // Prepare for a database query
478
        $err = $this->_prepare();
507
        $err = $this->_prepare();
479
        if ($err !== true) {
508
        if ($err !== true) {
480
            return PEAR::raiseError($err->getMessage(), $err->getCode());
509
            return PEAR::raiseError($err->getMessage(), $err->getCode());
481
        }
510
        }
Line 484... Line 513...
484
                         $this->options['final_table'],
513
                         $this->options['final_table'],
485
                         $this->options['final_usernamecol'],
514
                         $this->options['final_usernamecol'],
486
                         $this->db->quote($username, 'text')
515
                         $this->db->quote($username, 'text')
487
                         );
516
                         );
Line -... Line 517...
-
 
517
 
-
 
518
        // check if there is an optional parameter db_where
-
 
519
        if ($this->options['db_where'] != '') {
-
 
520
            // there is one, so add it to the query
-
 
521
            $query .= " AND ".$this->options['db_where'];
-
 
522
        }
-
 
523
 
-
 
524
        $this->log('Running SQL against MDB2: '.$query, AUTH_LOG_DEBUG);
488
 
525
 
Line 489... Line 526...
489
        $res = $this->query($query);
526
        $res = $this->query($query);
490
 
527
 
491
        if (MDB2::isError($res)) {
528
        if (MDB2::isError($res)) {
Line 503... Line 540...
503
     * @param string Username
540
     * @param string Username
504
     * @param string The new password (plain text)
541
     * @param string The new password (plain text)
505
     */
542
     */
506
    function changePassword($username, $password)
543
    function changePassword($username, $password)
507
    {
544
    {
-
 
545
        $this->log('Auth_Container_MDB2::changePassword() called.', AUTH_LOG_DEBUG);
508
        // Prepare for a database query
546
        // Prepare for a database query
509
        $err = $this->_prepare();
547
        $err = $this->_prepare();
510
        if ($err !== true) {
548
        if ($err !== true) {
511
            return PEAR::raiseError($err->getMessage(), $err->getCode());
549
            return PEAR::raiseError($err->getMessage(), $err->getCode());
512
        }
550
        }
Line 527... Line 565...
527
                         $this->db->quote($password, 'text'),
565
                         $this->db->quote($password, 'text'),
528
                         $this->options['final_usernamecol'],
566
                         $this->options['final_usernamecol'],
529
                         $this->db->quote($username, 'text')
567
                         $this->db->quote($username, 'text')
530
                         );
568
                         );
Line -... Line 569...
-
 
569
 
-
 
570
        // check if there is an optional parameter db_where
-
 
571
        if ($this->options['db_where'] != '') {
-
 
572
            // there is one, so add it to the query
-
 
573
            $query .= " AND ".$this->options['db_where'];
-
 
574
        }
-
 
575
 
-
 
576
        $this->log('Running SQL against MDB2: '.$query, AUTH_LOG_DEBUG);
531
 
577
 
Line 532... Line 578...
532
        $res = $this->query($query);
578
        $res = $this->query($query);
533
 
579
 
534
        if (MDB2::isError($res)) {
580
        if (MDB2::isError($res)) {