3 /* Copyright (C) 2004 ReiniUrban
4 * This file is part of PhpWiki. Terms and Conditions see LICENSE. (GPL2)
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);
14 class _SessionPassUser
17 function _SessionPassUser($UserName='',$prefs=false) {
18 if ($prefs) $this->_prefs = $prefs;
19 if (!defined("AUTH_SESS_USER") or !defined("AUTH_SESS_LEVEL")) {
21 "AUTH_SESS_USER or AUTH_SESS_LEVEL is not defined for the SessionPassUser method",
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 (explode("][", AUTH_SESS_USER) as $v) {
31 $v = str_replace(array("[","]"),'',$v);
34 $this->_userid = $sess;
35 } elseif (strstr(AUTH_SESS_USER,"->")) {
36 // object "user->id" (no objects inside hashes supported!)
37 list($obj,$key) = explode("->", AUTH_SESS_USER);
38 $this->_userid = $sess[$obj]->$key;
40 $this->_userid = $sess[AUTH_SESS_USER];
42 if (!isset($this->_prefs->_method))
43 _PassUser::_PassUser($this->_userid);
44 $this->_level = AUTH_SESS_LEVEL;
45 $this->_authmethod = 'Session';
47 function userExists() {
48 return !empty($this->_userid);
50 function checkPass($submitted_password) {
51 return $this->userExists() and $this->_level > -1;
53 function mayChangePass() {
62 // c-hanging-comment-ender-p: nil
63 // indent-tabs-mode: nil