/[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.1 by joko, Tue Nov 12 05:42:31 2002 UTC revision 1.11 by joko, Fri Feb 14 14:22:06 2003 UTC
# Line 3  Line 3 
3  //    $Id$  //    $Id$
4  //    -----------------------------------------------------------------------------  //    -----------------------------------------------------------------------------
5  //    $Log$  //    $Log$
6    //    Revision 1.11  2003/02/14 14:22:06  joko
7    //    + always (re-)tries to connect
8    //
9    //    Revision 1.10  2003/02/13 21:58:39  joko
10    //    + caching mechanisms more configurable now
11    //
12    //    Revision 1.9  2003/02/09 17:46:26  joko
13    //    + now utilizing Data::Driver::Proxy and Data::Deep
14    //
15    //    Revision 1.8  2002/12/28 01:16:42  jonen
16    //    + added clear of $this->state[autologout] at 'hadTimeout()'
17    //
18    //    Revision 1.7  2002/12/23 11:32:28  jonen
19    //    + added inserting of uservars on '_create' to frontend db(needed to login user after create!)
20    //      + added hard link to page 'pub/register', TODO: move this out here
21    //
22    //    Revision 1.6  2002/12/18 22:46:06  jonen
23    //    + added function 'getUserGuid()'
24    //       (returns user's 'guid' read from database at function 'login()'  (now))
25    //    + function '_loadData()' loads user remote now via 'getUserGuid()'
26    //
27    //    Revision 1.5  2002/12/12 21:34:32  joko
28    //    + fix in 'function update': invalidate data only if it's not for caching purposes
29    //
30    //    Revision 1.4  2002/12/06 04:10:28  joko
31    //    + replaced 'xyzCache' through 'xyzProxy'
32    //
33    //    Revision 1.3  2002/12/04 07:42:54  jonen
34    //    + changes according to backend schema change
35    //
36    //    Revision 1.2  2002/12/03 16:47:22  joko
37    //    - function preLogout()
38    //    + function preLogout($autologout = 0)
39    //    + function hadTimeout()
40    //
41  //    Revision 1.1  2002/11/12 05:42:31  joko  //    Revision 1.1  2002/11/12 05:42:31  joko
42  //    + initial checkin  //    + initial checkin
43  //  //
# Line 79  class User { Line 114  class User {
114    
115    
116    function _loadData() {    function _loadData() {
117      $this->pObject = new ProxyObject($this->state[id]);      $this->meta[data_ready] = 1;
118      if ($this->state[id]) {      //$this->pObject = new ProxyObject($this->getUserGuid(), array( remote => 1, classname => "NetPerson", guid => 1) );
119        $rpcinfo = $this->site->configuration->get("rpcinfo");
120        $this->pObject = mkObject('Data::Driver::Proxy', $this->getUserGuid(), array( remote => 1, classname => "NetPerson", guid => 1, rpcinfo => $rpcinfo, cache => array( db => 1, session => 1 ), connect => 1 ) );
121        if ($this->getUserGuid()) {
122        $this->data = $this->pObject->getAttributes();        $this->data = $this->pObject->getAttributes();
123      }      }
     $this->meta[data_ready] = 1;  
124    }    }
125    
126    function _saveData($newRawData) {    function _saveData($newRawData) {
# Line 95  class User { Line 132  class User {
132    
133      $this->_save("cache");      $this->_save("cache");
134            
135      //$this->pObject->flushCache();     // done in "pObject->save"      //$this->pObject->flushProxy();     // done in "pObject->save"
136            
137    }    }
138        
139    function _save($type = '') {    function _save($type = '') {
140    //print Dumper($this->data);
141      $this->pObject->save($this->data, $type);      $this->pObject->save($this->data, $type);
142      $this->meta[data_ready] = 0;      // invalidate data only if it's not for caching purposes
143        if ($type != 'cache') {
144          $this->meta[data_ready] = 0;
145        }
146    }    }
147        
148    function save() {    function save() {
# Line 120  class User { Line 161  class User {
161      //print "saving to backend: " . dumpVar($result) . "<br>";      //print "saving to backend: " . dumpVar($result) . "<br>";
162      $response = $this->pObject->backend->send('createUser', array('data' => $result) );      $response = $this->pObject->backend->send('createUser', array('data' => $result) );
163      $objectId = $response[oid];      $objectId = $response[oid];
164        if($objectId) {
165            connectdb();
166            $guid = $response[guid];
167            $username = $this->get('userData.username');
168            $password = $this->get('userData.password');
169            $sql = "INSERT into td_users VALUES ( '$objectId', '$guid', '', '$username', '$password','' )";
170                $res = send_sql($sql);
171              }
172              else {
173                // TODO: handle this with a generic rpc-debug/pending function
174          $site->session->set('register_error', 'rpc_error');
175          $site->redirect( getlink('/pub/register/') );
176              }
177      //$this->_init($objectId);      //$this->_init($objectId);
178    }    }
179    
   function _getHKR($key) {  
     $attr_arr = split('\.', $key);  
     $attr_hkr = '["' . join('"]["', $attr_arr) . '"]';  
     return $attr_hkr;  
   }  
   
180    function get($attr) {    function get($attr) {
181      $this->_doDataReady();      $this->_doDataReady();
182      $hkr = $this->_getHKR($attr);      $deep = new Data_Deep($this->data);
183      $evalstr = 'return $this->data' . $hkr . ';';      return $deep->get($attr);
     $val = eval($evalstr);  
     return $val;  
184    }    }
185    function set($attr, $val) {    function set($attr, $val) {
186      $this->_doDataReady();      $this->_doDataReady();
187      $hkr = $this->_getHKR($attr);      $deep = new Data_Deep($this->data);
188      $evalstr = '$this->data' . $hkr . ' = \'' . $val . '\';';      $deep->set($attr, $val);
     eval($evalstr);  
189    }    }
190        
191    function isLoggedOn() {    function isLoggedOn() {
# Line 154  class User { Line 199  class User {
199    function login($user,$passwd) {    function login($user,$passwd) {
200          connectdb();          connectdb();
201          //$sql = "SELECT * FROM td_users WHERE uname='$user'";          //$sql = "SELECT * FROM td_users WHERE uname='$user'";
202          $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'";
203          if ($res=send_sql($sql)) {          if ($res=send_sql($sql)) {
204                  $row = mysql_fetch_array($res,MYSQL_ASSOC);                  $row = mysql_fetch_array($res,MYSQL_ASSOC);
205                  if (!is_array($row)) { return 0; }                  if (!is_array($row)) { return 0; }
# Line 163  class User { Line 208  class User {
208        //return $uservars_db;        //return $uservars_db;
209        // store 1st priority user-data to state        // store 1st priority user-data to state
210          $this->state[id] = $row[user_oid];          $this->state[id] = $row[user_oid];
211            $this->state[guid] = $row[guid];
212          $this->state[status] = $this->meta[logontoken];          $this->state[status] = $this->meta[logontoken];
213          $this->_saveState();          $this->_saveState();
214        $this->site->log( get_class($this) . "->login ok", LOG_DEBUG );        $this->site->log( get_class($this) . "->login ok", PEAR_LOG_NOTICE );
215        return 1;        return 1;
216      } else {      } else {
217        return 0;        return 0;
# Line 186  class User { Line 232  class User {
232    }    }
233        
234    
235    function update(&$uservars) {    function update($vars) {
236      $this->setPostVars($uservars);      $this->setPostVars($vars);
237      $data = $this->_transformInputData($uservars);  //print Dumper($vars);
238        $data = $this->_transformInputData($vars);
239      $this->_saveData($data);      $this->_saveData($data);
240    }    }
241    
# Line 197  class User { Line 244  class User {
244      $mapping_uservars2data = array_flip($def_mapping[data2uservars]);      $mapping_uservars2data = array_flip($def_mapping[data2uservars]);
245      foreach ($uservars as $key => $val) {      foreach ($uservars as $key => $val) {
246        $key_target = $mapping_uservars2data[$key];        $key_target = $mapping_uservars2data[$key];
247        //print "$key => $key_target: $val<br>";        if($key_target != '') {
248        $target[$key_target] = $val;          //print "$key => $key_target: $val<br>";
249            $target[$key_target] = $val;
250          }
251      }      }
252      return $target;      return $target;
253    }    }
# Line 208  class User { Line 257  class User {
257      global $site;      global $site;
258    
259      // get information about user from site      // get information about user from site
260        $userid = $this->state[id];        $userid = $this->getUserId();
261    
262        $this->site->log( get_class($this) . "->logout: userid $userid", LOG_DEBUG );        $this->site->log( get_class($this) . "->logout: userid $userid", PEAR_LOG_NOTICE );
263            
264      // get information about session from php      // get information about session from php
265        $session_id = session_id();        $session_id = session_id();
# Line 232  class User { Line 281  class User {
281    
282    }    }
283    
284    function preLogout() {    function preLogout($autologout = 0) {
285      global $site;      global $site;
286      $this->state[status] = '';      $this->state[status] = '';
287        $this->state[autologout] = $autologout;
288      $this->_saveState();      $this->_saveState();
289    }    }
290    
291    function getAccountSum() {    function getAccountSum() {
292      // store additional user-data to state      // store additional user-data to state
293        if (!$this->state[accountSum]) {        if (!$this->state[accountSum]) {
294          $this->state[accountSum] = $this->get("financeInfo.accountSum");          $this->state[accountSum] = $this->get("account.amount");
295          $this->_saveState();          $this->_saveState();
296        }        }
297        return $this->state[accountSum];        return $this->state[accountSum];
# Line 250  class User { Line 300  class User {
300    function getAccountCurrency() {    function getAccountCurrency() {
301      // store additional user-data to state      // store additional user-data to state
302        if (!$this->state[accountCurrency]) {        if (!$this->state[accountCurrency]) {
303          $this->state[accountCurrency] = $this->get("financeInfo.currency");          $this->state[accountCurrency] = $this->get("account.currency");
304          $this->_saveState();          $this->_saveState();
305        }        }
306        //print "state: " . $this->get("financeInfo.currency") . "<br>";        //print "state: " . $this->get("financeInfo.currency") . "<br>";
# Line 286  class User { Line 336  class User {
336      return $this->state[id];      return $this->state[id];
337    }    }
338    
339      function getUserGuid() {
340        return $this->state[guid];
341      }
342    
343    function getPostVars() {    function getPostVars() {
344      return $this->state[postvars];      return $this->state[postvars];
# Line 300  class User { Line 353  class User {
353      return $this->state[postvars][$var];      return $this->state[postvars][$var];
354    }    }
355        
356      function hadTimeout() {
357        if ($this->state[autologout]) { $this->state[autologout] = ''; return 1; }
358      }
359    
360  }  }
361    

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.11

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