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