| 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.19 2004/06/22 09:18:47 jonen |
| 17 |
|
// removed debug dumps |
| 18 |
|
// |
| 19 |
|
// Revision 1.17 2004/06/07 16:54:53 joko |
| 20 |
|
// modified cache-key |
| 21 |
|
// added cache-control |
| 22 |
|
// |
| 23 |
|
// Revision 1.16 2004/05/06 13:02:09 jonen |
| 24 |
|
// + added/modified functions related to User-Messages |
| 25 |
|
// |
| 26 |
|
// Revision 1.15 2004/03/11 21:04:48 jonen |
| 27 |
|
// +changed backend-functions to only get/save User ONLY not SOME object (security!) |
| 28 |
|
// |
| 29 |
|
// Revision 1.14 2003/07/02 11:02:09 joko |
| 30 |
|
// + fixed bug with create/_create |
| 31 |
|
// |
| 32 |
|
// Revision 1.13 2003/04/04 02:15:09 joko |
| 33 |
|
// renamed method of helper object |
| 34 |
|
// |
| 35 |
|
// Revision 1.12 2003/03/03 21:20:47 joko |
| 36 |
|
// mungled the namespaces |
| 37 |
|
// |
| 38 |
|
// Revision 1.11 2003/02/14 14:22:06 joko |
| 39 |
|
// + always (re-)tries to connect |
| 40 |
|
// |
| 41 |
|
// Revision 1.10 2003/02/13 21:58:39 joko |
| 42 |
|
// + caching mechanisms more configurable now |
| 43 |
|
// |
| 44 |
|
// Revision 1.9 2003/02/09 17:46:26 joko |
| 45 |
|
// + now utilizing DesignPattern::RemoteProxy and Data::Deep |
| 46 |
|
// |
| 47 |
|
// Revision 1.8 2002/12/28 01:16:42 jonen |
| 48 |
|
// + added clear of $this->state[autologout] at 'hadTimeout()' |
| 49 |
|
// |
| 50 |
|
// Revision 1.7 2002/12/23 11:32:28 jonen |
| 51 |
|
// + added inserting of uservars on '_create' to frontend db(needed to login user after create!) |
| 52 |
|
// + added hard link to page 'pub/register', TODO: move this out here |
| 53 |
|
// |
| 54 |
// Revision 1.6 2002/12/18 22:46:06 jonen |
// Revision 1.6 2002/12/18 22:46:06 jonen |
| 55 |
// + added function 'getUserGuid()' |
// + added function 'getUserGuid()' |
| 56 |
// (returns user's 'guid' read from database at function 'login()' (now)) |
// (returns user's 'guid' read from database at function 'login()' (now)) |
| 112 |
// |
// |
| 113 |
// ----------------------------------------------------------------------------- |
// ----------------------------------------------------------------------------- |
| 114 |
|
|
| 115 |
|
|
| 116 |
|
/** |
| 117 |
|
* This is the User class. |
| 118 |
|
* |
| 119 |
|
* @author Andreas Motl <andreas.motl@ilo.de> |
| 120 |
|
* @package org.netfrag.flib |
| 121 |
|
* @name Tracker::User |
| 122 |
|
* |
| 123 |
|
*/ |
| 124 |
class User { |
class User { |
| 125 |
|
|
| 126 |
var $state; |
var $state; |
| 155 |
|
|
| 156 |
|
|
| 157 |
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(); |
|
|
} |
|
| 158 |
$this->meta[data_ready] = 1; |
$this->meta[data_ready] = 1; |
| 159 |
|
//$this->pObject = new ProxyObject($this->getUserGuid(), array( remote => 1, classname => "NetPerson", guid => 1) ); |
| 160 |
|
$rpcinfo = $this->site->configuration->get("rpcinfo"); |
| 161 |
|
//$this->pObject = mkObject('DesignPattern::RemoteProxy', $this->getUserGuid(), array( remote => 1, classname => "NetPerson", guid => 1, rpcinfo => $rpcinfo, cache => array( db => 1, session => 1 ), connect => 1 ) ); |
| 162 |
|
$cache_key = $this->getUserGuid() . "_user"; |
| 163 |
|
$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 ) ); |
| 164 |
|
if ($this->getUserGuid()) { |
| 165 |
|
$this->data = $this->pObject->getResult(); |
| 166 |
|
} |
| 167 |
} |
} |
| 168 |
|
|
| 169 |
function _saveData($newRawData) { |
function _saveData($newRawData) { |
| 170 |
|
|
| 171 |
|
//print "newRawData: " . Dumper($newRawData) . "<br>"; |
| 172 |
foreach ($newRawData as $key => $val) { |
foreach ($newRawData as $key => $val) { |
| 173 |
//print "$key => $val<br>"; |
//print "$key => $val<br>"; |
| 174 |
$this->set($key, $val); |
$this->set($key, $val); |
| 182 |
|
|
| 183 |
function _save($type = '') { |
function _save($type = '') { |
| 184 |
//print Dumper($this->data); |
//print Dumper($this->data); |
| 185 |
$this->pObject->save($this->data, $type); |
//$this->pObject->save($this->data, $type); |
| 186 |
|
// new of 2004-03-08: don't use generic 'saveObject'!! |
| 187 |
|
// for security reasons disabled at ClientBackend!!! |
| 188 |
|
if($type == 'commit') { |
| 189 |
|
$args = array( 'guid' => $this->data[guid], 'data' => $this->data ); |
| 190 |
|
$this->pObject->backend->send('saveUser', $args, array( utf8 => 1) ); |
| 191 |
|
$this->_save_local(); |
| 192 |
|
$this->refresh(); |
| 193 |
|
} |
| 194 |
// invalidate data only if it's not for caching purposes |
// invalidate data only if it's not for caching purposes |
| 195 |
if ($type != 'cache') { |
if ($type != 'cache') { |
| 196 |
$this->meta[data_ready] = 0; |
$this->meta[data_ready] = 0; |
| 197 |
} |
} |
| 198 |
} |
} |
| 199 |
|
|
| 200 |
|
function _save_local() { |
| 201 |
|
connectdb(); |
| 202 |
|
$username = $this->get('userData.username'); |
| 203 |
|
$password = $this->get('userData.password'); |
| 204 |
|
$sql = "UPDATE td_users SET pass='$password' WHERE uname='$username'"; |
| 205 |
|
$res = send_sql($sql); |
| 206 |
|
} |
| 207 |
|
|
| 208 |
function save() { |
function save() { |
| 209 |
$this->_doDataReady(); |
$this->_doDataReady(); |
| 212 |
|
|
| 213 |
function create() { |
function create() { |
| 214 |
$this->_save(); |
$this->_save(); |
| 215 |
$attr = $this->pObject->getAttributes(); |
$attr = $this->pObject->getResult(); |
| 216 |
//print DumpVar($attr); |
//print DumpVar($attr); |
| 217 |
$this->_create($attr); |
$this->_create($attr); |
| 218 |
} |
} |
| 219 |
|
|
| 220 |
|
function createGuest() { |
| 221 |
|
if($this->isLoggedOn) { return; } |
| 222 |
|
//$this->_save(); |
| 223 |
|
//$attr = $this->pObject->getResult(); |
| 224 |
|
//print DumpVar($attr); |
| 225 |
|
$data = $this->_createGuest(); |
| 226 |
|
return $data; |
| 227 |
|
} |
| 228 |
|
|
| 229 |
function _create($result) { |
function _create($result) { |
| 230 |
|
global $site; |
| 231 |
//print "saving to backend: " . dumpVar($result) . "<br>"; |
//print "saving to backend: " . dumpVar($result) . "<br>"; |
| 232 |
$response = $this->pObject->backend->send('createUser', array('data' => $result) ); |
$response = $this->pObject->backend->send('createUser', array('data' => $result) ); |
| 233 |
$objectId = $response[oid]; |
$objectId = $response[oid]; |
| 234 |
|
if($objectId) { |
| 235 |
|
connectdb(); |
| 236 |
|
$guid = $response[guid]; |
| 237 |
|
$username = $this->get('userData.username'); |
| 238 |
|
$password = $this->get('userData.password'); |
| 239 |
|
$sql = "INSERT into td_users VALUES ( '$objectId', '$guid', '', '$username', '$password','' )"; |
| 240 |
|
$res = send_sql($sql); |
| 241 |
|
} |
| 242 |
|
else { |
| 243 |
|
// TODO: handle this with a generic rpc-debug/pending function |
| 244 |
|
$site->session->set('register_error', 'rpc_error'); |
| 245 |
|
$site->redirect( getlink('/pub/register/') ); |
| 246 |
|
} |
| 247 |
//$this->_init($objectId); |
//$this->_init($objectId); |
| 248 |
} |
} |
| 249 |
|
|
| 250 |
function _getHKR($key) { |
function _createGuest() { |
| 251 |
$attr_arr = split('\.', $key); |
global $site; |
| 252 |
$attr_hkr = '["' . join('"]["', $attr_arr) . '"]'; |
//print "saving to backend: " . dumpVar($result) . "<br>"; |
| 253 |
return $attr_hkr; |
if(!$this->pObject) { |
| 254 |
|
$cache_key = php::CreateGUID() . "_guest"; |
| 255 |
|
$rpcinfo = $this->site->configuration->get("rpcinfo"); |
| 256 |
|
$pObject = mkObject('DesignPattern::RemoteProxy', $cache_key, array( key => 1, command => 'createGuestUser', '', remote => 1, rpcinfo => $rpcinfo, cache => array( db => 1, session => 1 ), connect => 1 ) ); |
| 257 |
|
$response = $pObject->getResult(); |
| 258 |
|
} else { |
| 259 |
|
$response = $this->pObject->backend->send('createGuestUser'); |
| 260 |
|
} |
| 261 |
|
//print "response: " . Dumper($response) . "<br>"; |
| 262 |
|
$objectId = $response[oid]; |
| 263 |
|
if($objectId) { |
| 264 |
|
return $response; |
| 265 |
|
} |
| 266 |
|
else { |
| 267 |
|
// TODO: handle this with a generic rpc-debug/pending function |
| 268 |
|
$site->session->set('login_error', 'rpc_error'); |
| 269 |
|
$site->redirect( getlink('/pub/login/') ); |
| 270 |
|
} |
| 271 |
|
//$this->_init($objectId); |
| 272 |
} |
} |
| 273 |
|
|
| 274 |
function get($attr) { |
function get($attr) { |
| 275 |
$this->_doDataReady(); |
$this->_doDataReady(); |
| 276 |
$hkr = $this->_getHKR($attr); |
$deep = new Data_Deep($this->data); |
| 277 |
$evalstr = 'return $this->data' . $hkr . ';'; |
return $deep->get($attr); |
|
$val = eval($evalstr); |
|
|
return $val; |
|
| 278 |
} |
} |
| 279 |
function set($attr, $val) { |
function set($attr, $val) { |
| 280 |
$this->_doDataReady(); |
$this->_doDataReady(); |
| 281 |
$hkr = $this->_getHKR($attr); |
$deep = new Data_Deep($this->data); |
| 282 |
$evalstr = '$this->data' . $hkr . ' = \'' . $val . '\';'; |
$deep->set($attr, $val); |
|
eval($evalstr); |
|
| 283 |
} |
} |
| 284 |
|
|
| 285 |
function isLoggedOn() { |
function isLoggedOn() { |
| 291 |
|
|
| 292 |
//===== function userlogin ========================= |
//===== function userlogin ========================= |
| 293 |
function login($user,$passwd) { |
function login($user,$passwd) { |
| 294 |
connectdb(); |
connectdb(); |
| 295 |
//$sql = "SELECT * FROM td_users WHERE uname='$user'"; |
//$sql = "SELECT * FROM td_users WHERE uname='$user'"; |
| 296 |
$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'"; |
| 297 |
if ($res=send_sql($sql)) { |
if ($res=send_sql($sql)) { |
| 298 |
$row = mysql_fetch_array($res,MYSQL_ASSOC); |
$row = mysql_fetch_array($res,MYSQL_ASSOC); |
| 299 |
if (!is_array($row)) { return 0; } |
if (!is_array($row)) { return 0; } |
| 300 |
} |
} |
| 301 |
if ($row[pass] == $passwd) { |
if ($row[pass] == $passwd) { |
| 302 |
//return $uservars_db; |
//return $uservars_db; |
| 303 |
// store 1st priority user-data to state |
// store 1st priority user-data to state |
| 304 |
$this->state[id] = $row[user_oid]; |
$this->state[id] = $row[user_oid]; |
| 305 |
$this->state[guid] = $row[guid]; |
$this->state[guid] = $row[guid]; |
| 306 |
$this->state[status] = $this->meta[logontoken]; |
$this->state[status] = $this->meta[logontoken]; |
| 307 |
$this->_saveState(); |
$this->_saveState(); |
| 308 |
$this->site->log( get_class($this) . "->login ok", LOG_DEBUG ); |
$this->site->log( get_class($this) . "->login ok", PEAR_LOG_NOTICE ); |
| 309 |
return 1; |
return 1; |
| 310 |
} else { |
} else { |
| 311 |
return 0; |
return 0; |
| 312 |
} |
} |
| 313 |
} |
} |
| 314 |
|
|
| 315 |
|
//===== function guestlogin ========================= |
| 316 |
|
function loginGuest($data) { |
| 317 |
|
// store 1st priority user-data to state |
| 318 |
|
$this->state[id] = $data[oid]; |
| 319 |
|
$this->state[guid] = $data[guid]; |
| 320 |
|
$this->state[status] = $this->meta[logontoken]; |
| 321 |
|
$this->_saveState(); |
| 322 |
|
$this->site->log( get_class($this) . "->guest-login ok", PEAR_LOG_NOTICE ); |
| 323 |
|
return 1; |
| 324 |
|
} |
| 325 |
|
|
| 326 |
function exists($string) { |
function exists($string) { |
| 327 |
connectdb(); |
connectdb(); |
| 339 |
|
|
| 340 |
function update($vars) { |
function update($vars) { |
| 341 |
$this->setPostVars($vars); |
$this->setPostVars($vars); |
| 342 |
//print Dumper($vars); |
//print Dumper($vars); |
| 343 |
$data = $this->_transformInputData($vars); |
$data = $this->_transformInputData($vars); |
| 344 |
|
//print Dumper($data); |
| 345 |
$this->_saveData($data); |
$this->_saveData($data); |
| 346 |
} |
} |
| 347 |
|
|
| 350 |
$mapping_uservars2data = array_flip($def_mapping[data2uservars]); |
$mapping_uservars2data = array_flip($def_mapping[data2uservars]); |
| 351 |
foreach ($uservars as $key => $val) { |
foreach ($uservars as $key => $val) { |
| 352 |
$key_target = $mapping_uservars2data[$key]; |
$key_target = $mapping_uservars2data[$key]; |
| 353 |
//print "$key => $key_target: $val<br>"; |
if($key_target != '') { |
| 354 |
$target[$key_target] = $val; |
//print "$key => $key_target: $val<br>"; |
| 355 |
|
$target[$key_target] = $val; |
| 356 |
|
} |
| 357 |
} |
} |
| 358 |
return $target; |
return $target; |
| 359 |
} |
} |
| 365 |
// get information about user from site |
// get information about user from site |
| 366 |
$userid = $this->getUserId(); |
$userid = $this->getUserId(); |
| 367 |
|
|
| 368 |
$this->site->log( get_class($this) . "->logout: userid $userid", LOG_DEBUG ); |
$this->site->log( get_class($this) . "->logout: userid $userid", PEAR_LOG_NOTICE ); |
| 369 |
|
|
| 370 |
// get information about session from php |
// get information about session from php |
| 371 |
$session_id = session_id(); |
$session_id = session_id(); |
| 414 |
} |
} |
| 415 |
|
|
| 416 |
function refresh() { |
function refresh() { |
| 417 |
if ($this->pObject) {$this->pObject->flushState();} |
if ($this->pObject) {$this->pObject->flush();} |
| 418 |
$this->meta[data_ready] = 0; |
$this->meta[data_ready] = 0; |
| 419 |
} |
} |
| 420 |
|
|
| 460 |
} |
} |
| 461 |
|
|
| 462 |
function hadTimeout() { |
function hadTimeout() { |
| 463 |
if ($this->state[autologout]) { return 1; } |
if ($this->state[autologout]) { $this->state[autologout] = ''; return 1; } |
| 464 |
|
} |
| 465 |
|
|
| 466 |
|
function getNewMessages() { |
| 467 |
|
$messages = array(); |
| 468 |
|
$userguid = $this->getUserGuid(); |
| 469 |
|
connectdb(); |
| 470 |
|
$sql = "SELECT * FROM td_message WHERE target_guid='$userguid' AND new='1'"; |
| 471 |
|
if ($res=send_sql($sql)) { |
| 472 |
|
while($row = mysql_fetch_array($res,MYSQL_ASSOC)) { |
| 473 |
|
if (!is_array($row)) { return 0; } |
| 474 |
|
array_push($messages, $row); |
| 475 |
|
} |
| 476 |
|
} |
| 477 |
|
return $messages; |
| 478 |
|
} |
| 479 |
|
|
| 480 |
|
function markNewMessage($mid) { |
| 481 |
|
connectdb(); |
| 482 |
|
$sql = "UPDATE td_message SET new='0' WHERE mid='$mid'"; |
| 483 |
|
if(!$res=send_sql($sql)) { |
| 484 |
|
return "Message not found!"; |
| 485 |
|
} |
| 486 |
} |
} |
| 487 |
|
|
| 488 |
} |
} |