| 13 |
// $Id$ |
// $Id$ |
| 14 |
// ----------------------------------------------------------------------------- |
// ----------------------------------------------------------------------------- |
| 15 |
// $Log$ |
// $Log$ |
| 16 |
|
// Revision 1.18 2004/06/22 09:15:50 jonen |
| 17 |
|
// bugfix: use unique cache-keys at createGuest |
| 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 |
// Revision 1.15 2004/03/11 21:04:48 jonen |
| 27 |
// +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!) |
| 28 |
// |
// |
| 159 |
//$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) ); |
| 160 |
$rpcinfo = $this->site->configuration->get("rpcinfo"); |
$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 ) ); |
//$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 |
$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"; |
| 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()) { |
if ($this->getUserGuid()) { |
| 165 |
$this->data = $this->pObject->getResult(); |
$this->data = $this->pObject->getResult(); |
| 166 |
} |
} |
| 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); |
| 188 |
if($type == 'commit') { |
if($type == 'commit') { |
| 189 |
$args = array( 'guid' => $this->data[guid], 'data' => $this->data ); |
$args = array( 'guid' => $this->data[guid], 'data' => $this->data ); |
| 190 |
$this->pObject->backend->send('saveUser', $args, array( utf8 => 1) ); |
$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(); |
| 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; |
global $site; |
| 231 |
//print "saving to backend: " . dumpVar($result) . "<br>"; |
//print "saving to backend: " . dumpVar($result) . "<br>"; |
| 247 |
//$this->_init($objectId); |
//$this->_init($objectId); |
| 248 |
} |
} |
| 249 |
|
|
| 250 |
|
function _createGuest() { |
| 251 |
|
global $site; |
| 252 |
|
//print "saving to backend: " . dumpVar($result) . "<br>"; |
| 253 |
|
if(!$this->pObject) { |
| 254 |
|
$cache_key = php::CreateGUID() . "_guest"; |
| 255 |
|
print "guest_cache_key: $cache_key <br>"; |
| 256 |
|
$rpcinfo = $this->site->configuration->get("rpcinfo"); |
| 257 |
|
$pObject = mkObject('DesignPattern::RemoteProxy', $cache_key, array( key => 1, command => 'createGuestUser', '', remote => 1, rpcinfo => $rpcinfo, cache => array( db => 1, session => 1 ), connect => 1 ) ); |
| 258 |
|
$response = $pObject->getResult(); |
| 259 |
|
} else { |
| 260 |
|
$response = $this->pObject->backend->send('createGuestUser'); |
| 261 |
|
} |
| 262 |
|
//print "response: " . Dumper($response) . "<br>"; |
| 263 |
|
$objectId = $response[oid]; |
| 264 |
|
if($objectId) { |
| 265 |
|
return $response; |
| 266 |
|
} |
| 267 |
|
else { |
| 268 |
|
// TODO: handle this with a generic rpc-debug/pending function |
| 269 |
|
$site->session->set('login_error', 'rpc_error'); |
| 270 |
|
$site->redirect( getlink('/pub/login/') ); |
| 271 |
|
} |
| 272 |
|
//$this->_init($objectId); |
| 273 |
|
} |
| 274 |
|
|
| 275 |
function get($attr) { |
function get($attr) { |
| 276 |
$this->_doDataReady(); |
$this->_doDataReady(); |
| 277 |
$deep = new Data_Deep($this->data); |
$deep = new Data_Deep($this->data); |
| 292 |
|
|
| 293 |
//===== function userlogin ========================= |
//===== function userlogin ========================= |
| 294 |
function login($user,$passwd) { |
function login($user,$passwd) { |
| 295 |
connectdb(); |
connectdb(); |
| 296 |
//$sql = "SELECT * FROM td_users WHERE uname='$user'"; |
//$sql = "SELECT * FROM td_users WHERE uname='$user'"; |
| 297 |
$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'"; |
| 298 |
if ($res=send_sql($sql)) { |
if ($res=send_sql($sql)) { |
| 299 |
$row = mysql_fetch_array($res,MYSQL_ASSOC); |
$row = mysql_fetch_array($res,MYSQL_ASSOC); |
| 300 |
if (!is_array($row)) { return 0; } |
if (!is_array($row)) { return 0; } |
| 301 |
} |
} |
| 302 |
if ($row[pass] == $passwd) { |
if ($row[pass] == $passwd) { |
| 303 |
//return $uservars_db; |
//return $uservars_db; |
| 304 |
// store 1st priority user-data to state |
// store 1st priority user-data to state |
| 305 |
$this->state[id] = $row[user_oid]; |
$this->state[id] = $row[user_oid]; |
| 311 |
} else { |
} else { |
| 312 |
return 0; |
return 0; |
| 313 |
} |
} |
| 314 |
} |
} |
| 315 |
|
|
| 316 |
|
//===== function guestlogin ========================= |
| 317 |
|
function loginGuest($data) { |
| 318 |
|
// store 1st priority user-data to state |
| 319 |
|
$this->state[id] = $data[oid]; |
| 320 |
|
$this->state[guid] = $data[guid]; |
| 321 |
|
$this->state[status] = $this->meta[logontoken]; |
| 322 |
|
$this->_saveState(); |
| 323 |
|
$this->site->log( get_class($this) . "->guest-login ok", PEAR_LOG_NOTICE ); |
| 324 |
|
return 1; |
| 325 |
|
} |
| 326 |
|
|
| 327 |
function exists($string) { |
function exists($string) { |
| 328 |
connectdb(); |
connectdb(); |
| 340 |
|
|
| 341 |
function update($vars) { |
function update($vars) { |
| 342 |
$this->setPostVars($vars); |
$this->setPostVars($vars); |
| 343 |
//print Dumper($vars); |
//print Dumper($vars); |
| 344 |
$data = $this->_transformInputData($vars); |
$data = $this->_transformInputData($vars); |
| 345 |
|
//print Dumper($data); |
| 346 |
$this->_saveData($data); |
$this->_saveData($data); |
| 347 |
} |
} |
| 348 |
|
|
| 415 |
} |
} |
| 416 |
|
|
| 417 |
function refresh() { |
function refresh() { |
| 418 |
if ($this->pObject) {$this->pObject->flushState();} |
if ($this->pObject) {$this->pObject->flush();} |
| 419 |
$this->meta[data_ready] = 0; |
$this->meta[data_ready] = 0; |
| 420 |
} |
} |
| 421 |
|
|
| 463 |
function hadTimeout() { |
function hadTimeout() { |
| 464 |
if ($this->state[autologout]) { $this->state[autologout] = ''; return 1; } |
if ($this->state[autologout]) { $this->state[autologout] = ''; return 1; } |
| 465 |
} |
} |
| 466 |
|
|
| 467 |
|
function getNewMessages() { |
| 468 |
|
$messages = array(); |
| 469 |
|
$userguid = $this->getUserGuid(); |
| 470 |
|
connectdb(); |
| 471 |
|
$sql = "SELECT * FROM td_message WHERE target_guid='$userguid' AND new='1'"; |
| 472 |
|
if ($res=send_sql($sql)) { |
| 473 |
|
while($row = mysql_fetch_array($res,MYSQL_ASSOC)) { |
| 474 |
|
if (!is_array($row)) { return 0; } |
| 475 |
|
array_push($messages, $row); |
| 476 |
|
} |
| 477 |
|
} |
| 478 |
|
return $messages; |
| 479 |
|
} |
| 480 |
|
|
| 481 |
|
function markNewMessage($mid) { |
| 482 |
|
connectdb(); |
| 483 |
|
$sql = "UPDATE td_message SET new='0' WHERE mid='$mid'"; |
| 484 |
|
if(!$res=send_sql($sql)) { |
| 485 |
|
return "Message not found!"; |
| 486 |
|
} |
| 487 |
|
} |
| 488 |
|
|
| 489 |
} |
} |
| 490 |
|
|