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.17 2004/06/07 16:54:53 joko |
17 |
|
// modified cache-key |
18 |
|
// added cache-control |
19 |
|
// |
20 |
|
// Revision 1.16 2004/05/06 13:02:09 jonen |
21 |
|
// + added/modified functions related to User-Messages |
22 |
|
// |
23 |
|
// Revision 1.15 2004/03/11 21:04:48 jonen |
24 |
|
// +changed backend-functions to only get/save User ONLY not SOME object (security!) |
25 |
|
// |
26 |
|
// Revision 1.14 2003/07/02 11:02:09 joko |
27 |
|
// + fixed bug with create/_create |
28 |
|
// |
29 |
|
// Revision 1.13 2003/04/04 02:15:09 joko |
30 |
|
// renamed method of helper object |
31 |
|
// |
32 |
|
// Revision 1.12 2003/03/03 21:20:47 joko |
33 |
|
// mungled the namespaces |
34 |
|
// |
35 |
|
// Revision 1.11 2003/02/14 14:22:06 joko |
36 |
|
// + always (re-)tries to connect |
37 |
|
// |
38 |
// Revision 1.10 2003/02/13 21:58:39 joko |
// Revision 1.10 2003/02/13 21:58:39 joko |
39 |
// + caching mechanisms more configurable now |
// + caching mechanisms more configurable now |
40 |
// |
// |
41 |
// Revision 1.9 2003/02/09 17:46:26 joko |
// Revision 1.9 2003/02/09 17:46:26 joko |
42 |
// + now utilizing Data::Driver::Proxy and Data::Deep |
// + now utilizing DesignPattern::RemoteProxy and Data::Deep |
43 |
// |
// |
44 |
// Revision 1.8 2002/12/28 01:16:42 jonen |
// Revision 1.8 2002/12/28 01:16:42 jonen |
45 |
// + added clear of $this->state[autologout] at 'hadTimeout()' |
// + added clear of $this->state[autologout] at 'hadTimeout()' |
109 |
// |
// |
110 |
// ----------------------------------------------------------------------------- |
// ----------------------------------------------------------------------------- |
111 |
|
|
112 |
|
|
113 |
|
/** |
114 |
|
* This is the User class. |
115 |
|
* |
116 |
|
* @author Andreas Motl <andreas.motl@ilo.de> |
117 |
|
* @package org.netfrag.flib |
118 |
|
* @name Tracker::User |
119 |
|
* |
120 |
|
*/ |
121 |
class User { |
class User { |
122 |
|
|
123 |
var $state; |
var $state; |
155 |
$this->meta[data_ready] = 1; |
$this->meta[data_ready] = 1; |
156 |
//$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) ); |
157 |
$rpcinfo = $this->site->configuration->get("rpcinfo"); |
$rpcinfo = $this->site->configuration->get("rpcinfo"); |
158 |
$this->pObject = mkObject('Data::Driver::Proxy', $this->getUserGuid(), array( remote => 1, classname => "NetPerson", guid => 1, rpcinfo => $rpcinfo, cache => array( db => 1, session => 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 ) ); |
159 |
if ($this->getUserGuid()) { |
$cache_key = $this->getUserGuid() . "_user"; |
160 |
$this->data = $this->pObject->getAttributes(); |
$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 ) ); |
161 |
|
if ($this->getUserGuid()) { |
162 |
|
$this->data = $this->pObject->getResult(); |
163 |
} |
} |
164 |
} |
} |
165 |
|
|
166 |
function _saveData($newRawData) { |
function _saveData($newRawData) { |
167 |
|
|
168 |
|
//print "newRawData: " . Dumper($newRawData) . "<br>"; |
169 |
foreach ($newRawData as $key => $val) { |
foreach ($newRawData as $key => $val) { |
170 |
//print "$key => $val<br>"; |
//print "$key => $val<br>"; |
171 |
$this->set($key, $val); |
$this->set($key, $val); |
179 |
|
|
180 |
function _save($type = '') { |
function _save($type = '') { |
181 |
//print Dumper($this->data); |
//print Dumper($this->data); |
182 |
$this->pObject->save($this->data, $type); |
//$this->pObject->save($this->data, $type); |
183 |
|
// new of 2004-03-08: don't use generic 'saveObject'!! |
184 |
|
// for security reasons disabled at ClientBackend!!! |
185 |
|
if($type == 'commit') { |
186 |
|
$args = array( 'guid' => $this->data[guid], 'data' => $this->data ); |
187 |
|
$this->pObject->backend->send('saveUser', $args, array( utf8 => 1) ); |
188 |
|
$this->_save_local(); |
189 |
|
$this->refresh(); |
190 |
|
} |
191 |
// invalidate data only if it's not for caching purposes |
// invalidate data only if it's not for caching purposes |
192 |
if ($type != 'cache') { |
if ($type != 'cache') { |
193 |
$this->meta[data_ready] = 0; |
$this->meta[data_ready] = 0; |
194 |
} |
} |
195 |
} |
} |
196 |
|
|
197 |
|
function _save_local() { |
198 |
|
connectdb(); |
199 |
|
$username = $this->get('userData.username'); |
200 |
|
$password = $this->get('userData.password'); |
201 |
|
$sql = "UPDATE td_users SET pass='$password' WHERE uname='$username'"; |
202 |
|
$res = send_sql($sql); |
203 |
|
} |
204 |
|
|
205 |
function save() { |
function save() { |
206 |
$this->_doDataReady(); |
$this->_doDataReady(); |
209 |
|
|
210 |
function create() { |
function create() { |
211 |
$this->_save(); |
$this->_save(); |
212 |
$attr = $this->pObject->getAttributes(); |
$attr = $this->pObject->getResult(); |
213 |
//print DumpVar($attr); |
//print DumpVar($attr); |
214 |
$this->_create($attr); |
$this->_create($attr); |
215 |
} |
} |
216 |
|
|
217 |
|
function createGuest() { |
218 |
|
if($this->isLoggedOn) { return; } |
219 |
|
//$this->_save(); |
220 |
|
//$attr = $this->pObject->getResult(); |
221 |
|
//print DumpVar($attr); |
222 |
|
$data = $this->_createGuest(); |
223 |
|
return $data; |
224 |
|
} |
225 |
|
|
226 |
function _create($result) { |
function _create($result) { |
227 |
|
global $site; |
228 |
//print "saving to backend: " . dumpVar($result) . "<br>"; |
//print "saving to backend: " . dumpVar($result) . "<br>"; |
229 |
$response = $this->pObject->backend->send('createUser', array('data' => $result) ); |
$response = $this->pObject->backend->send('createUser', array('data' => $result) ); |
230 |
$objectId = $response[oid]; |
$objectId = $response[oid]; |
244 |
//$this->_init($objectId); |
//$this->_init($objectId); |
245 |
} |
} |
246 |
|
|
247 |
|
function _createGuest() { |
248 |
|
global $site; |
249 |
|
//print "saving to backend: " . dumpVar($result) . "<br>"; |
250 |
|
if(!$this->pObject) { |
251 |
|
$rpcinfo = $this->site->configuration->get("rpcinfo"); |
252 |
|
$pObject = mkObject('DesignPattern::RemoteProxy', 'guest', array( key => 1, command => 'createGuestUser', '', remote => 1, rpcinfo => $rpcinfo, cache => array( db => 1, session => 1 ), connect => 1 ) ); |
253 |
|
$response = $pObject->getResult(); |
254 |
|
} else { |
255 |
|
$response = $this->pObject->backend->send('createGuestUser'); |
256 |
|
} |
257 |
|
//print "response: " . Dumper($response) . "<br>"; |
258 |
|
$objectId = $response[oid]; |
259 |
|
if($objectId) { |
260 |
|
return $response; |
261 |
|
} |
262 |
|
else { |
263 |
|
// TODO: handle this with a generic rpc-debug/pending function |
264 |
|
$site->session->set('login_error', 'rpc_error'); |
265 |
|
$site->redirect( getlink('/pub/login/') ); |
266 |
|
} |
267 |
|
//$this->_init($objectId); |
268 |
|
} |
269 |
|
|
270 |
function get($attr) { |
function get($attr) { |
271 |
$this->_doDataReady(); |
$this->_doDataReady(); |
272 |
$deep = new Data_Deep($this->data); |
$deep = new Data_Deep($this->data); |
287 |
|
|
288 |
//===== function userlogin ========================= |
//===== function userlogin ========================= |
289 |
function login($user,$passwd) { |
function login($user,$passwd) { |
290 |
connectdb(); |
connectdb(); |
291 |
//$sql = "SELECT * FROM td_users WHERE uname='$user'"; |
//$sql = "SELECT * FROM td_users WHERE uname='$user'"; |
292 |
$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'"; |
293 |
if ($res=send_sql($sql)) { |
if ($res=send_sql($sql)) { |
294 |
$row = mysql_fetch_array($res,MYSQL_ASSOC); |
$row = mysql_fetch_array($res,MYSQL_ASSOC); |
295 |
if (!is_array($row)) { return 0; } |
if (!is_array($row)) { return 0; } |
296 |
} |
} |
297 |
if ($row[pass] == $passwd) { |
if ($row[pass] == $passwd) { |
298 |
//return $uservars_db; |
//return $uservars_db; |
299 |
// store 1st priority user-data to state |
// store 1st priority user-data to state |
300 |
$this->state[id] = $row[user_oid]; |
$this->state[id] = $row[user_oid]; |
306 |
} else { |
} else { |
307 |
return 0; |
return 0; |
308 |
} |
} |
309 |
} |
} |
310 |
|
|
311 |
|
//===== function guestlogin ========================= |
312 |
|
function loginGuest($data) { |
313 |
|
// store 1st priority user-data to state |
314 |
|
$this->state[id] = $data[oid]; |
315 |
|
$this->state[guid] = $data[guid]; |
316 |
|
$this->state[status] = $this->meta[logontoken]; |
317 |
|
$this->_saveState(); |
318 |
|
$this->site->log( get_class($this) . "->guest-login ok", PEAR_LOG_NOTICE ); |
319 |
|
return 1; |
320 |
|
} |
321 |
|
|
322 |
function exists($string) { |
function exists($string) { |
323 |
connectdb(); |
connectdb(); |
335 |
|
|
336 |
function update($vars) { |
function update($vars) { |
337 |
$this->setPostVars($vars); |
$this->setPostVars($vars); |
338 |
//print Dumper($vars); |
//print Dumper($vars); |
339 |
$data = $this->_transformInputData($vars); |
$data = $this->_transformInputData($vars); |
340 |
|
//print Dumper($data); |
341 |
$this->_saveData($data); |
$this->_saveData($data); |
342 |
} |
} |
343 |
|
|
410 |
} |
} |
411 |
|
|
412 |
function refresh() { |
function refresh() { |
413 |
if ($this->pObject) {$this->pObject->flushState();} |
if ($this->pObject) {$this->pObject->flush();} |
414 |
$this->meta[data_ready] = 0; |
$this->meta[data_ready] = 0; |
415 |
} |
} |
416 |
|
|
458 |
function hadTimeout() { |
function hadTimeout() { |
459 |
if ($this->state[autologout]) { $this->state[autologout] = ''; return 1; } |
if ($this->state[autologout]) { $this->state[autologout] = ''; return 1; } |
460 |
} |
} |
461 |
|
|
462 |
|
function getNewMessages() { |
463 |
|
$messages = array(); |
464 |
|
$userguid = $this->getUserGuid(); |
465 |
|
connectdb(); |
466 |
|
$sql = "SELECT * FROM td_message WHERE target_guid='$userguid' AND new='1'"; |
467 |
|
if ($res=send_sql($sql)) { |
468 |
|
while($row = mysql_fetch_array($res,MYSQL_ASSOC)) { |
469 |
|
if (!is_array($row)) { return 0; } |
470 |
|
array_push($messages, $row); |
471 |
|
} |
472 |
|
} |
473 |
|
return $messages; |
474 |
|
} |
475 |
|
|
476 |
|
function markNewMessage($mid) { |
477 |
|
connectdb(); |
478 |
|
$sql = "UPDATE td_message SET new='0' WHERE mid='$mid'"; |
479 |
|
if(!$res=send_sql($sql)) { |
480 |
|
return "Message not found!"; |
481 |
|
} |
482 |
|
} |
483 |
|
|
484 |
} |
} |
485 |
|
|