]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/WikiUser/Db.php
add PdoDbPassUser
[SourceForge/phpwiki.git] / lib / WikiUser / Db.php
1 <?php //-*-php-*-
2 rcs_id('$Id: Db.php,v 1.2 2004-12-26 17:11:15 rurban Exp $');
3 /* Copyright (C) 2004 ReiniUrban
4  * This file is part of PhpWiki. Terms and Conditions see LICENSE. (GPL2)
5  */
6
7 /**
8  * Baseclass for PearDB and ADODB PassUser's
9  * Authenticate against a database, to be able to use shared users.
10  *   internal: no different $DbAuthParams['dsn'] defined, or
11  *   external: different $DbAuthParams['dsn']
12  * The magic is done in the symbolic SQL statements in config/config.ini, similar to
13  * libnss-mysql.
14  *
15  * We support only the SQL and ADODB backends.
16  * The other WikiDB backends (flat, cvs, dba, ...) should be used for pages, 
17  * not for auth stuff. If one would like to use e.g. dba for auth, he should 
18  * use PearDB (SQL) with the right $DBAuthParam['auth_dsn']. 
19  * (Not supported yet, since we require SQL. SQLite would make since when 
20  * it will come to PHP)
21  *
22  * @tables: user, pref
23  *
24  * Preferences are handled in the parent class _PassUser, because the 
25  * previous classes may also use DB pref_select and pref_update.
26  *
27  * Flat files auth is handled by the auth method "File".
28  */
29 class _DbPassUser
30 extends _PassUser
31 {
32     var $_authselect, $_authupdate, $_authcreate;
33
34     // This can only be called from _PassUser, because the parent class 
35     // sets the auth_dbi and pref methods, before this class is initialized.
36     function _DbPassUser($UserName='',$prefs=false) {
37         if (!$this->_prefs) {
38             if ($prefs) $this->_prefs = $prefs;
39         }
40         if (!isset($this->_prefs->_method))
41            _PassUser::_PassUser($UserName);
42         elseif (!$this->isValidName($UserName)) {
43             trigger_error(_("Invalid username."),E_USER_WARNING);
44             return false;
45         }
46         $this->_authmethod = 'Db';
47         //$this->getAuthDbh();
48         //$this->_auth_crypt_method = @$GLOBALS['DBAuthParams']['auth_crypt_method'];
49         $dbi =& $GLOBALS['request']->_dbi;
50         $dbtype = $dbi->getParam('dbtype');
51         if ($dbtype == 'ADODB') {
52             include_once("lib/WikiUser/AdoDb.php");
53             if (check_php_version(5))
54                 return new _AdoDbPassUser($UserName,$this->_prefs);
55             else {
56                 $user = new _AdoDbPassUser($UserName,$this->_prefs);
57                 eval("\$this = \$user;");
58                 return $user;
59             }
60         }
61         elseif ($dbtype == 'SQL') {
62             include_once("lib/WikiUser/PearDb.php");
63             if (check_php_version(5))
64                 return new _PearDbPassUser($UserName,$this->_prefs);
65             else {
66                 $user = new _PearDbPassUser($UserName,$this->_prefs);
67                 eval("\$this = \$user;");
68                 return $user;
69             }
70         }
71         return false;
72     }
73
74     function mayChangePass() {
75         return !isset($this->_authupdate);
76     }
77
78 }
79
80 // $Log: not supported by cvs2svn $
81 // Revision 1.1  2004/11/01 10:43:58  rurban
82 // seperate PassUser methods into seperate dir (memory usage)
83 // fix WikiUser (old) overlarge data session
84 // remove wikidb arg from various page class methods, use global ->_dbi instead
85 // ...
86 //
87
88 // Local Variables:
89 // mode: php
90 // tab-width: 8
91 // c-basic-offset: 4
92 // c-hanging-comment-ender-p: nil
93 // indent-tabs-mode: nil
94 // End:
95 ?>