]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/WikiUser/Session.php
Reformat code
[SourceForge/phpwiki.git] / lib / WikiUser / Session.php
1 <?php
2
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 along
19  * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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     {
35         if ($prefs) $this->_prefs = $prefs;
36         if (!defined("AUTH_SESS_USER") or !defined("AUTH_SESS_LEVEL")) {
37             trigger_error(
38                 "AUTH_SESS_USER or AUTH_SESS_LEVEL is not defined for the SessionPassUser method",
39                 E_USER_ERROR);
40             exit;
41         }
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);
49                 $sess = $sess[$v];
50             }
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;
56         } else {
57             $this->_userid = $sess[AUTH_SESS_USER];
58         }
59         if (!isset($this->_prefs->_method))
60             _PassUser::_PassUser($this->_userid);
61         $this->_level = AUTH_SESS_LEVEL;
62         $this->_authmethod = 'Session';
63     }
64
65     function userExists()
66     {
67         return !empty($this->_userid);
68     }
69
70     function checkPass($submitted_password)
71     {
72         return $this->userExists() and $this->_level > -1;
73     }
74
75     function mayChangePass()
76     {
77         return false;
78     }
79 }
80
81 // Local Variables:
82 // mode: php
83 // tab-width: 8
84 // c-basic-offset: 4
85 // c-hanging-comment-ender-p: nil
86 // indent-tabs-mode: nil
87 // End: