]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/WikiUser/Session.php
seperate PassUser methods into seperate dir (memory usage)
[SourceForge/phpwiki.git] / lib / WikiUser / Session.php
1 <?php //-*-php-*-
2 rcs_id('$Id: Session.php,v 1.1 2004-11-01 10:43:58 rurban Exp $');
3 /* Copyright (C) 2004 $ThePhpWikiProgrammingTeam
4  */
5
6 /** 
7  * Support reuse of existing user session from another application.
8  * You have to define which session variable holds the userid, and 
9  * at what level is that user then. 1: BogoUser, 2: PassUser
10  *   define('AUTH_SESS_USER','userid');
11  *   define('AUTH_SESS_LEVEL',2);
12  */
13 class _SessionPassUser
14 extends _PassUser
15 {
16     function _SessionPassUser($UserName='',$prefs=false) {
17         if ($prefs) $this->_prefs = $prefs;
18         if (!defined("AUTH_SESS_USER") or !defined("AUTH_SESS_LEVEL")) {
19             trigger_error(
20                 "AUTH_SESS_USER or AUTH_SESS_LEVEL is not defined for the SessionPassUser method",
21                 E_USER_ERROR);
22             exit;
23         }
24         $sess =& $GLOBALS['HTTP_SESSION_VARS'];
25         // user hash: "[user][userid]" or object "user->id"
26         if (strstr(AUTH_SESS_USER,"][")) {
27             $sess = $GLOBALS['HTTP_SESSION_VARS'];
28             // recurse into hashes: "[user][userid]", sess = sess[user] => sess = sess[userid]
29             foreach (split("][",AUTH_SESS_USER) as $v) {
30                 $v = str_replace(array("[","]"),'',$v);
31                 $sess = $sess[$v];
32             }
33             $this->_userid = $sess;
34         } elseif (strstr(AUTH_SESS_USER,"->")) {
35             // object "user->id" (no objects inside hashes supported!)
36             list($obj,$key) = split("->",AUTH_SESS_USER);
37             $this->_userid = $sess[$obj]->$key;
38         } else {
39             $this->_userid = $sess[AUTH_SESS_USER];
40         }
41         if (!isset($this->_prefs->_method))
42            _PassUser::_PassUser($this->_userid);
43         $this->_level = AUTH_SESS_LEVEL;
44         $this->_authmethod = 'Session';
45     }
46     function userExists() {
47         return !empty($this->_userid);
48     }
49     function checkPass($submitted_password) {
50         return $this->userExists() and $this->_level;
51     }
52     function mayChangePass() {
53         return false;
54     }
55 }
56
57 // $Log: not supported by cvs2svn $
58
59 // Local Variables:
60 // mode: php
61 // tab-width: 8
62 // c-basic-offset: 4
63 // c-hanging-comment-ender-p: nil
64 // indent-tabs-mode: nil
65 // End:
66 ?>