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
19 * along with PhpWiki; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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) {
34 if ($prefs) $this->_prefs = $prefs;
35 if (!defined("AUTH_SESS_USER") or !defined("AUTH_SESS_LEVEL")) {
37 "AUTH_SESS_USER or AUTH_SESS_LEVEL is not defined for the SessionPassUser method",
41 $sess =& $GLOBALS['HTTP_SESSION_VARS'];
42 // user hash: "[user][userid]" or object "user->id"
43 if (strstr(AUTH_SESS_USER,"][")) {
44 $sess = $GLOBALS['HTTP_SESSION_VARS'];
45 // recurse into hashes: "[user][userid]", sess = sess[user] => sess = sess[userid]
46 foreach (explode("][", AUTH_SESS_USER) as $v) {
47 $v = str_replace(array("[","]"),'',$v);
50 $this->_userid = $sess;
51 } elseif (strstr(AUTH_SESS_USER,"->")) {
52 // object "user->id" (no objects inside hashes supported!)
53 list($obj,$key) = explode("->", AUTH_SESS_USER);
54 $this->_userid = $sess[$obj]->$key;
56 $this->_userid = $sess[AUTH_SESS_USER];
58 if (!isset($this->_prefs->_method))
59 _PassUser::_PassUser($this->_userid);
60 $this->_level = AUTH_SESS_LEVEL;
61 $this->_authmethod = 'Session';
63 function userExists() {
64 return !empty($this->_userid);
66 function checkPass($submitted_password) {
67 return $this->userExists() and $this->_level > -1;
69 function mayChangePass() {
78 // c-hanging-comment-ender-p: nil
79 // indent-tabs-mode: nil