00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 require_once dirname(__FILE__).'/diogenes.core.logger.inc.php';
00022 require_once dirname(__FILE__).'/diogenes.flagset.inc.php';
00023
00025 $diogenes_core_usercache = array();
00026
00029 class DiogenesCoreSession {
00031 var $challenge;
00032
00034 var $uid;
00036 var $username;
00038 var $perms;
00039
00042 function DiogenesCoreSession()
00043 {
00044 $this->challenge = md5(uniqid(rand(), 1));
00045 $this->perms = new flagset("");
00046 }
00047
00048
00053 function hasPerms($level)
00054 {
00055 return $this->perms->hasflag($level);
00056 }
00057
00058
00064 function doAuth(&$page) {
00065 global $globals;
00066 echo "DiogenesCoreSession::doAuth needs to be overriden";
00067 exit;
00068
00069
00070 if ($this->perms->hasflag("auth"))
00071 return;
00072
00073
00074 if (isset($_REQUEST['some_token_needed_for_auth'])) {
00075
00076 } else {
00077 $this->doLogin($page);
00078 }
00079 }
00080
00081
00086 function doLogin(&$page) {
00087 echo "DiogenesCoreSession::doLogin needs to be overriden";
00088 exit;
00089 }
00090
00091
00103 function getUserId($auth,$username) {
00104 global $diogenes_core_usercache, $globals;
00105
00106 if (isset($diogenes_core_usercache[$auth]) and ($uid = array_search($username, $diogenes_core_usercache[$auth])))
00107 {
00108
00109
00110 return $uid;
00111
00112 } else {
00113
00114
00115 $uid = call_user_func(array($globals->session,'lookupUserId'),$auth,$username);
00116
00117
00118 $diogenes_core_usercache[$auth][$uid] = $username;
00119 return $uid;
00120 }
00121
00122 }
00123
00124
00136 function getUsername($auth,$uid) {
00137 global $diogenes_core_usercache, $globals;
00138
00139 if (isset($diogenes_core_usercache[$auth][$uid])) {
00140
00141
00142 return $diogenes_core_usercache[$auth][$uid];
00143
00144 } else {
00145
00146
00147 $username = call_user_func(array($globals->session,'lookupUsername'),$auth,$uid);
00148
00149
00150 $diogenes_core_usercache[$auth][$uid] = $username;
00151
00152 return $username;
00153 }
00154
00155 }
00156
00157
00165 function lookupUserId($auth, $username)
00166 {
00167 global $globals;
00168
00169 $res = $globals->db->query("select user_id from {$globals->tauth[$auth]} where username='$username'");
00170 list($uid) = mysql_fetch_row($res);
00171 mysql_free_result($res);
00172
00173 return $uid;
00174 }
00175
00176
00184 function lookupUsername($auth, $uid)
00185 {
00186 global $globals;
00187
00188 $res = $globals->db->query("select username from {$globals->tauth[$auth]} where user_id='$uid'");
00189 list($username) = mysql_fetch_row($res);
00190 mysql_free_result($res);
00191
00192 return $username;
00193 }
00194
00195 }
00196
00197 ?>