/[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.13 by joko, Fri Apr 4 02:15:09 2003 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     * @package org.netfrag.flib
7     * @name Tracker::User
8     *
9     */
10    
11    
12  //    -----------------------------------------------------------------------------  //    -----------------------------------------------------------------------------
13  //    $Id$  //    $Id$
14  //    -----------------------------------------------------------------------------  //    -----------------------------------------------------------------------------
15  //    $Log$  //    $Log$
16    //    Revision 1.13  2003/04/04 02:15:09  joko
17    //    renamed method of helper object
18    //
19    //    Revision 1.12  2003/03/03 21:20:47  joko
20    //    mungled the namespaces
21    //
22    //    Revision 1.11  2003/02/14 14:22:06  joko
23    //    + always (re-)tries to connect
24    //
25    //    Revision 1.10  2003/02/13 21:58:39  joko
26    //    + caching mechanisms more configurable now
27    //
28    //    Revision 1.9  2003/02/09 17:46:26  joko
29    //    + now utilizing DesignPattern::RemoteProxy and Data::Deep
30    //
31    //    Revision 1.8  2002/12/28 01:16:42  jonen
32    //    + added clear of $this->state[autologout] at 'hadTimeout()'
33    //
34    //    Revision 1.7  2002/12/23 11:32:28  jonen
35    //    + added inserting of uservars on '_create' to frontend db(needed to login user after create!)
36    //      + added hard link to page 'pub/register', TODO: move this out here
37    //
38    //    Revision 1.6  2002/12/18 22:46:06  jonen
39    //    + added function 'getUserGuid()'
40    //       (returns user's 'guid' read from database at function 'login()'  (now))
41    //    + function '_loadData()' loads user remote now via 'getUserGuid()'
42    //
43    //    Revision 1.5  2002/12/12 21:34:32  joko
44    //    + fix in 'function update': invalidate data only if it's not for caching purposes
45    //
46    //    Revision 1.4  2002/12/06 04:10:28  joko
47    //    + replaced 'xyzCache' through 'xyzProxy'
48    //
49    //    Revision 1.3  2002/12/04 07:42:54  jonen
50    //    + changes according to backend schema change
51    //
52  //    Revision 1.2  2002/12/03 16:47:22  joko  //    Revision 1.2  2002/12/03 16:47:22  joko
53  //    - function preLogout()  //    - function preLogout()
54  //    + function preLogout($autologout = 0)  //    + function preLogout($autologout = 0)
# Line 50  Line 96 
96  //  //
97  //    -----------------------------------------------------------------------------  //    -----------------------------------------------------------------------------
98    
99    
100    /**
101     * This is the User class.
102     *
103     * @author Andreas Motl <andreas.motl@ilo.de>
104     * @package org.netfrag.flib
105     * @name Tracker::User
106     *
107     */
108  class User {  class User {
109        
110    var $state;    var $state;
# Line 84  class User { Line 139  class User {
139    
140    
141    function _loadData() {    function _loadData() {
     $this->pObject = new ProxyObject($this->state[id]);  
     if ($this->state[id]) {  
       $this->data = $this->pObject->getAttributes();  
     }  
142      $this->meta[data_ready] = 1;      $this->meta[data_ready] = 1;
143        //$this->pObject = new ProxyObject($this->getUserGuid(), array( remote => 1, classname => "NetPerson", guid => 1) );
144        $rpcinfo = $this->site->configuration->get("rpcinfo");
145        $this->pObject = mkObject('DesignPattern::RemoteProxy', $this->getUserGuid(), array( remote => 1, classname => "NetPerson", guid => 1, rpcinfo => $rpcinfo, cache => array( db => 1, session => 1 ), connect => 1 ) );
146        if ($this->getUserGuid()) {
147          $this->data = $this->pObject->getResult();
148        }
149    }    }
150    
151    function _saveData($newRawData) {    function _saveData($newRawData) {
# Line 100  class User { Line 157  class User {
157    
158      $this->_save("cache");      $this->_save("cache");
159            
160      //$this->pObject->flushCache();     // done in "pObject->save"      //$this->pObject->flushProxy();     // done in "pObject->save"
161            
162    }    }
163        
164    function _save($type = '') {    function _save($type = '') {
165    //print Dumper($this->data);
166      $this->pObject->save($this->data, $type);      $this->pObject->save($this->data, $type);
167      $this->meta[data_ready] = 0;      // invalidate data only if it's not for caching purposes
168        if ($type != 'cache') {
169          $this->meta[data_ready] = 0;
170        }
171    }    }
172        
173    function save() {    function save() {
# Line 125  class User { Line 186  class User {
186      //print "saving to backend: " . dumpVar($result) . "<br>";      //print "saving to backend: " . dumpVar($result) . "<br>";
187      $response = $this->pObject->backend->send('createUser', array('data' => $result) );      $response = $this->pObject->backend->send('createUser', array('data' => $result) );
188      $objectId = $response[oid];      $objectId = $response[oid];
189        if($objectId) {
190            connectdb();
191            $guid = $response[guid];
192            $username = $this->get('userData.username');
193            $password = $this->get('userData.password');
194            $sql = "INSERT into td_users VALUES ( '$objectId', '$guid', '', '$username', '$password','' )";
195                $res = send_sql($sql);
196              }
197              else {
198                // TODO: handle this with a generic rpc-debug/pending function
199          $site->session->set('register_error', 'rpc_error');
200          $site->redirect( getlink('/pub/register/') );
201              }
202      //$this->_init($objectId);      //$this->_init($objectId);
203    }    }
204    
   function _getHKR($key) {  
     $attr_arr = split('\.', $key);  
     $attr_hkr = '["' . join('"]["', $attr_arr) . '"]';  
     return $attr_hkr;  
   }  
   
205    function get($attr) {    function get($attr) {
206      $this->_doDataReady();      $this->_doDataReady();
207      $hkr = $this->_getHKR($attr);      $deep = new Data_Deep($this->data);
208      $evalstr = 'return $this->data' . $hkr . ';';      return $deep->get($attr);
     $val = eval($evalstr);  
     return $val;  
209    }    }
210    function set($attr, $val) {    function set($attr, $val) {
211      $this->_doDataReady();      $this->_doDataReady();
212      $hkr = $this->_getHKR($attr);      $deep = new Data_Deep($this->data);
213      $evalstr = '$this->data' . $hkr . ' = \'' . $val . '\';';      $deep->set($attr, $val);
     eval($evalstr);  
214    }    }
215        
216    function isLoggedOn() {    function isLoggedOn() {
# Line 159  class User { Line 224  class User {
224    function login($user,$passwd) {    function login($user,$passwd) {
225          connectdb();          connectdb();
226          //$sql = "SELECT * FROM td_users WHERE uname='$user'";          //$sql = "SELECT * FROM td_users WHERE uname='$user'";
227          $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'";
228          if ($res=send_sql($sql)) {          if ($res=send_sql($sql)) {
229                  $row = mysql_fetch_array($res,MYSQL_ASSOC);                  $row = mysql_fetch_array($res,MYSQL_ASSOC);
230                  if (!is_array($row)) { return 0; }                  if (!is_array($row)) { return 0; }
# Line 168  class User { Line 233  class User {
233        //return $uservars_db;        //return $uservars_db;
234        // store 1st priority user-data to state        // store 1st priority user-data to state
235          $this->state[id] = $row[user_oid];          $this->state[id] = $row[user_oid];
236            $this->state[guid] = $row[guid];
237          $this->state[status] = $this->meta[logontoken];          $this->state[status] = $this->meta[logontoken];
238          $this->_saveState();          $this->_saveState();
239        $this->site->log( get_class($this) . "->login ok", LOG_DEBUG );        $this->site->log( get_class($this) . "->login ok", PEAR_LOG_NOTICE );
240        return 1;        return 1;
241      } else {      } else {
242        return 0;        return 0;
# Line 191  class User { Line 257  class User {
257    }    }
258        
259    
260    function update(&$uservars) {    function update($vars) {
261      $this->setPostVars($uservars);      $this->setPostVars($vars);
262      $data = $this->_transformInputData($uservars);  //print Dumper($vars);
263        $data = $this->_transformInputData($vars);
264      $this->_saveData($data);      $this->_saveData($data);
265    }    }
266    
# Line 202  class User { Line 269  class User {
269      $mapping_uservars2data = array_flip($def_mapping[data2uservars]);      $mapping_uservars2data = array_flip($def_mapping[data2uservars]);
270      foreach ($uservars as $key => $val) {      foreach ($uservars as $key => $val) {
271        $key_target = $mapping_uservars2data[$key];        $key_target = $mapping_uservars2data[$key];
272        //print "$key => $key_target: $val<br>";        if($key_target != '') {
273        $target[$key_target] = $val;          //print "$key => $key_target: $val<br>";
274            $target[$key_target] = $val;
275          }
276      }      }
277      return $target;      return $target;
278    }    }
# Line 213  class User { Line 282  class User {
282      global $site;      global $site;
283    
284      // get information about user from site      // get information about user from site
285        $userid = $this->state[id];        $userid = $this->getUserId();
286    
287        $this->site->log( get_class($this) . "->logout: userid $userid", LOG_DEBUG );        $this->site->log( get_class($this) . "->logout: userid $userid", PEAR_LOG_NOTICE );
288            
289      // get information about session from php      // get information about session from php
290        $session_id = session_id();        $session_id = session_id();
# Line 247  class User { Line 316  class User {
316    function getAccountSum() {    function getAccountSum() {
317      // store additional user-data to state      // store additional user-data to state
318        if (!$this->state[accountSum]) {        if (!$this->state[accountSum]) {
319          $this->state[accountSum] = $this->get("financeInfo.accountSum");          $this->state[accountSum] = $this->get("account.amount");
320          $this->_saveState();          $this->_saveState();
321        }        }
322        return $this->state[accountSum];        return $this->state[accountSum];
# Line 256  class User { Line 325  class User {
325    function getAccountCurrency() {    function getAccountCurrency() {
326      // store additional user-data to state      // store additional user-data to state
327        if (!$this->state[accountCurrency]) {        if (!$this->state[accountCurrency]) {
328          $this->state[accountCurrency] = $this->get("financeInfo.currency");          $this->state[accountCurrency] = $this->get("account.currency");
329          $this->_saveState();          $this->_saveState();
330        }        }
331        //print "state: " . $this->get("financeInfo.currency") . "<br>";        //print "state: " . $this->get("financeInfo.currency") . "<br>";
# Line 292  class User { Line 361  class User {
361      return $this->state[id];      return $this->state[id];
362    }    }
363    
364      function getUserGuid() {
365        return $this->state[guid];
366      }
367    
368    function getPostVars() {    function getPostVars() {
369      return $this->state[postvars];      return $this->state[postvars];
# Line 307  class User { Line 379  class User {
379    }    }
380        
381    function hadTimeout() {    function hadTimeout() {
382      if ($this->state[autologout]) { return 1; }      if ($this->state[autologout]) { $this->state[autologout] = ''; return 1; }
383    }    }
384    
385  }  }

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

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