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