| 1 |
<? |
<? |
| 2 |
|
/** |
| 3 |
|
* This file contains the Tracker::User module. |
| 4 |
|
* |
| 5 |
|
* @author Andreas Motl <andreas.motl@ilo.de> |
| 6 |
|
* @package org.netfrag.flib |
| 7 |
|
* @name Tracker::User |
| 8 |
|
* |
| 9 |
|
*/ |
| 10 |
|
|
| 11 |
|
|
| 12 |
// ----------------------------------------------------------------------------- |
// ----------------------------------------------------------------------------- |
| 13 |
// $Id$ |
// $Id$ |
| 14 |
// ----------------------------------------------------------------------------- |
// ----------------------------------------------------------------------------- |
| 15 |
// $Log$ |
// $Log$ |
| 16 |
|
// Revision 1.15 2004/03/11 21:04:48 jonen |
| 17 |
|
// +changed backend-functions to only get/save User ONLY not SOME object (security!) |
| 18 |
|
// |
| 19 |
|
// Revision 1.14 2003/07/02 11:02:09 joko |
| 20 |
|
// + fixed bug with create/_create |
| 21 |
|
// |
| 22 |
|
// Revision 1.13 2003/04/04 02:15:09 joko |
| 23 |
|
// renamed method of helper object |
| 24 |
|
// |
| 25 |
|
// Revision 1.12 2003/03/03 21:20:47 joko |
| 26 |
|
// mungled the namespaces |
| 27 |
|
// |
| 28 |
|
// Revision 1.11 2003/02/14 14:22:06 joko |
| 29 |
|
// + always (re-)tries to connect |
| 30 |
|
// |
| 31 |
|
// Revision 1.10 2003/02/13 21:58:39 joko |
| 32 |
|
// + caching mechanisms more configurable now |
| 33 |
|
// |
| 34 |
|
// Revision 1.9 2003/02/09 17:46:26 joko |
| 35 |
|
// + now utilizing DesignPattern::RemoteProxy and Data::Deep |
| 36 |
|
// |
| 37 |
|
// Revision 1.8 2002/12/28 01:16:42 jonen |
| 38 |
|
// + added clear of $this->state[autologout] at 'hadTimeout()' |
| 39 |
|
// |
| 40 |
|
// Revision 1.7 2002/12/23 11:32:28 jonen |
| 41 |
|
// + added inserting of uservars on '_create' to frontend db(needed to login user after create!) |
| 42 |
|
// + added hard link to page 'pub/register', TODO: move this out here |
| 43 |
|
// |
| 44 |
|
// Revision 1.6 2002/12/18 22:46:06 jonen |
| 45 |
|
// + added function 'getUserGuid()' |
| 46 |
|
// (returns user's 'guid' read from database at function 'login()' (now)) |
| 47 |
|
// + function '_loadData()' loads user remote now via 'getUserGuid()' |
| 48 |
|
// |
| 49 |
// Revision 1.5 2002/12/12 21:34:32 joko |
// Revision 1.5 2002/12/12 21:34:32 joko |
| 50 |
// + fix in 'function update': invalidate data only if it's not for caching purposes |
// + fix in 'function update': invalidate data only if it's not for caching purposes |
| 51 |
// |
// |
| 102 |
// |
// |
| 103 |
// ----------------------------------------------------------------------------- |
// ----------------------------------------------------------------------------- |
| 104 |
|
|
| 105 |
|
|
| 106 |
|
/** |
| 107 |
|
* This is the User class. |
| 108 |
|
* |
| 109 |
|
* @author Andreas Motl <andreas.motl@ilo.de> |
| 110 |
|
* @package org.netfrag.flib |
| 111 |
|
* @name Tracker::User |
| 112 |
|
* |
| 113 |
|
*/ |
| 114 |
class User { |
class User { |
| 115 |
|
|
| 116 |
var $state; |
var $state; |
| 145 |
|
|
| 146 |
|
|
| 147 |
function _loadData() { |
function _loadData() { |
|
$this->pObject = new ProxyObject($this->state[id]); |
|
|
if ($this->state[id]) { |
|
|
$this->data = $this->pObject->getAttributes(); |
|
|
} |
|
| 148 |
$this->meta[data_ready] = 1; |
$this->meta[data_ready] = 1; |
| 149 |
|
//$this->pObject = new ProxyObject($this->getUserGuid(), array( remote => 1, classname => "NetPerson", guid => 1) ); |
| 150 |
|
$rpcinfo = $this->site->configuration->get("rpcinfo"); |
| 151 |
|
//$this->pObject = mkObject('DesignPattern::RemoteProxy', $this->getUserGuid(), array( remote => 1, classname => "NetPerson", guid => 1, rpcinfo => $rpcinfo, cache => array( db => 1, session => 1 ), connect => 1 ) ); |
| 152 |
|
$this->pObject = mkObject('DesignPattern::RemoteProxy', $this->getUserGuid(), array( key => 1, command => 'getUser', query => $this->getUserGuid(), remote => 1, rpcinfo => $rpcinfo, cache => array( db => 1, session => 1 ), connect => 1 ) ); |
| 153 |
|
if ($this->getUserGuid()) { |
| 154 |
|
$this->data = $this->pObject->getResult(); |
| 155 |
|
} |
| 156 |
} |
} |
| 157 |
|
|
| 158 |
function _saveData($newRawData) { |
function _saveData($newRawData) { |
| 170 |
|
|
| 171 |
function _save($type = '') { |
function _save($type = '') { |
| 172 |
//print Dumper($this->data); |
//print Dumper($this->data); |
| 173 |
$this->pObject->save($this->data, $type); |
//$this->pObject->save($this->data, $type); |
| 174 |
|
// new of 2004-03-08: don't use generic 'saveObject'!! |
| 175 |
|
// for security reasons disabled at ClientBackend!!! |
| 176 |
|
if($type == 'commit') { |
| 177 |
|
$args = array( 'guid' => $this->data[guid], 'data' => $this->data ); |
| 178 |
|
$this->pObject->backend->send('saveUser', $args, array( utf8 => 1) ); |
| 179 |
|
} |
| 180 |
// invalidate data only if it's not for caching purposes |
// invalidate data only if it's not for caching purposes |
| 181 |
if ($type != 'cache') { |
if ($type != 'cache') { |
| 182 |
$this->meta[data_ready] = 0; |
$this->meta[data_ready] = 0; |
| 190 |
|
|
| 191 |
function create() { |
function create() { |
| 192 |
$this->_save(); |
$this->_save(); |
| 193 |
$attr = $this->pObject->getAttributes(); |
$attr = $this->pObject->getResult(); |
| 194 |
//print DumpVar($attr); |
//print DumpVar($attr); |
| 195 |
$this->_create($attr); |
$this->_create($attr); |
| 196 |
} |
} |
| 197 |
|
|
| 198 |
function _create($result) { |
function _create($result) { |
| 199 |
|
global $site; |
| 200 |
//print "saving to backend: " . dumpVar($result) . "<br>"; |
//print "saving to backend: " . dumpVar($result) . "<br>"; |
| 201 |
$response = $this->pObject->backend->send('createUser', array('data' => $result) ); |
$response = $this->pObject->backend->send('createUser', array('data' => $result) ); |
| 202 |
$objectId = $response[oid]; |
$objectId = $response[oid]; |
| 203 |
|
if($objectId) { |
| 204 |
|
connectdb(); |
| 205 |
|
$guid = $response[guid]; |
| 206 |
|
$username = $this->get('userData.username'); |
| 207 |
|
$password = $this->get('userData.password'); |
| 208 |
|
$sql = "INSERT into td_users VALUES ( '$objectId', '$guid', '', '$username', '$password','' )"; |
| 209 |
|
$res = send_sql($sql); |
| 210 |
|
} |
| 211 |
|
else { |
| 212 |
|
// TODO: handle this with a generic rpc-debug/pending function |
| 213 |
|
$site->session->set('register_error', 'rpc_error'); |
| 214 |
|
$site->redirect( getlink('/pub/register/') ); |
| 215 |
|
} |
| 216 |
//$this->_init($objectId); |
//$this->_init($objectId); |
| 217 |
} |
} |
| 218 |
|
|
|
function _getHKR($key) { |
|
|
$attr_arr = split('\.', $key); |
|
|
$attr_hkr = '["' . join('"]["', $attr_arr) . '"]'; |
|
|
return $attr_hkr; |
|
|
} |
|
|
|
|
| 219 |
function get($attr) { |
function get($attr) { |
| 220 |
$this->_doDataReady(); |
$this->_doDataReady(); |
| 221 |
$hkr = $this->_getHKR($attr); |
$deep = new Data_Deep($this->data); |
| 222 |
$evalstr = 'return $this->data' . $hkr . ';'; |
return $deep->get($attr); |
|
$val = eval($evalstr); |
|
|
return $val; |
|
| 223 |
} |
} |
| 224 |
function set($attr, $val) { |
function set($attr, $val) { |
| 225 |
$this->_doDataReady(); |
$this->_doDataReady(); |
| 226 |
$hkr = $this->_getHKR($attr); |
$deep = new Data_Deep($this->data); |
| 227 |
$evalstr = '$this->data' . $hkr . ' = \'' . $val . '\';'; |
$deep->set($attr, $val); |
|
eval($evalstr); |
|
| 228 |
} |
} |
| 229 |
|
|
| 230 |
function isLoggedOn() { |
function isLoggedOn() { |
| 238 |
function login($user,$passwd) { |
function login($user,$passwd) { |
| 239 |
connectdb(); |
connectdb(); |
| 240 |
//$sql = "SELECT * FROM td_users WHERE uname='$user'"; |
//$sql = "SELECT * FROM td_users WHERE uname='$user'"; |
| 241 |
$sql = "SELECT user_oid, uname, pass FROM td_users WHERE uname='$user'"; |
$sql = "SELECT user_oid, guid, uname, pass FROM td_users WHERE uname='$user'"; |
| 242 |
if ($res=send_sql($sql)) { |
if ($res=send_sql($sql)) { |
| 243 |
$row = mysql_fetch_array($res,MYSQL_ASSOC); |
$row = mysql_fetch_array($res,MYSQL_ASSOC); |
| 244 |
if (!is_array($row)) { return 0; } |
if (!is_array($row)) { return 0; } |
| 247 |
//return $uservars_db; |
//return $uservars_db; |
| 248 |
// store 1st priority user-data to state |
// store 1st priority user-data to state |
| 249 |
$this->state[id] = $row[user_oid]; |
$this->state[id] = $row[user_oid]; |
| 250 |
|
$this->state[guid] = $row[guid]; |
| 251 |
$this->state[status] = $this->meta[logontoken]; |
$this->state[status] = $this->meta[logontoken]; |
| 252 |
$this->_saveState(); |
$this->_saveState(); |
| 253 |
$this->site->log( get_class($this) . "->login ok", LOG_DEBUG ); |
$this->site->log( get_class($this) . "->login ok", PEAR_LOG_NOTICE ); |
| 254 |
return 1; |
return 1; |
| 255 |
} else { |
} else { |
| 256 |
return 0; |
return 0; |
| 283 |
$mapping_uservars2data = array_flip($def_mapping[data2uservars]); |
$mapping_uservars2data = array_flip($def_mapping[data2uservars]); |
| 284 |
foreach ($uservars as $key => $val) { |
foreach ($uservars as $key => $val) { |
| 285 |
$key_target = $mapping_uservars2data[$key]; |
$key_target = $mapping_uservars2data[$key]; |
| 286 |
//print "$key => $key_target: $val<br>"; |
if($key_target != '') { |
| 287 |
$target[$key_target] = $val; |
//print "$key => $key_target: $val<br>"; |
| 288 |
|
$target[$key_target] = $val; |
| 289 |
|
} |
| 290 |
} |
} |
| 291 |
return $target; |
return $target; |
| 292 |
} |
} |
| 296 |
global $site; |
global $site; |
| 297 |
|
|
| 298 |
// get information about user from site |
// get information about user from site |
| 299 |
$userid = $this->state[id]; |
$userid = $this->getUserId(); |
| 300 |
|
|
| 301 |
$this->site->log( get_class($this) . "->logout: userid $userid", LOG_DEBUG ); |
$this->site->log( get_class($this) . "->logout: userid $userid", PEAR_LOG_NOTICE ); |
| 302 |
|
|
| 303 |
// get information about session from php |
// get information about session from php |
| 304 |
$session_id = session_id(); |
$session_id = session_id(); |
| 375 |
return $this->state[id]; |
return $this->state[id]; |
| 376 |
} |
} |
| 377 |
|
|
| 378 |
|
function getUserGuid() { |
| 379 |
|
return $this->state[guid]; |
| 380 |
|
} |
| 381 |
|
|
| 382 |
function getPostVars() { |
function getPostVars() { |
| 383 |
return $this->state[postvars]; |
return $this->state[postvars]; |
| 393 |
} |
} |
| 394 |
|
|
| 395 |
function hadTimeout() { |
function hadTimeout() { |
| 396 |
if ($this->state[autologout]) { return 1; } |
if ($this->state[autologout]) { $this->state[autologout] = ''; return 1; } |
| 397 |
} |
} |
| 398 |
|
|
| 399 |
} |
} |