]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/WikiUser/Session.php
Remove rcs_id
[SourceForge/phpwiki.git] / lib / WikiUser / Session.php
1 <?php //-*-php-*-
2 // $Id$
3 /*
4  * Copyright (C) 2004 ReiniUrban
5  *
6  * This file is part of PhpWiki.
7  *
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.
12  *
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.
17  *
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
21  */
22
23 /**
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);
29  */
30 class _SessionPassUser
31 extends _PassUser
32 {
33     function _SessionPassUser($UserName='',$prefs=false) {
34         if ($prefs) $this->_prefs = $prefs;
35         if (!defined("AUTH_SESS_USER") or !defined("AUTH_SESS_LEVEL")) {
36             trigger_error(
37                 "AUTH_SESS_USER or AUTH_SESS_LEVEL is not defined for the SessionPassUser method",
38                 E_USER_ERROR);
39             exit;
40         }
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);
48                 $sess = $sess[$v];
49             }
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;
55         } else {
56             $this->_userid = $sess[AUTH_SESS_USER];
57         }
58         if (!isset($this->_prefs->_method))
59            _PassUser::_PassUser($this->_userid);
60         $this->_level = AUTH_SESS_LEVEL;
61         $this->_authmethod = 'Session';
62     }
63     function userExists() {
64         return !empty($this->_userid);
65     }
66     function checkPass($submitted_password) {
67         return $this->userExists() and $this->_level > -1;
68     }
69     function mayChangePass() {
70         return false;
71     }
72 }
73
74 // Local Variables:
75 // mode: php
76 // tab-width: 8
77 // c-basic-offset: 4
78 // c-hanging-comment-ender-p: nil
79 // indent-tabs-mode: nil
80 // End:
81 ?>