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.16 2004/05/06 13:02:09 jonen |
17 |
|
// + added/modified functions related to User-Messages |
18 |
|
// |
19 |
|
// Revision 1.15 2004/03/11 21:04:48 jonen |
20 |
|
// +changed backend-functions to only get/save User ONLY not SOME object (security!) |
21 |
|
// |
22 |
|
// Revision 1.14 2003/07/02 11:02:09 joko |
23 |
|
// + fixed bug with create/_create |
24 |
|
// |
25 |
|
// Revision 1.13 2003/04/04 02:15:09 joko |
26 |
|
// renamed method of helper object |
27 |
|
// |
28 |
|
// Revision 1.12 2003/03/03 21:20:47 joko |
29 |
|
// mungled the namespaces |
30 |
|
// |
31 |
|
// Revision 1.11 2003/02/14 14:22:06 joko |
32 |
|
// + always (re-)tries to connect |
33 |
|
// |
34 |
|
// Revision 1.10 2003/02/13 21:58:39 joko |
35 |
|
// + caching mechanisms more configurable now |
36 |
|
// |
37 |
|
// Revision 1.9 2003/02/09 17:46:26 joko |
38 |
|
// + now utilizing DesignPattern::RemoteProxy and Data::Deep |
39 |
|
// |
40 |
|
// Revision 1.8 2002/12/28 01:16:42 jonen |
41 |
|
// + added clear of $this->state[autologout] at 'hadTimeout()' |
42 |
|
// |
43 |
|
// Revision 1.7 2002/12/23 11:32:28 jonen |
44 |
|
// + added inserting of uservars on '_create' to frontend db(needed to login user after create!) |
45 |
|
// + added hard link to page 'pub/register', TODO: move this out here |
46 |
|
// |
47 |
|
// Revision 1.6 2002/12/18 22:46:06 jonen |
48 |
|
// + added function 'getUserGuid()' |
49 |
|
// (returns user's 'guid' read from database at function 'login()' (now)) |
50 |
|
// + function '_loadData()' loads user remote now via 'getUserGuid()' |
51 |
|
// |
52 |
|
// Revision 1.5 2002/12/12 21:34:32 joko |
53 |
|
// + fix in 'function update': invalidate data only if it's not for caching purposes |
54 |
|
// |
55 |
|
// Revision 1.4 2002/12/06 04:10:28 joko |
56 |
|
// + replaced 'xyzCache' through 'xyzProxy' |
57 |
|
// |
58 |
|
// Revision 1.3 2002/12/04 07:42:54 jonen |
59 |
|
// + changes according to backend schema change |
60 |
|
// |
61 |
// Revision 1.2 2002/12/03 16:47:22 joko |
// Revision 1.2 2002/12/03 16:47:22 joko |
62 |
// - function preLogout() |
// - function preLogout() |
63 |
// + function preLogout($autologout = 0) |
// + function preLogout($autologout = 0) |
105 |
// |
// |
106 |
// ----------------------------------------------------------------------------- |
// ----------------------------------------------------------------------------- |
107 |
|
|
108 |
|
|
109 |
|
/** |
110 |
|
* This is the User class. |
111 |
|
* |
112 |
|
* @author Andreas Motl <andreas.motl@ilo.de> |
113 |
|
* @package org.netfrag.flib |
114 |
|
* @name Tracker::User |
115 |
|
* |
116 |
|
*/ |
117 |
class User { |
class User { |
118 |
|
|
119 |
var $state; |
var $state; |
148 |
|
|
149 |
|
|
150 |
function _loadData() { |
function _loadData() { |
|
$this->pObject = new ProxyObject($this->state[id]); |
|
|
if ($this->state[id]) { |
|
|
$this->data = $this->pObject->getAttributes(); |
|
|
} |
|
151 |
$this->meta[data_ready] = 1; |
$this->meta[data_ready] = 1; |
152 |
|
//$this->pObject = new ProxyObject($this->getUserGuid(), array( remote => 1, classname => "NetPerson", guid => 1) ); |
153 |
|
$rpcinfo = $this->site->configuration->get("rpcinfo"); |
154 |
|
//$this->pObject = mkObject('DesignPattern::RemoteProxy', $this->getUserGuid(), array( remote => 1, classname => "NetPerson", guid => 1, rpcinfo => $rpcinfo, cache => array( db => 1, session => 1 ), connect => 1 ) ); |
155 |
|
$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 ) ); |
156 |
|
if ($this->getUserGuid()) { |
157 |
|
$this->data = $this->pObject->getResult(); |
158 |
|
} |
159 |
} |
} |
160 |
|
|
161 |
function _saveData($newRawData) { |
function _saveData($newRawData) { |
162 |
|
|
163 |
|
//print "newRawData: " . Dumper($newRawData) . "<br>"; |
164 |
foreach ($newRawData as $key => $val) { |
foreach ($newRawData as $key => $val) { |
165 |
//print "$key => $val<br>"; |
//print "$key => $val<br>"; |
166 |
$this->set($key, $val); |
$this->set($key, $val); |
168 |
|
|
169 |
$this->_save("cache"); |
$this->_save("cache"); |
170 |
|
|
171 |
//$this->pObject->flushCache(); // done in "pObject->save" |
//$this->pObject->flushProxy(); // done in "pObject->save" |
172 |
|
|
173 |
} |
} |
174 |
|
|
175 |
function _save($type = '') { |
function _save($type = '') { |
176 |
$this->pObject->save($this->data, $type); |
//print Dumper($this->data); |
177 |
$this->meta[data_ready] = 0; |
//$this->pObject->save($this->data, $type); |
178 |
|
// new of 2004-03-08: don't use generic 'saveObject'!! |
179 |
|
// for security reasons disabled at ClientBackend!!! |
180 |
|
if($type == 'commit') { |
181 |
|
$args = array( 'guid' => $this->data[guid], 'data' => $this->data ); |
182 |
|
$this->pObject->backend->send('saveUser', $args, array( utf8 => 1) ); |
183 |
|
$this->_save_local(); |
184 |
|
} |
185 |
|
// invalidate data only if it's not for caching purposes |
186 |
|
if ($type != 'cache') { |
187 |
|
$this->meta[data_ready] = 0; |
188 |
|
} |
189 |
|
} |
190 |
|
|
191 |
|
function _save_local() { |
192 |
|
connectdb(); |
193 |
|
$username = $this->get('userData.username'); |
194 |
|
$password = $this->get('userData.password'); |
195 |
|
$sql = "UPDATE td_users SET pass='$password' WHERE uname='$username'"; |
196 |
|
$res = send_sql($sql); |
197 |
} |
} |
198 |
|
|
199 |
function save() { |
function save() { |
203 |
|
|
204 |
function create() { |
function create() { |
205 |
$this->_save(); |
$this->_save(); |
206 |
$attr = $this->pObject->getAttributes(); |
$attr = $this->pObject->getResult(); |
207 |
//print DumpVar($attr); |
//print DumpVar($attr); |
208 |
$this->_create($attr); |
$this->_create($attr); |
209 |
} |
} |
210 |
|
|
211 |
|
function createGuest() { |
212 |
|
if($this->isLoggedOn) { return; } |
213 |
|
//$this->_save(); |
214 |
|
//$attr = $this->pObject->getResult(); |
215 |
|
//print DumpVar($attr); |
216 |
|
$data = $this->_createGuest(); |
217 |
|
return $data; |
218 |
|
} |
219 |
|
|
220 |
function _create($result) { |
function _create($result) { |
221 |
|
global $site; |
222 |
//print "saving to backend: " . dumpVar($result) . "<br>"; |
//print "saving to backend: " . dumpVar($result) . "<br>"; |
223 |
$response = $this->pObject->backend->send('createUser', array('data' => $result) ); |
$response = $this->pObject->backend->send('createUser', array('data' => $result) ); |
224 |
$objectId = $response[oid]; |
$objectId = $response[oid]; |
225 |
|
if($objectId) { |
226 |
|
connectdb(); |
227 |
|
$guid = $response[guid]; |
228 |
|
$username = $this->get('userData.username'); |
229 |
|
$password = $this->get('userData.password'); |
230 |
|
$sql = "INSERT into td_users VALUES ( '$objectId', '$guid', '', '$username', '$password','' )"; |
231 |
|
$res = send_sql($sql); |
232 |
|
} |
233 |
|
else { |
234 |
|
// TODO: handle this with a generic rpc-debug/pending function |
235 |
|
$site->session->set('register_error', 'rpc_error'); |
236 |
|
$site->redirect( getlink('/pub/register/') ); |
237 |
|
} |
238 |
//$this->_init($objectId); |
//$this->_init($objectId); |
239 |
} |
} |
240 |
|
|
241 |
function _getHKR($key) { |
function _createGuest() { |
242 |
$attr_arr = split('\.', $key); |
global $site; |
243 |
$attr_hkr = '["' . join('"]["', $attr_arr) . '"]'; |
//print "saving to backend: " . dumpVar($result) . "<br>"; |
244 |
return $attr_hkr; |
if(!$this->pObject) { |
245 |
|
$rpcinfo = $this->site->configuration->get("rpcinfo"); |
246 |
|
$pObject = mkObject('DesignPattern::RemoteProxy', 'guest', array( key => 1, command => 'createGuestUser', '', remote => 1, rpcinfo => $rpcinfo, cache => array( db => 1, session => 1 ), connect => 1 ) ); |
247 |
|
$response = $pObject->getResult(); |
248 |
|
} else { |
249 |
|
$response = $this->pObject->backend->send('createGuestUser'); |
250 |
|
} |
251 |
|
//print "response: " . Dumper($response) . "<br>"; |
252 |
|
$objectId = $response[oid]; |
253 |
|
if($objectId) { |
254 |
|
return $response; |
255 |
|
} |
256 |
|
else { |
257 |
|
// TODO: handle this with a generic rpc-debug/pending function |
258 |
|
$site->session->set('login_error', 'rpc_error'); |
259 |
|
$site->redirect( getlink('/pub/login/') ); |
260 |
|
} |
261 |
|
//$this->_init($objectId); |
262 |
} |
} |
263 |
|
|
264 |
function get($attr) { |
function get($attr) { |
265 |
$this->_doDataReady(); |
$this->_doDataReady(); |
266 |
$hkr = $this->_getHKR($attr); |
$deep = new Data_Deep($this->data); |
267 |
$evalstr = 'return $this->data' . $hkr . ';'; |
return $deep->get($attr); |
|
$val = eval($evalstr); |
|
|
return $val; |
|
268 |
} |
} |
269 |
function set($attr, $val) { |
function set($attr, $val) { |
270 |
$this->_doDataReady(); |
$this->_doDataReady(); |
271 |
$hkr = $this->_getHKR($attr); |
$deep = new Data_Deep($this->data); |
272 |
$evalstr = '$this->data' . $hkr . ' = \'' . $val . '\';'; |
$deep->set($attr, $val); |
|
eval($evalstr); |
|
273 |
} |
} |
274 |
|
|
275 |
function isLoggedOn() { |
function isLoggedOn() { |
281 |
|
|
282 |
//===== function userlogin ========================= |
//===== function userlogin ========================= |
283 |
function login($user,$passwd) { |
function login($user,$passwd) { |
284 |
connectdb(); |
connectdb(); |
285 |
//$sql = "SELECT * FROM td_users WHERE uname='$user'"; |
//$sql = "SELECT * FROM td_users WHERE uname='$user'"; |
286 |
$sql = "SELECT user_oid, uname, pass FROM td_users WHERE uname='$user'"; |
$sql = "SELECT user_oid, guid, uname, pass FROM td_users WHERE uname='$user'"; |
287 |
if ($res=send_sql($sql)) { |
if ($res=send_sql($sql)) { |
288 |
$row = mysql_fetch_array($res,MYSQL_ASSOC); |
$row = mysql_fetch_array($res,MYSQL_ASSOC); |
289 |
if (!is_array($row)) { return 0; } |
if (!is_array($row)) { return 0; } |
290 |
} |
} |
291 |
if ($row[pass] == $passwd) { |
if ($row[pass] == $passwd) { |
292 |
//return $uservars_db; |
//return $uservars_db; |
293 |
// store 1st priority user-data to state |
// store 1st priority user-data to state |
294 |
$this->state[id] = $row[user_oid]; |
$this->state[id] = $row[user_oid]; |
295 |
|
$this->state[guid] = $row[guid]; |
296 |
$this->state[status] = $this->meta[logontoken]; |
$this->state[status] = $this->meta[logontoken]; |
297 |
$this->_saveState(); |
$this->_saveState(); |
298 |
$this->site->log( get_class($this) . "->login ok", LOG_DEBUG ); |
$this->site->log( get_class($this) . "->login ok", PEAR_LOG_NOTICE ); |
299 |
return 1; |
return 1; |
300 |
} else { |
} else { |
301 |
return 0; |
return 0; |
302 |
} |
} |
303 |
} |
} |
304 |
|
|
305 |
|
//===== function guestlogin ========================= |
306 |
|
function loginGuest($data) { |
307 |
|
// store 1st priority user-data to state |
308 |
|
$this->state[id] = $data[oid]; |
309 |
|
$this->state[guid] = $data[guid]; |
310 |
|
$this->state[status] = $this->meta[logontoken]; |
311 |
|
$this->_saveState(); |
312 |
|
$this->site->log( get_class($this) . "->guest-login ok", PEAR_LOG_NOTICE ); |
313 |
|
return 1; |
314 |
|
} |
315 |
|
|
316 |
function exists($string) { |
function exists($string) { |
317 |
connectdb(); |
connectdb(); |
327 |
} |
} |
328 |
|
|
329 |
|
|
330 |
function update(&$uservars) { |
function update($vars) { |
331 |
$this->setPostVars($uservars); |
$this->setPostVars($vars); |
332 |
$data = $this->_transformInputData($uservars); |
//print Dumper($vars); |
333 |
|
$data = $this->_transformInputData($vars); |
334 |
|
//print Dumper($data); |
335 |
$this->_saveData($data); |
$this->_saveData($data); |
336 |
} |
} |
337 |
|
|
340 |
$mapping_uservars2data = array_flip($def_mapping[data2uservars]); |
$mapping_uservars2data = array_flip($def_mapping[data2uservars]); |
341 |
foreach ($uservars as $key => $val) { |
foreach ($uservars as $key => $val) { |
342 |
$key_target = $mapping_uservars2data[$key]; |
$key_target = $mapping_uservars2data[$key]; |
343 |
//print "$key => $key_target: $val<br>"; |
if($key_target != '') { |
344 |
$target[$key_target] = $val; |
//print "$key => $key_target: $val<br>"; |
345 |
|
$target[$key_target] = $val; |
346 |
|
} |
347 |
} |
} |
348 |
return $target; |
return $target; |
349 |
} |
} |
353 |
global $site; |
global $site; |
354 |
|
|
355 |
// get information about user from site |
// get information about user from site |
356 |
$userid = $this->state[id]; |
$userid = $this->getUserId(); |
357 |
|
|
358 |
$this->site->log( get_class($this) . "->logout: userid $userid", LOG_DEBUG ); |
$this->site->log( get_class($this) . "->logout: userid $userid", PEAR_LOG_NOTICE ); |
359 |
|
|
360 |
// get information about session from php |
// get information about session from php |
361 |
$session_id = session_id(); |
$session_id = session_id(); |
387 |
function getAccountSum() { |
function getAccountSum() { |
388 |
// store additional user-data to state |
// store additional user-data to state |
389 |
if (!$this->state[accountSum]) { |
if (!$this->state[accountSum]) { |
390 |
$this->state[accountSum] = $this->get("financeInfo.accountSum"); |
$this->state[accountSum] = $this->get("account.amount"); |
391 |
$this->_saveState(); |
$this->_saveState(); |
392 |
} |
} |
393 |
return $this->state[accountSum]; |
return $this->state[accountSum]; |
396 |
function getAccountCurrency() { |
function getAccountCurrency() { |
397 |
// store additional user-data to state |
// store additional user-data to state |
398 |
if (!$this->state[accountCurrency]) { |
if (!$this->state[accountCurrency]) { |
399 |
$this->state[accountCurrency] = $this->get("financeInfo.currency"); |
$this->state[accountCurrency] = $this->get("account.currency"); |
400 |
$this->_saveState(); |
$this->_saveState(); |
401 |
} |
} |
402 |
//print "state: " . $this->get("financeInfo.currency") . "<br>"; |
//print "state: " . $this->get("financeInfo.currency") . "<br>"; |
432 |
return $this->state[id]; |
return $this->state[id]; |
433 |
} |
} |
434 |
|
|
435 |
|
function getUserGuid() { |
436 |
|
return $this->state[guid]; |
437 |
|
} |
438 |
|
|
439 |
function getPostVars() { |
function getPostVars() { |
440 |
return $this->state[postvars]; |
return $this->state[postvars]; |
450 |
} |
} |
451 |
|
|
452 |
function hadTimeout() { |
function hadTimeout() { |
453 |
if ($this->state[autologout]) { return 1; } |
if ($this->state[autologout]) { $this->state[autologout] = ''; return 1; } |
454 |
|
} |
455 |
|
|
456 |
|
function getNewMessages() { |
457 |
|
$messages = array(); |
458 |
|
$userguid = $this->getUserGuid(); |
459 |
|
connectdb(); |
460 |
|
$sql = "SELECT * FROM td_message WHERE target_guid='$userguid' AND new='1'"; |
461 |
|
if ($res=send_sql($sql)) { |
462 |
|
while($row = mysql_fetch_array($res,MYSQL_ASSOC)) { |
463 |
|
if (!is_array($row)) { return 0; } |
464 |
|
array_push($messages, $row); |
465 |
|
} |
466 |
|
} |
467 |
|
return $messages; |
468 |
|
} |
469 |
|
|
470 |
|
function markNewMessage($mid) { |
471 |
|
connectdb(); |
472 |
|
$sql = "UPDATE td_message SET new='0' WHERE mid='$mid'"; |
473 |
|
if(!$res=send_sql($sql)) { |
474 |
|
return "Message not found!"; |
475 |
|
} |
476 |
} |
} |
477 |
|
|
478 |
} |
} |