/[cvs]/nfo/php/libs/org.netfrag.flib/Tracker/User.php
ViewVC logotype

Diff of /nfo/php/libs/org.netfrag.flib/Tracker/User.php

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.2 by joko, Tue Dec 3 16:47:22 2002 UTC revision 1.23 by jonen, Thu Aug 11 14:08:11 2005 UTC
# Line 1  Line 1 
1  <?  <?
2    /**
3     * This file contains the Tracker::User module.
4     *
5     * @author Andreas Motl <andreas.motl@ilo.de>
6     * @author Sebastian Utz <su@rtme.net>
7     * @package org.netfrag.flib
8     * @name Tracker::User
9     *
10     */
11    
12    
13  //    -----------------------------------------------------------------------------  //    -----------------------------------------------------------------------------
14  //    $Id$  //    $Id$
15  //    -----------------------------------------------------------------------------  //    -----------------------------------------------------------------------------
16  //    $Log$  //    $Log$
17    //    Revision 1.23  2005/08/11 14:08:11  jonen
18    //    + added functions relating to TerminalUser
19    //
20    //    Revision 1.22  2004/11/17 16:14:47  jonen
21    //    + minor changes related to utf8 encoding
22    //
23    //    Revision 1.21  2004/11/03 14:13:21  jonen
24    //     small changes at create function
25    //
26    //    Revision 1.20  2004/10/07 14:08:51  jonen
27    //    + bufix related to save new-registered user-data
28    //
29    //    Revision 1.19  2004/06/22 09:18:47  jonen
30    //    removed debug dumps
31    //
32    //    Revision 1.17  2004/06/07 16:54:53  joko
33    //    modified cache-key
34    //    added cache-control
35    //
36    //    Revision 1.16  2004/05/06 13:02:09  jonen
37    //    + added/modified functions related to User-Messages
38    //
39    //    Revision 1.15  2004/03/11 21:04:48  jonen
40    //    +changed backend-functions to only get/save User ONLY not SOME object (security!)
41    //
42    //    Revision 1.14  2003/07/02 11:02:09  joko
43    //    + fixed bug with create/_create
44    //
45    //    Revision 1.13  2003/04/04 02:15:09  joko
46    //    renamed method of helper object
47    //
48    //    Revision 1.12  2003/03/03 21:20:47  joko
49    //    mungled the namespaces
50    //
51    //    Revision 1.11  2003/02/14 14:22:06  joko
52    //    + always (re-)tries to connect
53    //
54    //    Revision 1.10  2003/02/13 21:58:39  joko
55    //    + caching mechanisms more configurable now
56    //
57    //    Revision 1.9  2003/02/09 17:46:26  joko
58    //    + now utilizing DesignPattern::RemoteProxy and Data::Deep
59    //
60    //    Revision 1.8  2002/12/28 01:16:42  jonen
61    //    + added clear of $this->state[autologout] at 'hadTimeout()'
62    //
63    //    Revision 1.7  2002/12/23 11:32:28  jonen
64    //    + added inserting of uservars on '_create' to frontend db(needed to login user after create!)
65    //      + added hard link to page 'pub/register', TODO: move this out here
66    //
67    //    Revision 1.6  2002/12/18 22:46:06  jonen
68    //    + added function 'getUserGuid()'
69    //       (returns user's 'guid' read from database at function 'login()'  (now))
70    //    + function '_loadData()' loads user remote now via 'getUserGuid()'
71    //
72    //    Revision 1.5  2002/12/12 21:34:32  joko
73    //    + fix in 'function update': invalidate data only if it's not for caching purposes
74    //
75    //    Revision 1.4  2002/12/06 04:10:28  joko
76    //    + replaced 'xyzCache' through 'xyzProxy'
77    //
78    //    Revision 1.3  2002/12/04 07:42:54  jonen
79    //    + changes according to backend schema change
80    //
81  //    Revision 1.2  2002/12/03 16:47:22  joko  //    Revision 1.2  2002/12/03 16:47:22  joko
82  //    - function preLogout()  //    - function preLogout()
83  //    + function preLogout($autologout = 0)  //    + function preLogout($autologout = 0)
# Line 50  Line 125 
125  //  //
126  //    -----------------------------------------------------------------------------  //    -----------------------------------------------------------------------------
127    
128    
129    /**
130     * This is the User class.
131     *
132     * @author Andreas Motl <andreas.motl@ilo.de>
133     * @package org.netfrag.flib
134     * @name Tracker::User
135     *
136     */
137  class User {  class User {
138        
139    var $state;    var $state;
# Line 84  class User { Line 168  class User {
168    
169    
170    function _loadData() {    function _loadData() {
     $this->pObject = new ProxyObject($this->state[id]);  
     if ($this->state[id]) {  
       $this->data = $this->pObject->getAttributes();  
     }  
171      $this->meta[data_ready] = 1;      $this->meta[data_ready] = 1;
172        //$this->pObject = new ProxyObject($this->getUserGuid(), array( remote => 1, classname => "NetPerson", guid => 1) );
173        $rpcinfo = $this->site->configuration->get("rpcinfo");
174        //$this->pObject = mkObject('DesignPattern::RemoteProxy', $this->getUserGuid(), array( remote => 1, classname => "NetPerson", guid => 1, rpcinfo => $rpcinfo, cache => array( db => 1, session => 1 ), connect => 1 ) );
175        $cache_key = $this->getUserGuid() . "_user";
176        $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 ) );
177         if ($this->getUserGuid()) {
178          $this->data = $this->pObject->getResult();
179        }
180    }    }
181    
182    function _saveData($newRawData) {    function _saveData($newRawData) {
183    
184        //print "newRawData: " . Dumper($newRawData) . "<br>";
185      foreach ($newRawData as $key => $val) {      foreach ($newRawData as $key => $val) {
186        //print "$key => $val<br>";        //print "$key => $val<br>";
187        $this->set($key, $val);        $this->set($key, $val);
188      }      }
189    
190      $this->_save("cache");      $this->_save("cache");
191        //$this->_save("commit");
192            
193      //$this->pObject->flushCache();     // done in "pObject->save"      //$this->pObject->flushProxy();     // done in "pObject->save"
194            
195    }    }
196        
197    function _save($type = '') {    function _save($type = '') {
198      $this->pObject->save($this->data, $type);  //print Dumper($this->data);
199      $this->meta[data_ready] = 0;      //$this->pObject->save($this->data, $type);
200        // new of 2004-03-08: don't use generic 'saveObject'!!
201        //   for security reasons disabled at ClientBackend!!!
202        if($type == 'commit') {
203          $args = array( 'guid' => $this->data[guid], 'data' => $this->data );
204          $this->pObject->backend->send('saveUser', $args, array( utf8 => 1) );
205          $this->_save_local();
206          $this->refresh();
207        }
208        // invalidate data only if it's not for caching purposes
209        if ($type != 'cache') {
210          $this->meta[data_ready] = 0;
211        }
212      }
213    
214      function _save_local() {
215            connectdb();
216            $username = $this->get('userData.username');
217            $password = $this->get('userData.password');
218            $sql = "UPDATE td_users SET pass='$password' WHERE uname='$username'";
219                $res = send_sql($sql);
220    }    }
221        
222    function save() {    function save() {
# Line 115  class User { Line 225  class User {
225    }    }
226        
227    function create() {    function create() {
228     $this->_save();      // How THIS can function??? we will fool ourselves...
229     $attr = $this->pObject->getAttributes();     //$this->_save();
230       //$attr = $this->pObject->getResult();
231       $this->_create($this->data);
232      }
233    
234      function createGuest() {
235        if($this->isLoggedOn) { return; }
236       //$this->_save();
237       //$attr = $this->pObject->getResult();
238     //print DumpVar($attr);     //print DumpVar($attr);
239     $this->_create($attr);     $data = $this->_createGuest();
240       return $data;
241      }
242    
243      function createTerminalUser() {
244        if($this->isLoggedOn) { return; }
245       //$this->_save();
246       //$attr = $this->pObject->getResult();
247       //print DumpVar($attr);
248       $data = $this->_createTerminalUser();
249       return $data;
250    }    }
251    
252    function _create($result) {    function _create($result) {
253        global $site;
254      //print "saving to backend: " . dumpVar($result) . "<br>";      //print "saving to backend: " . dumpVar($result) . "<br>";
255      $response = $this->pObject->backend->send('createUser', array('data' => $result) );      $response = $this->pObject->backend->send('createUser', array('data' => $result), array( utf8 => 1) );
256      $objectId = $response[oid];      $objectId = $response[oid];
257        if($objectId) {
258            connectdb();
259            $guid = $response[guid];
260            $username = $this->get('userData.username');
261            $password = $this->get('userData.password');
262            $sql = "INSERT into td_users VALUES ( '$objectId', '$guid', '', '$username', '$password','' )";
263                $res = send_sql($sql);
264              }
265              else {
266                // TODO: handle this with a generic rpc-debug/pending function
267          $site->session->set('commit_error', array( form => getlt('page/register/notify/rpc_error') ));
268          $site->redirect( getlink('/pub/register/') );
269              }
270      //$this->_init($objectId);      //$this->_init($objectId);
271    }    }
272    
273    function _getHKR($key) {    function _createGuest() {
274      $attr_arr = split('\.', $key);      global $site;
275      $attr_hkr = '["' . join('"]["', $attr_arr) . '"]';      //print "saving to backend: " . dumpVar($result) . "<br>";
276      return $attr_hkr;      if(!$this->pObject) {
277          $cache_key = php::CreateGUID() . "_guest";
278          $rpcinfo = $this->site->configuration->get("rpcinfo");
279          $pObject = mkObject('DesignPattern::RemoteProxy', $cache_key, array( key => 1, command => 'createGuestUser', '', remote => 1, rpcinfo => $rpcinfo, cache => array( db => 1, session => 1 ), connect => 1 ) );
280          $response = $pObject->getResult();
281        } else {
282          $response = $this->pObject->backend->send('createGuestUser');
283        }
284        //print "response: " . Dumper($response) . "<br>";
285        $objectId = $response[oid];
286        if($objectId) {
287          return $response;
288              }
289              else {
290                // TODO: handle this with a generic rpc-debug/pending function
291          $site->session->set('login_error', 'rpc_error');
292          $site->redirect( getlink('/pub/login/') );
293              }
294        //$this->_init($objectId);
295      }
296    
297      function _createTerminalUser() {
298        global $site;
299        //print "saving to backend: " . dumpVar($result) . "<br>";
300        if(!$this->pObject) {
301          $rpcinfo = $this->site->configuration->get("rpcinfo");
302          $backend = mkObject('DataSource::Proxy::XMLRPC', $rpcinfo);
303          //$pObject = mkObject('DesignPattern::RemoteProxy', 'createTerminalUser', array( key => 1, command => 'createTerminalUser', array('terminalID' => $site->session->get('validTerminal'), ), remote => 1, rpcinfo => $rpcinfo, cache => array( db => 1, session => 0 ), connect => 1 ) );
304          //$response = $pObject->getResult();
305          $response = $backend->send('createTerminalUser', array('terminalID' => $site->session->get('validTerminal')), array( utf8 => 1) );
306        } else {
307          $response = $this->pObject->backend->send('createTerminalUser', array('terminalID' => $site->session->get('validTerminal')), array( utf8 => 1) );
308        }
309        //print "response: " . Dumper($response) . "<br>";
310        $objectId = $response[oid];
311        if($objectId) {
312          return $response;
313        } elseif($response[error]) {
314          $site->session->set('site_error', $response[error]);      
315              } else {
316                // TODO: handle this with a generic rpc-debug/pending function
317          $site->session->set('login_error', 'rpc_error');
318          $site->redirect( getlink('/pub/login/') );
319              }
320        //$this->_init($objectId);
321    }    }
322    
323    
324    function get($attr) {    function get($attr) {
325      $this->_doDataReady();      $this->_doDataReady();
326      $hkr = $this->_getHKR($attr);      $deep = new Data_Deep($this->data);
327      $evalstr = 'return $this->data' . $hkr . ';';      return $deep->get($attr);
     $val = eval($evalstr);  
     return $val;  
328    }    }
329    function set($attr, $val) {    function set($attr, $val) {
330      $this->_doDataReady();      $this->_doDataReady();
331      $hkr = $this->_getHKR($attr);      $deep = new Data_Deep($this->data);
332      $evalstr = '$this->data' . $hkr . ' = \'' . $val . '\';';      $deep->set($attr, $val);
     eval($evalstr);  
333    }    }
334        
335    function isLoggedOn() {    function isLoggedOn() {
# Line 157  class User { Line 341  class User {
341    
342    //===== function userlogin =========================    //===== function userlogin =========================
343    function login($user,$passwd) {    function login($user,$passwd) {
344          connectdb();            connectdb();
345          //$sql = "SELECT * FROM td_users WHERE uname='$user'";            //$sql = "SELECT * FROM td_users WHERE uname='$user'";
346          $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'";
347          if ($res=send_sql($sql)) {            if ($res=send_sql($sql)) {
348                  $row = mysql_fetch_array($res,MYSQL_ASSOC);                  $row = mysql_fetch_array($res,MYSQL_ASSOC);
349                  if (!is_array($row)) { return 0; }                  if (!is_array($row)) { return 0; }
350          }            }
351          if ($row[pass] == $passwd) {            if ($row[pass] == $passwd) {
352        //return $uservars_db;        //return $uservars_db;
353        // store 1st priority user-data to state        // store 1st priority user-data to state
354          $this->state[id] = $row[user_oid];          $this->state[id] = $row[user_oid];
355            $this->state[guid] = $row[guid];
356          $this->state[status] = $this->meta[logontoken];          $this->state[status] = $this->meta[logontoken];
357          $this->_saveState();          $this->_saveState();
358        $this->site->log( get_class($this) . "->login ok", LOG_DEBUG );        $this->site->log( get_class($this) . "->login ok", PEAR_LOG_NOTICE );
359        return 1;        return 1;
360      } else {      } else {
361        return 0;        return 0;
362      }      }
363  }    }
364    
365      //===== function guestlogin =========================
366      function loginGuest($data) {
367          // store 1st priority user-data to state
368            $this->state[id] = $data[oid];
369            $this->state[guid] = $data[guid];
370            $this->state[status] = $this->meta[logontoken];
371            $this->_saveState();
372          $this->site->log( get_class($this) . "->guest-login ok", PEAR_LOG_NOTICE );
373          return 1;
374      }
375    
376      //===== function terminallogin =========================
377      function loginTerminalUser($data) {
378          // store 1st priority user-data to state
379            $this->state[id] = $data[oid];
380            $this->state[guid] = $data[guid];
381            $this->state[status] = $this->meta[logontoken];
382            $this->_saveState();
383          $this->site->log( get_class($this) . "->terminalUser-login ok", PEAR_LOG_NOTICE );
384          return 1;
385      }
386    
387    function exists($string) {    function exists($string) {
388          connectdb();          connectdb();
# Line 191  class User { Line 398  class User {
398    }    }
399        
400    
401    function update(&$uservars) {    function update($vars) {
402      $this->setPostVars($uservars);      $this->setPostVars($vars);
403      $data = $this->_transformInputData($uservars);      //print Dumper($vars);
404        $data = $this->_transformInputData($vars);
405        //print Dumper($data);
406      $this->_saveData($data);      $this->_saveData($data);
407    }    }
408    
# Line 202  class User { Line 411  class User {
411      $mapping_uservars2data = array_flip($def_mapping[data2uservars]);      $mapping_uservars2data = array_flip($def_mapping[data2uservars]);
412      foreach ($uservars as $key => $val) {      foreach ($uservars as $key => $val) {
413        $key_target = $mapping_uservars2data[$key];        $key_target = $mapping_uservars2data[$key];
414        //print "$key => $key_target: $val<br>";        if($key_target != '') {
415        $target[$key_target] = $val;          //print "$key => $key_target: $val<br>";
416            $target[$key_target] = $val;
417          }
418      }      }
419      return $target;      return $target;
420    }    }
# Line 213  class User { Line 424  class User {
424      global $site;      global $site;
425    
426      // get information about user from site      // get information about user from site
427        $userid = $this->state[id];        $userid = $this->getUserId();
428    
429        $this->site->log( get_class($this) . "->logout: userid $userid", LOG_DEBUG );        $this->site->log( get_class($this) . "->logout: userid $userid", PEAR_LOG_NOTICE );
430            
431      // get information about session from php      // get information about session from php
432        $session_id = session_id();        $session_id = session_id();
# Line 247  class User { Line 458  class User {
458    function getAccountSum() {    function getAccountSum() {
459      // store additional user-data to state      // store additional user-data to state
460        if (!$this->state[accountSum]) {        if (!$this->state[accountSum]) {
461          $this->state[accountSum] = $this->get("financeInfo.accountSum");          $this->state[accountSum] = $this->get("account.amount");
462          $this->_saveState();          $this->_saveState();
463        }        }
464        return $this->state[accountSum];        return $this->state[accountSum];
# Line 256  class User { Line 467  class User {
467    function getAccountCurrency() {    function getAccountCurrency() {
468      // store additional user-data to state      // store additional user-data to state
469        if (!$this->state[accountCurrency]) {        if (!$this->state[accountCurrency]) {
470          $this->state[accountCurrency] = $this->get("financeInfo.currency");          $this->state[accountCurrency] = $this->get("account.currency");
471          $this->_saveState();          $this->_saveState();
472        }        }
473        //print "state: " . $this->get("financeInfo.currency") . "<br>";        //print "state: " . $this->get("financeInfo.currency") . "<br>";
# Line 264  class User { Line 475  class User {
475    }    }
476        
477    function refresh() {    function refresh() {
478      if ($this->pObject) {$this->pObject->flushState();}      if ($this->pObject) {$this->pObject->flush();}
479      $this->meta[data_ready] = 0;      $this->meta[data_ready] = 0;
480    }    }
481        
# Line 292  class User { Line 503  class User {
503      return $this->state[id];      return $this->state[id];
504    }    }
505    
506      function getUserGuid() {
507        return $this->state[guid];
508      }
509    
510    function getPostVars() {    function getPostVars() {
511      return $this->state[postvars];      return $this->state[postvars];
# Line 307  class User { Line 521  class User {
521    }    }
522        
523    function hadTimeout() {    function hadTimeout() {
524      if ($this->state[autologout]) { return 1; }      if ($this->state[autologout]) { $this->state[autologout] = ''; return 1; }
525      }
526      
527      function getNewMessages() {
528        $messages = array();
529        $userguid = $this->getUserGuid();
530        connectdb();
531        $sql = "SELECT * FROM td_message WHERE target_guid='$userguid' AND new='1'";
532              if ($res=send_sql($sql)) {
533          while($row = mysql_fetch_array($res,MYSQL_ASSOC)) {
534                        if (!is_array($row)) { return 0; }
535                        array_push($messages, $row);
536          }
537            }
538            return $messages;
539      }
540      
541      function markNewMessage($mid) {
542        connectdb();
543        $sql = "UPDATE td_message SET new='0' WHERE mid='$mid'";
544              if(!$res=send_sql($sql)) {
545                return "Message not found!";
546              }
547    }    }
548    
549  }  }

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.23

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed