| 3 |
* This file contains the Tracker::User module. |
* This file contains the Tracker::User module. |
| 4 |
* |
* |
| 5 |
* @author Andreas Motl <andreas.motl@ilo.de> |
* @author Andreas Motl <andreas.motl@ilo.de> |
| 6 |
|
* @author Sebastian Utz <su@rtme.net> |
| 7 |
* @package org.netfrag.flib |
* @package org.netfrag.flib |
| 8 |
* @name Tracker::User |
* @name Tracker::User |
| 9 |
* |
* |
| 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 |
// Revision 1.15 2004/03/11 21:04:48 jonen |
| 40 |
// +changed backend-functions to only get/save User ONLY not SOME object (security!) |
// +changed backend-functions to only get/save User ONLY not SOME object (security!) |
| 41 |
// |
// |
| 172 |
//$this->pObject = new ProxyObject($this->getUserGuid(), array( remote => 1, classname => "NetPerson", guid => 1) ); |
//$this->pObject = new ProxyObject($this->getUserGuid(), array( remote => 1, classname => "NetPerson", guid => 1) ); |
| 173 |
$rpcinfo = $this->site->configuration->get("rpcinfo"); |
$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 ) ); |
//$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 |
$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 ) ); |
$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()) { |
if ($this->getUserGuid()) { |
| 178 |
$this->data = $this->pObject->getResult(); |
$this->data = $this->pObject->getResult(); |
| 179 |
} |
} |
| 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 |
|
|
| 202 |
if($type == 'commit') { |
if($type == 'commit') { |
| 203 |
$args = array( 'guid' => $this->data[guid], 'data' => $this->data ); |
$args = array( 'guid' => $this->data[guid], 'data' => $this->data ); |
| 204 |
$this->pObject->backend->send('saveUser', $args, array( utf8 => 1) ); |
$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->getResult(); |
//$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); |
| 239 |
|
$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); |
//print DumpVar($attr); |
| 248 |
$this->_create($attr); |
$data = $this->_createTerminalUser(); |
| 249 |
|
return $data; |
| 250 |
} |
} |
| 251 |
|
|
| 252 |
function _create($result) { |
function _create($result) { |
| 253 |
global $site; |
global $site; |
| 254 |
//print "saving to backend: " . dumpVar($result) . "<br>"; |
//print "saving to backend: " . dumpVar($result) . "<br>"; |
| 255 |
$response = $this->pObject->backend->send('createUser', array('data' => $result) ); |
$response = $this->pObject->backend->send('createUser', array('data' => $result), array( utf8 => 1) ); |
| 256 |
$objectId = $response[oid]; |
$objectId = $response[oid]; |
| 257 |
if($objectId) { |
if($objectId) { |
| 258 |
connectdb(); |
connectdb(); |
| 264 |
} |
} |
| 265 |
else { |
else { |
| 266 |
// TODO: handle this with a generic rpc-debug/pending function |
// TODO: handle this with a generic rpc-debug/pending function |
| 267 |
$site->session->set('register_error', 'rpc_error'); |
$site->session->set('commit_error', array( form => getlt('page/register/notify/rpc_error') )); |
| 268 |
$site->redirect( getlink('/pub/register/') ); |
$site->redirect( getlink('/pub/register/') ); |
| 269 |
} |
} |
| 270 |
//$this->_init($objectId); |
//$this->_init($objectId); |
| 271 |
} |
} |
| 272 |
|
|
| 273 |
|
function _createGuest() { |
| 274 |
|
global $site; |
| 275 |
|
//print "saving to backend: " . dumpVar($result) . "<br>"; |
| 276 |
|
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]; |
| 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); |
| 295 |
|
} |
| 296 |
|
|
| 297 |
|
function _createTerminalUser() { |
| 298 |
|
global $site; |
| 299 |
|
//print "saving to backend: " . dumpVar($result) . "<br>"; |
| 300 |
|
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 |
$deep = new Data_Deep($this->data); |
$deep = new Data_Deep($this->data); |
| 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]; |
| 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 |
|
|
| 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 |
|
|
| 523 |
function hadTimeout() { |
function hadTimeout() { |
| 524 |
if ($this->state[autologout]) { $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 |
} |
} |
| 550 |
|
|