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.22 2004/11/17 16:14:47 jonen |
17 |
|
// + minor changes related to utf8 encoding |
18 |
|
// |
19 |
|
// Revision 1.21 2004/11/03 14:13:21 jonen |
20 |
|
// small changes at create function |
21 |
|
// |
22 |
|
// Revision 1.20 2004/10/07 14:08:51 jonen |
23 |
|
// + bufix related to save new-registered user-data |
24 |
|
// |
25 |
|
// Revision 1.19 2004/06/22 09:18:47 jonen |
26 |
|
// removed debug dumps |
27 |
|
// |
28 |
|
// Revision 1.17 2004/06/07 16:54:53 joko |
29 |
|
// modified cache-key |
30 |
|
// added cache-control |
31 |
|
// |
32 |
|
// Revision 1.16 2004/05/06 13:02:09 jonen |
33 |
|
// + added/modified functions related to User-Messages |
34 |
|
// |
35 |
|
// Revision 1.15 2004/03/11 21:04:48 jonen |
36 |
|
// +changed backend-functions to only get/save User ONLY not SOME object (security!) |
37 |
|
// |
38 |
|
// Revision 1.14 2003/07/02 11:02:09 joko |
39 |
|
// + fixed bug with create/_create |
40 |
|
// |
41 |
|
// Revision 1.13 2003/04/04 02:15:09 joko |
42 |
|
// renamed method of helper object |
43 |
|
// |
44 |
|
// Revision 1.12 2003/03/03 21:20:47 joko |
45 |
|
// mungled the namespaces |
46 |
|
// |
47 |
|
// Revision 1.11 2003/02/14 14:22:06 joko |
48 |
|
// + always (re-)tries to connect |
49 |
|
// |
50 |
// Revision 1.10 2003/02/13 21:58:39 joko |
// Revision 1.10 2003/02/13 21:58:39 joko |
51 |
// + caching mechanisms more configurable now |
// + caching mechanisms more configurable now |
52 |
// |
// |
53 |
// Revision 1.9 2003/02/09 17:46:26 joko |
// Revision 1.9 2003/02/09 17:46:26 joko |
54 |
// + now utilizing Data::Driver::Proxy and Data::Deep |
// + now utilizing DesignPattern::RemoteProxy and Data::Deep |
55 |
// |
// |
56 |
// Revision 1.8 2002/12/28 01:16:42 jonen |
// Revision 1.8 2002/12/28 01:16:42 jonen |
57 |
// + added clear of $this->state[autologout] at 'hadTimeout()' |
// + added clear of $this->state[autologout] at 'hadTimeout()' |
121 |
// |
// |
122 |
// ----------------------------------------------------------------------------- |
// ----------------------------------------------------------------------------- |
123 |
|
|
124 |
|
|
125 |
|
/** |
126 |
|
* This is the User class. |
127 |
|
* |
128 |
|
* @author Andreas Motl <andreas.motl@ilo.de> |
129 |
|
* @package org.netfrag.flib |
130 |
|
* @name Tracker::User |
131 |
|
* |
132 |
|
*/ |
133 |
class User { |
class User { |
134 |
|
|
135 |
var $state; |
var $state; |
167 |
$this->meta[data_ready] = 1; |
$this->meta[data_ready] = 1; |
168 |
//$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) ); |
169 |
$rpcinfo = $this->site->configuration->get("rpcinfo"); |
$rpcinfo = $this->site->configuration->get("rpcinfo"); |
170 |
$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 ) ); |
171 |
if ($this->getUserGuid()) { |
$cache_key = $this->getUserGuid() . "_user"; |
172 |
$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 ) ); |
173 |
|
if ($this->getUserGuid()) { |
174 |
|
$this->data = $this->pObject->getResult(); |
175 |
} |
} |
176 |
} |
} |
177 |
|
|
178 |
function _saveData($newRawData) { |
function _saveData($newRawData) { |
179 |
|
|
180 |
|
//print "newRawData: " . Dumper($newRawData) . "<br>"; |
181 |
foreach ($newRawData as $key => $val) { |
foreach ($newRawData as $key => $val) { |
182 |
//print "$key => $val<br>"; |
//print "$key => $val<br>"; |
183 |
$this->set($key, $val); |
$this->set($key, $val); |
184 |
} |
} |
185 |
|
|
186 |
$this->_save("cache"); |
$this->_save("cache"); |
187 |
|
//$this->_save("commit"); |
188 |
|
|
189 |
//$this->pObject->flushProxy(); // done in "pObject->save" |
//$this->pObject->flushProxy(); // done in "pObject->save" |
190 |
|
|
192 |
|
|
193 |
function _save($type = '') { |
function _save($type = '') { |
194 |
//print Dumper($this->data); |
//print Dumper($this->data); |
195 |
$this->pObject->save($this->data, $type); |
//$this->pObject->save($this->data, $type); |
196 |
|
// new of 2004-03-08: don't use generic 'saveObject'!! |
197 |
|
// for security reasons disabled at ClientBackend!!! |
198 |
|
if($type == 'commit') { |
199 |
|
$args = array( 'guid' => $this->data[guid], 'data' => $this->data ); |
200 |
|
$this->pObject->backend->send('saveUser', $args, array( utf8 => 1) ); |
201 |
|
$this->_save_local(); |
202 |
|
$this->refresh(); |
203 |
|
} |
204 |
// invalidate data only if it's not for caching purposes |
// invalidate data only if it's not for caching purposes |
205 |
if ($type != 'cache') { |
if ($type != 'cache') { |
206 |
$this->meta[data_ready] = 0; |
$this->meta[data_ready] = 0; |
207 |
} |
} |
208 |
} |
} |
209 |
|
|
210 |
|
function _save_local() { |
211 |
|
connectdb(); |
212 |
|
$username = $this->get('userData.username'); |
213 |
|
$password = $this->get('userData.password'); |
214 |
|
$sql = "UPDATE td_users SET pass='$password' WHERE uname='$username'"; |
215 |
|
$res = send_sql($sql); |
216 |
|
} |
217 |
|
|
218 |
function save() { |
function save() { |
219 |
$this->_doDataReady(); |
$this->_doDataReady(); |
221 |
} |
} |
222 |
|
|
223 |
function create() { |
function create() { |
224 |
$this->_save(); |
// How THIS can function??? we will fool ourselves... |
225 |
$attr = $this->pObject->getAttributes(); |
//$this->_save(); |
226 |
|
//$attr = $this->pObject->getResult(); |
227 |
|
$this->_create($this->data); |
228 |
|
} |
229 |
|
|
230 |
|
function createGuest() { |
231 |
|
if($this->isLoggedOn) { return; } |
232 |
|
//$this->_save(); |
233 |
|
//$attr = $this->pObject->getResult(); |
234 |
//print DumpVar($attr); |
//print DumpVar($attr); |
235 |
$this->_create($attr); |
$data = $this->_createGuest(); |
236 |
|
return $data; |
237 |
} |
} |
238 |
|
|
239 |
function _create($result) { |
function _create($result) { |
240 |
|
global $site; |
241 |
//print "saving to backend: " . dumpVar($result) . "<br>"; |
//print "saving to backend: " . dumpVar($result) . "<br>"; |
242 |
$response = $this->pObject->backend->send('createUser', array('data' => $result) ); |
$response = $this->pObject->backend->send('createUser', array('data' => $result), array( utf8 => 1) ); |
243 |
$objectId = $response[oid]; |
$objectId = $response[oid]; |
244 |
if($objectId) { |
if($objectId) { |
245 |
connectdb(); |
connectdb(); |
251 |
} |
} |
252 |
else { |
else { |
253 |
// TODO: handle this with a generic rpc-debug/pending function |
// TODO: handle this with a generic rpc-debug/pending function |
254 |
$site->session->set('register_error', 'rpc_error'); |
$site->session->set('commit_error', array( form => getlt('page/register/notify/rpc_error') )); |
255 |
$site->redirect( getlink('/pub/register/') ); |
$site->redirect( getlink('/pub/register/') ); |
256 |
} |
} |
257 |
//$this->_init($objectId); |
//$this->_init($objectId); |
258 |
} |
} |
259 |
|
|
260 |
|
function _createGuest() { |
261 |
|
global $site; |
262 |
|
//print "saving to backend: " . dumpVar($result) . "<br>"; |
263 |
|
if(!$this->pObject) { |
264 |
|
$cache_key = php::CreateGUID() . "_guest"; |
265 |
|
$rpcinfo = $this->site->configuration->get("rpcinfo"); |
266 |
|
$pObject = mkObject('DesignPattern::RemoteProxy', $cache_key, array( key => 1, command => 'createGuestUser', '', remote => 1, rpcinfo => $rpcinfo, cache => array( db => 1, session => 1 ), connect => 1 ) ); |
267 |
|
$response = $pObject->getResult(); |
268 |
|
} else { |
269 |
|
$response = $this->pObject->backend->send('createGuestUser'); |
270 |
|
} |
271 |
|
//print "response: " . Dumper($response) . "<br>"; |
272 |
|
$objectId = $response[oid]; |
273 |
|
if($objectId) { |
274 |
|
return $response; |
275 |
|
} |
276 |
|
else { |
277 |
|
// TODO: handle this with a generic rpc-debug/pending function |
278 |
|
$site->session->set('login_error', 'rpc_error'); |
279 |
|
$site->redirect( getlink('/pub/login/') ); |
280 |
|
} |
281 |
|
//$this->_init($objectId); |
282 |
|
} |
283 |
|
|
284 |
function get($attr) { |
function get($attr) { |
285 |
$this->_doDataReady(); |
$this->_doDataReady(); |
286 |
$deep = new Data_Deep($this->data); |
$deep = new Data_Deep($this->data); |
301 |
|
|
302 |
//===== function userlogin ========================= |
//===== function userlogin ========================= |
303 |
function login($user,$passwd) { |
function login($user,$passwd) { |
304 |
connectdb(); |
connectdb(); |
305 |
//$sql = "SELECT * FROM td_users WHERE uname='$user'"; |
//$sql = "SELECT * FROM td_users WHERE uname='$user'"; |
306 |
$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'"; |
307 |
if ($res=send_sql($sql)) { |
if ($res=send_sql($sql)) { |
308 |
$row = mysql_fetch_array($res,MYSQL_ASSOC); |
$row = mysql_fetch_array($res,MYSQL_ASSOC); |
309 |
if (!is_array($row)) { return 0; } |
if (!is_array($row)) { return 0; } |
310 |
} |
} |
311 |
if ($row[pass] == $passwd) { |
if ($row[pass] == $passwd) { |
312 |
//return $uservars_db; |
//return $uservars_db; |
313 |
// store 1st priority user-data to state |
// store 1st priority user-data to state |
314 |
$this->state[id] = $row[user_oid]; |
$this->state[id] = $row[user_oid]; |
320 |
} else { |
} else { |
321 |
return 0; |
return 0; |
322 |
} |
} |
323 |
} |
} |
324 |
|
|
325 |
|
//===== function guestlogin ========================= |
326 |
|
function loginGuest($data) { |
327 |
|
// store 1st priority user-data to state |
328 |
|
$this->state[id] = $data[oid]; |
329 |
|
$this->state[guid] = $data[guid]; |
330 |
|
$this->state[status] = $this->meta[logontoken]; |
331 |
|
$this->_saveState(); |
332 |
|
$this->site->log( get_class($this) . "->guest-login ok", PEAR_LOG_NOTICE ); |
333 |
|
return 1; |
334 |
|
} |
335 |
|
|
336 |
function exists($string) { |
function exists($string) { |
337 |
connectdb(); |
connectdb(); |
349 |
|
|
350 |
function update($vars) { |
function update($vars) { |
351 |
$this->setPostVars($vars); |
$this->setPostVars($vars); |
352 |
//print Dumper($vars); |
//print Dumper($vars); |
353 |
$data = $this->_transformInputData($vars); |
$data = $this->_transformInputData($vars); |
354 |
|
//print Dumper($data); |
355 |
$this->_saveData($data); |
$this->_saveData($data); |
356 |
} |
} |
357 |
|
|
424 |
} |
} |
425 |
|
|
426 |
function refresh() { |
function refresh() { |
427 |
if ($this->pObject) {$this->pObject->flushState();} |
if ($this->pObject) {$this->pObject->flush();} |
428 |
$this->meta[data_ready] = 0; |
$this->meta[data_ready] = 0; |
429 |
} |
} |
430 |
|
|
472 |
function hadTimeout() { |
function hadTimeout() { |
473 |
if ($this->state[autologout]) { $this->state[autologout] = ''; return 1; } |
if ($this->state[autologout]) { $this->state[autologout] = ''; return 1; } |
474 |
} |
} |
475 |
|
|
476 |
|
function getNewMessages() { |
477 |
|
$messages = array(); |
478 |
|
$userguid = $this->getUserGuid(); |
479 |
|
connectdb(); |
480 |
|
$sql = "SELECT * FROM td_message WHERE target_guid='$userguid' AND new='1'"; |
481 |
|
if ($res=send_sql($sql)) { |
482 |
|
while($row = mysql_fetch_array($res,MYSQL_ASSOC)) { |
483 |
|
if (!is_array($row)) { return 0; } |
484 |
|
array_push($messages, $row); |
485 |
|
} |
486 |
|
} |
487 |
|
return $messages; |
488 |
|
} |
489 |
|
|
490 |
|
function markNewMessage($mid) { |
491 |
|
connectdb(); |
492 |
|
$sql = "UPDATE td_message SET new='0' WHERE mid='$mid'"; |
493 |
|
if(!$res=send_sql($sql)) { |
494 |
|
return "Message not found!"; |
495 |
|
} |
496 |
|
} |
497 |
|
|
498 |
} |
} |
499 |
|
|