4 * Copyright (C) 2004 ReiniUrban
6 * This file is part of PhpWiki.
8 * PhpWiki is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * PhpWiki is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * Support reuse of existing user session from another application.
25 * You have to define which session variable holds the userid, and
26 * at what level is that user then. 1: BogoUser, 2: PassUser
27 * define('AUTH_SESS_USER','userid');
28 * define('AUTH_SESS_LEVEL',2);
30 class _SessionPassUser
33 function _SessionPassUser($UserName = '', $prefs = false)
35 if ($prefs) $this->_prefs = $prefs;
36 if (!defined("AUTH_SESS_USER") or !defined("AUTH_SESS_LEVEL")) {
38 "AUTH_SESS_USER or AUTH_SESS_LEVEL is not defined for the SessionPassUser method",
42 $sess =& $GLOBALS['HTTP_SESSION_VARS'];
43 // user hash: "[user][userid]" or object "user->id"
44 if (strstr(AUTH_SESS_USER, "][")) {
45 $sess = $GLOBALS['HTTP_SESSION_VARS'];
46 // recurse into hashes: "[user][userid]", sess = sess[user] => sess = sess[userid]
47 foreach (explode("][", AUTH_SESS_USER) as $v) {
48 $v = str_replace(array("[", "]"), '', $v);
51 $this->_userid = $sess;
52 } elseif (strstr(AUTH_SESS_USER, "->")) {
53 // object "user->id" (no objects inside hashes supported!)
54 list($obj, $key) = explode("->", AUTH_SESS_USER);
55 $this->_userid = $sess[$obj]->$key;
57 $this->_userid = $sess[AUTH_SESS_USER];
59 if (!isset($this->_prefs->_method))
60 _PassUser::_PassUser($this->_userid);
61 $this->_level = AUTH_SESS_LEVEL;
62 $this->_authmethod = 'Session';
67 return !empty($this->_userid);
70 function checkPass($submitted_password)
72 return $this->userExists() and $this->_level > -1;
75 function mayChangePass()
85 // c-hanging-comment-ender-p: nil
86 // indent-tabs-mode: nil