| 1 |
<? |
<? |
| 2 |
|
/** |
| 3 |
|
* This file contains the Tracker::User module. |
| 4 |
|
* |
| 5 |
|
* @author Andreas Motl <andreas.motl@ilo.de> |
| 6 |
|
* @author Sebastian Utz <su@rtme.net> |
| 7 |
|
* @package org.netfrag.flib |
| 8 |
|
* @name Tracker::User |
| 9 |
|
* |
| 10 |
|
*/ |
| 11 |
|
|
| 12 |
|
|
| 13 |
// ----------------------------------------------------------------------------- |
// ----------------------------------------------------------------------------- |
| 14 |
// $Id$ |
// $Id$ |
| 15 |
// ----------------------------------------------------------------------------- |
// ----------------------------------------------------------------------------- |
| 16 |
// $Log$ |
// $Log$ |
| 17 |
|
// Revision 1.23 2005/08/11 14:08:11 jonen |
| 18 |
|
// + added functions relating to TerminalUser |
| 19 |
|
// |
| 20 |
|
// Revision 1.22 2004/11/17 16:14:47 jonen |
| 21 |
|
// + minor changes related to utf8 encoding |
| 22 |
|
// |
| 23 |
|
// Revision 1.21 2004/11/03 14:13:21 jonen |
| 24 |
|
// small changes at create function |
| 25 |
|
// |
| 26 |
|
// Revision 1.20 2004/10/07 14:08:51 jonen |
| 27 |
|
// + bufix related to save new-registered user-data |
| 28 |
|
// |
| 29 |
|
// Revision 1.19 2004/06/22 09:18:47 jonen |
| 30 |
|
// removed debug dumps |
| 31 |
|
// |
| 32 |
|
// Revision 1.17 2004/06/07 16:54:53 joko |
| 33 |
|
// modified cache-key |
| 34 |
|
// added cache-control |
| 35 |
|
// |
| 36 |
|
// Revision 1.16 2004/05/06 13:02:09 jonen |
| 37 |
|
// + added/modified functions related to User-Messages |
| 38 |
|
// |
| 39 |
|
// Revision 1.15 2004/03/11 21:04:48 jonen |
| 40 |
|
// +changed backend-functions to only get/save User ONLY not SOME object (security!) |
| 41 |
|
// |
| 42 |
|
// Revision 1.14 2003/07/02 11:02:09 joko |
| 43 |
|
// + fixed bug with create/_create |
| 44 |
|
// |
| 45 |
|
// Revision 1.13 2003/04/04 02:15:09 joko |
| 46 |
|
// renamed method of helper object |
| 47 |
|
// |
| 48 |
|
// Revision 1.12 2003/03/03 21:20:47 joko |
| 49 |
|
// mungled the namespaces |
| 50 |
|
// |
| 51 |
|
// Revision 1.11 2003/02/14 14:22:06 joko |
| 52 |
|
// + always (re-)tries to connect |
| 53 |
|
// |
| 54 |
|
// Revision 1.10 2003/02/13 21:58:39 joko |
| 55 |
|
// + caching mechanisms more configurable now |
| 56 |
|
// |
| 57 |
|
// Revision 1.9 2003/02/09 17:46:26 joko |
| 58 |
|
// + now utilizing DesignPattern::RemoteProxy and Data::Deep |
| 59 |
|
// |
| 60 |
|
// Revision 1.8 2002/12/28 01:16:42 jonen |
| 61 |
|
// + added clear of $this->state[autologout] at 'hadTimeout()' |
| 62 |
|
// |
| 63 |
|
// Revision 1.7 2002/12/23 11:32:28 jonen |
| 64 |
|
// + added inserting of uservars on '_create' to frontend db(needed to login user after create!) |
| 65 |
|
// + added hard link to page 'pub/register', TODO: move this out here |
| 66 |
|
// |
| 67 |
// Revision 1.6 2002/12/18 22:46:06 jonen |
// Revision 1.6 2002/12/18 22:46:06 jonen |
| 68 |
// + added function 'getUserGuid()' |
// + added function 'getUserGuid()' |
| 69 |
// (returns user's 'guid' read from database at function 'login()' (now)) |
// (returns user's 'guid' read from database at function 'login()' (now)) |
| 125 |
// |
// |
| 126 |
// ----------------------------------------------------------------------------- |
// ----------------------------------------------------------------------------- |
| 127 |
|
|
| 128 |
|
|
| 129 |
|
/** |
| 130 |
|
* This is the User class. |
| 131 |
|
* |
| 132 |
|
* @author Andreas Motl <andreas.motl@ilo.de> |
| 133 |
|
* @package org.netfrag.flib |
| 134 |
|
* @name Tracker::User |
| 135 |
|
* |
| 136 |
|
*/ |
| 137 |
class User { |
class User { |
| 138 |
|
|
| 139 |
var $state; |
var $state; |
| 168 |
|
|
| 169 |
|
|
| 170 |
function _loadData() { |
function _loadData() { |
|
$this->pObject = new ProxyObject($this->getUserGuid(), array( remote => 1, classname => "NetPerson", guid => 1) ); |
|
|
if ($this->getUserGuid()) { |
|
|
$this->data = $this->pObject->getAttributes(); |
|
|
} |
|
| 171 |
$this->meta[data_ready] = 1; |
$this->meta[data_ready] = 1; |
| 172 |
|
//$this->pObject = new ProxyObject($this->getUserGuid(), array( remote => 1, classname => "NetPerson", guid => 1) ); |
| 173 |
|
$rpcinfo = $this->site->configuration->get("rpcinfo"); |
| 174 |
|
//$this->pObject = mkObject('DesignPattern::RemoteProxy', $this->getUserGuid(), array( remote => 1, classname => "NetPerson", guid => 1, rpcinfo => $rpcinfo, cache => array( db => 1, session => 1 ), connect => 1 ) ); |
| 175 |
|
$cache_key = $this->getUserGuid() . "_user"; |
| 176 |
|
$this->pObject = mkObject('DesignPattern::RemoteProxy', $cache_key, array( key => 1, command => 'getUser', query => $this->getUserGuid(), remote => 1, rpcinfo => $rpcinfo, cache => array( db => 1, session => 1 ), connect => 1 ) ); |
| 177 |
|
if ($this->getUserGuid()) { |
| 178 |
|
$this->data = $this->pObject->getResult(); |
| 179 |
|
} |
| 180 |
} |
} |
| 181 |
|
|
| 182 |
function _saveData($newRawData) { |
function _saveData($newRawData) { |
| 183 |
|
|
| 184 |
|
//print "newRawData: " . Dumper($newRawData) . "<br>"; |
| 185 |
foreach ($newRawData as $key => $val) { |
foreach ($newRawData as $key => $val) { |
| 186 |
//print "$key => $val<br>"; |
//print "$key => $val<br>"; |
| 187 |
$this->set($key, $val); |
$this->set($key, $val); |
| 188 |
} |
} |
| 189 |
|
|
| 190 |
$this->_save("cache"); |
$this->_save("cache"); |
| 191 |
|
//$this->_save("commit"); |
| 192 |
|
|
| 193 |
//$this->pObject->flushProxy(); // done in "pObject->save" |
//$this->pObject->flushProxy(); // done in "pObject->save" |
| 194 |
|
|
| 196 |
|
|
| 197 |
function _save($type = '') { |
function _save($type = '') { |
| 198 |
//print Dumper($this->data); |
//print Dumper($this->data); |
| 199 |
$this->pObject->save($this->data, $type); |
//$this->pObject->save($this->data, $type); |
| 200 |
|
// new of 2004-03-08: don't use generic 'saveObject'!! |
| 201 |
|
// for security reasons disabled at ClientBackend!!! |
| 202 |
|
if($type == 'commit') { |
| 203 |
|
$args = array( 'guid' => $this->data[guid], 'data' => $this->data ); |
| 204 |
|
$this->pObject->backend->send('saveUser', $args, array( utf8 => 1) ); |
| 205 |
|
$this->_save_local(); |
| 206 |
|
$this->refresh(); |
| 207 |
|
} |
| 208 |
// invalidate data only if it's not for caching purposes |
// invalidate data only if it's not for caching purposes |
| 209 |
if ($type != 'cache') { |
if ($type != 'cache') { |
| 210 |
$this->meta[data_ready] = 0; |
$this->meta[data_ready] = 0; |
| 211 |
} |
} |
| 212 |
} |
} |
| 213 |
|
|
| 214 |
|
function _save_local() { |
| 215 |
|
connectdb(); |
| 216 |
|
$username = $this->get('userData.username'); |
| 217 |
|
$password = $this->get('userData.password'); |
| 218 |
|
$sql = "UPDATE td_users SET pass='$password' WHERE uname='$username'"; |
| 219 |
|
$res = send_sql($sql); |
| 220 |
|
} |
| 221 |
|
|
| 222 |
function save() { |
function save() { |
| 223 |
$this->_doDataReady(); |
$this->_doDataReady(); |
| 225 |
} |
} |
| 226 |
|
|
| 227 |
function create() { |
function create() { |
| 228 |
$this->_save(); |
// How THIS can function??? we will fool ourselves... |
| 229 |
$attr = $this->pObject->getAttributes(); |
//$this->_save(); |
| 230 |
|
//$attr = $this->pObject->getResult(); |
| 231 |
|
$this->_create($this->data); |
| 232 |
|
} |
| 233 |
|
|
| 234 |
|
function createGuest() { |
| 235 |
|
if($this->isLoggedOn) { return; } |
| 236 |
|
//$this->_save(); |
| 237 |
|
//$attr = $this->pObject->getResult(); |
| 238 |
//print DumpVar($attr); |
//print DumpVar($attr); |
| 239 |
$this->_create($attr); |
$data = $this->_createGuest(); |
| 240 |
|
return $data; |
| 241 |
|
} |
| 242 |
|
|
| 243 |
|
function createTerminalUser() { |
| 244 |
|
if($this->isLoggedOn) { return; } |
| 245 |
|
//$this->_save(); |
| 246 |
|
//$attr = $this->pObject->getResult(); |
| 247 |
|
//print DumpVar($attr); |
| 248 |
|
$data = $this->_createTerminalUser(); |
| 249 |
|
return $data; |
| 250 |
} |
} |
| 251 |
|
|
| 252 |
function _create($result) { |
function _create($result) { |
| 253 |
|
global $site; |
| 254 |
|
//print "saving to backend: " . dumpVar($result) . "<br>"; |
| 255 |
|
$response = $this->pObject->backend->send('createUser', array('data' => $result), array( utf8 => 1) ); |
| 256 |
|
$objectId = $response[oid]; |
| 257 |
|
if($objectId) { |
| 258 |
|
connectdb(); |
| 259 |
|
$guid = $response[guid]; |
| 260 |
|
$username = $this->get('userData.username'); |
| 261 |
|
$password = $this->get('userData.password'); |
| 262 |
|
$sql = "INSERT into td_users VALUES ( '$objectId', '$guid', '', '$username', '$password','' )"; |
| 263 |
|
$res = send_sql($sql); |
| 264 |
|
} |
| 265 |
|
else { |
| 266 |
|
// TODO: handle this with a generic rpc-debug/pending function |
| 267 |
|
$site->session->set('commit_error', array( form => getlt('page/register/notify/rpc_error') )); |
| 268 |
|
$site->redirect( getlink('/pub/register/') ); |
| 269 |
|
} |
| 270 |
|
//$this->_init($objectId); |
| 271 |
|
} |
| 272 |
|
|
| 273 |
|
function _createGuest() { |
| 274 |
|
global $site; |
| 275 |
//print "saving to backend: " . dumpVar($result) . "<br>"; |
//print "saving to backend: " . dumpVar($result) . "<br>"; |
| 276 |
$response = $this->pObject->backend->send('createUser', array('data' => $result) ); |
if(!$this->pObject) { |
| 277 |
|
$cache_key = php::CreateGUID() . "_guest"; |
| 278 |
|
$rpcinfo = $this->site->configuration->get("rpcinfo"); |
| 279 |
|
$pObject = mkObject('DesignPattern::RemoteProxy', $cache_key, array( key => 1, command => 'createGuestUser', '', remote => 1, rpcinfo => $rpcinfo, cache => array( db => 1, session => 1 ), connect => 1 ) ); |
| 280 |
|
$response = $pObject->getResult(); |
| 281 |
|
} else { |
| 282 |
|
$response = $this->pObject->backend->send('createGuestUser'); |
| 283 |
|
} |
| 284 |
|
//print "response: " . Dumper($response) . "<br>"; |
| 285 |
$objectId = $response[oid]; |
$objectId = $response[oid]; |
| 286 |
|
if($objectId) { |
| 287 |
|
return $response; |
| 288 |
|
} |
| 289 |
|
else { |
| 290 |
|
// TODO: handle this with a generic rpc-debug/pending function |
| 291 |
|
$site->session->set('login_error', 'rpc_error'); |
| 292 |
|
$site->redirect( getlink('/pub/login/') ); |
| 293 |
|
} |
| 294 |
//$this->_init($objectId); |
//$this->_init($objectId); |
| 295 |
} |
} |
| 296 |
|
|
| 297 |
function _getHKR($key) { |
function _createTerminalUser() { |
| 298 |
$attr_arr = split('\.', $key); |
global $site; |
| 299 |
$attr_hkr = '["' . join('"]["', $attr_arr) . '"]'; |
//print "saving to backend: " . dumpVar($result) . "<br>"; |
| 300 |
return $attr_hkr; |
if(!$this->pObject) { |
| 301 |
|
$rpcinfo = $this->site->configuration->get("rpcinfo"); |
| 302 |
|
$backend = mkObject('DataSource::Proxy::XMLRPC', $rpcinfo); |
| 303 |
|
//$pObject = mkObject('DesignPattern::RemoteProxy', 'createTerminalUser', array( key => 1, command => 'createTerminalUser', array('terminalID' => $site->session->get('validTerminal'), ), remote => 1, rpcinfo => $rpcinfo, cache => array( db => 1, session => 0 ), connect => 1 ) ); |
| 304 |
|
//$response = $pObject->getResult(); |
| 305 |
|
$response = $backend->send('createTerminalUser', array('terminalID' => $site->session->get('validTerminal')), array( utf8 => 1) ); |
| 306 |
|
} else { |
| 307 |
|
$response = $this->pObject->backend->send('createTerminalUser', array('terminalID' => $site->session->get('validTerminal')), array( utf8 => 1) ); |
| 308 |
|
} |
| 309 |
|
//print "response: " . Dumper($response) . "<br>"; |
| 310 |
|
$objectId = $response[oid]; |
| 311 |
|
if($objectId) { |
| 312 |
|
return $response; |
| 313 |
|
} elseif($response[error]) { |
| 314 |
|
$site->session->set('site_error', $response[error]); |
| 315 |
|
} else { |
| 316 |
|
// TODO: handle this with a generic rpc-debug/pending function |
| 317 |
|
$site->session->set('login_error', 'rpc_error'); |
| 318 |
|
$site->redirect( getlink('/pub/login/') ); |
| 319 |
|
} |
| 320 |
|
//$this->_init($objectId); |
| 321 |
} |
} |
| 322 |
|
|
| 323 |
|
|
| 324 |
function get($attr) { |
function get($attr) { |
| 325 |
$this->_doDataReady(); |
$this->_doDataReady(); |
| 326 |
$hkr = $this->_getHKR($attr); |
$deep = new Data_Deep($this->data); |
| 327 |
$evalstr = 'return $this->data' . $hkr . ';'; |
return $deep->get($attr); |
|
$val = eval($evalstr); |
|
|
return $val; |
|
| 328 |
} |
} |
| 329 |
function set($attr, $val) { |
function set($attr, $val) { |
| 330 |
$this->_doDataReady(); |
$this->_doDataReady(); |
| 331 |
$hkr = $this->_getHKR($attr); |
$deep = new Data_Deep($this->data); |
| 332 |
$evalstr = '$this->data' . $hkr . ' = \'' . $val . '\';'; |
$deep->set($attr, $val); |
|
eval($evalstr); |
|
| 333 |
} |
} |
| 334 |
|
|
| 335 |
function isLoggedOn() { |
function isLoggedOn() { |
| 341 |
|
|
| 342 |
//===== function userlogin ========================= |
//===== function userlogin ========================= |
| 343 |
function login($user,$passwd) { |
function login($user,$passwd) { |
| 344 |
connectdb(); |
connectdb(); |
| 345 |
//$sql = "SELECT * FROM td_users WHERE uname='$user'"; |
//$sql = "SELECT * FROM td_users WHERE uname='$user'"; |
| 346 |
$sql = "SELECT user_oid, guid, uname, pass FROM td_users WHERE uname='$user'"; |
$sql = "SELECT user_oid, guid, uname, pass FROM td_users WHERE uname='$user'"; |
| 347 |
if ($res=send_sql($sql)) { |
if ($res=send_sql($sql)) { |
| 348 |
$row = mysql_fetch_array($res,MYSQL_ASSOC); |
$row = mysql_fetch_array($res,MYSQL_ASSOC); |
| 349 |
if (!is_array($row)) { return 0; } |
if (!is_array($row)) { return 0; } |
| 350 |
} |
} |
| 351 |
if ($row[pass] == $passwd) { |
if ($row[pass] == $passwd) { |
| 352 |
//return $uservars_db; |
//return $uservars_db; |
| 353 |
// store 1st priority user-data to state |
// store 1st priority user-data to state |
| 354 |
$this->state[id] = $row[user_oid]; |
$this->state[id] = $row[user_oid]; |
| 355 |
$this->state[guid] = $row[guid]; |
$this->state[guid] = $row[guid]; |
| 356 |
$this->state[status] = $this->meta[logontoken]; |
$this->state[status] = $this->meta[logontoken]; |
| 357 |
$this->_saveState(); |
$this->_saveState(); |
| 358 |
$this->site->log( get_class($this) . "->login ok", LOG_DEBUG ); |
$this->site->log( get_class($this) . "->login ok", PEAR_LOG_NOTICE ); |
| 359 |
return 1; |
return 1; |
| 360 |
} else { |
} else { |
| 361 |
return 0; |
return 0; |
| 362 |
} |
} |
| 363 |
} |
} |
| 364 |
|
|
| 365 |
|
//===== function guestlogin ========================= |
| 366 |
|
function loginGuest($data) { |
| 367 |
|
// store 1st priority user-data to state |
| 368 |
|
$this->state[id] = $data[oid]; |
| 369 |
|
$this->state[guid] = $data[guid]; |
| 370 |
|
$this->state[status] = $this->meta[logontoken]; |
| 371 |
|
$this->_saveState(); |
| 372 |
|
$this->site->log( get_class($this) . "->guest-login ok", PEAR_LOG_NOTICE ); |
| 373 |
|
return 1; |
| 374 |
|
} |
| 375 |
|
|
| 376 |
|
//===== function terminallogin ========================= |
| 377 |
|
function loginTerminalUser($data) { |
| 378 |
|
// store 1st priority user-data to state |
| 379 |
|
$this->state[id] = $data[oid]; |
| 380 |
|
$this->state[guid] = $data[guid]; |
| 381 |
|
$this->state[status] = $this->meta[logontoken]; |
| 382 |
|
$this->_saveState(); |
| 383 |
|
$this->site->log( get_class($this) . "->terminalUser-login ok", PEAR_LOG_NOTICE ); |
| 384 |
|
return 1; |
| 385 |
|
} |
| 386 |
|
|
| 387 |
function exists($string) { |
function exists($string) { |
| 388 |
connectdb(); |
connectdb(); |
| 400 |
|
|
| 401 |
function update($vars) { |
function update($vars) { |
| 402 |
$this->setPostVars($vars); |
$this->setPostVars($vars); |
| 403 |
//print Dumper($vars); |
//print Dumper($vars); |
| 404 |
$data = $this->_transformInputData($vars); |
$data = $this->_transformInputData($vars); |
| 405 |
|
//print Dumper($data); |
| 406 |
$this->_saveData($data); |
$this->_saveData($data); |
| 407 |
} |
} |
| 408 |
|
|
| 411 |
$mapping_uservars2data = array_flip($def_mapping[data2uservars]); |
$mapping_uservars2data = array_flip($def_mapping[data2uservars]); |
| 412 |
foreach ($uservars as $key => $val) { |
foreach ($uservars as $key => $val) { |
| 413 |
$key_target = $mapping_uservars2data[$key]; |
$key_target = $mapping_uservars2data[$key]; |
| 414 |
//print "$key => $key_target: $val<br>"; |
if($key_target != '') { |
| 415 |
$target[$key_target] = $val; |
//print "$key => $key_target: $val<br>"; |
| 416 |
|
$target[$key_target] = $val; |
| 417 |
|
} |
| 418 |
} |
} |
| 419 |
return $target; |
return $target; |
| 420 |
} |
} |
| 426 |
// get information about user from site |
// get information about user from site |
| 427 |
$userid = $this->getUserId(); |
$userid = $this->getUserId(); |
| 428 |
|
|
| 429 |
$this->site->log( get_class($this) . "->logout: userid $userid", LOG_DEBUG ); |
$this->site->log( get_class($this) . "->logout: userid $userid", PEAR_LOG_NOTICE ); |
| 430 |
|
|
| 431 |
// get information about session from php |
// get information about session from php |
| 432 |
$session_id = session_id(); |
$session_id = session_id(); |
| 475 |
} |
} |
| 476 |
|
|
| 477 |
function refresh() { |
function refresh() { |
| 478 |
if ($this->pObject) {$this->pObject->flushState();} |
if ($this->pObject) {$this->pObject->flush();} |
| 479 |
$this->meta[data_ready] = 0; |
$this->meta[data_ready] = 0; |
| 480 |
} |
} |
| 481 |
|
|
| 521 |
} |
} |
| 522 |
|
|
| 523 |
function hadTimeout() { |
function hadTimeout() { |
| 524 |
if ($this->state[autologout]) { return 1; } |
if ($this->state[autologout]) { $this->state[autologout] = ''; return 1; } |
| 525 |
|
} |
| 526 |
|
|
| 527 |
|
function getNewMessages() { |
| 528 |
|
$messages = array(); |
| 529 |
|
$userguid = $this->getUserGuid(); |
| 530 |
|
connectdb(); |
| 531 |
|
$sql = "SELECT * FROM td_message WHERE target_guid='$userguid' AND new='1'"; |
| 532 |
|
if ($res=send_sql($sql)) { |
| 533 |
|
while($row = mysql_fetch_array($res,MYSQL_ASSOC)) { |
| 534 |
|
if (!is_array($row)) { return 0; } |
| 535 |
|
array_push($messages, $row); |
| 536 |
|
} |
| 537 |
|
} |
| 538 |
|
return $messages; |
| 539 |
|
} |
| 540 |
|
|
| 541 |
|
function markNewMessage($mid) { |
| 542 |
|
connectdb(); |
| 543 |
|
$sql = "UPDATE td_message SET new='0' WHERE mid='$mid'"; |
| 544 |
|
if(!$res=send_sql($sql)) { |
| 545 |
|
return "Message not found!"; |
| 546 |
|
} |
| 547 |
} |
} |
| 548 |
|
|
| 549 |
} |
} |