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 |
// Revision 1.10 2003/02/13 21:58:39 joko |
35 |
// + caching mechanisms more configurable now |
// + caching mechanisms more configurable now |
36 |
// |
// |
37 |
// Revision 1.9 2003/02/09 17:46:26 joko |
// Revision 1.9 2003/02/09 17:46:26 joko |
38 |
// + now utilizing Data::Driver::Proxy and Data::Deep |
// + now utilizing DesignPattern::RemoteProxy and Data::Deep |
39 |
// |
// |
40 |
// Revision 1.8 2002/12/28 01:16:42 jonen |
// Revision 1.8 2002/12/28 01:16:42 jonen |
41 |
// + added clear of $this->state[autologout] at 'hadTimeout()' |
// + added clear of $this->state[autologout] at 'hadTimeout()' |
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; |
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) ); |
//$this->pObject = new ProxyObject($this->getUserGuid(), array( remote => 1, classname => "NetPerson", guid => 1) ); |
153 |
$rpcinfo = $this->site->configuration->get("rpcinfo"); |
$rpcinfo = $this->site->configuration->get("rpcinfo"); |
154 |
$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 ) ); |
155 |
if ($this->getUserGuid()) { |
$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 |
$this->data = $this->pObject->getAttributes(); |
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); |
174 |
|
|
175 |
function _save($type = '') { |
function _save($type = '') { |
176 |
//print Dumper($this->data); |
//print Dumper($this->data); |
177 |
$this->pObject->save($this->data, $type); |
//$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 |
// invalidate data only if it's not for caching purposes |
186 |
if ($type != 'cache') { |
if ($type != 'cache') { |
187 |
$this->meta[data_ready] = 0; |
$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() { |
200 |
$this->_doDataReady(); |
$this->_doDataReady(); |
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]; |
238 |
//$this->_init($objectId); |
//$this->_init($objectId); |
239 |
} |
} |
240 |
|
|
241 |
|
function _createGuest() { |
242 |
|
global $site; |
243 |
|
//print "saving to backend: " . dumpVar($result) . "<br>"; |
244 |
|
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 |
$deep = new Data_Deep($this->data); |
$deep = new Data_Deep($this->data); |
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, guid, 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]; |
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(); |
329 |
|
|
330 |
function update($vars) { |
function update($vars) { |
331 |
$this->setPostVars($vars); |
$this->setPostVars($vars); |
332 |
//print Dumper($vars); |
//print Dumper($vars); |
333 |
$data = $this->_transformInputData($vars); |
$data = $this->_transformInputData($vars); |
334 |
|
//print Dumper($data); |
335 |
$this->_saveData($data); |
$this->_saveData($data); |
336 |
} |
} |
337 |
|
|
452 |
function hadTimeout() { |
function hadTimeout() { |
453 |
if ($this->state[autologout]) { $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 |
} |
} |
479 |
|
|