/[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.5 by joko, Thu Dec 12 21:34:32 2002 UTC revision 1.21 by jonen, Wed Nov 3 14:13:21 2004 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.21  2004/11/03 14:13:21  jonen
17    //    small changes at create function
18    //
19    //    Revision 1.20  2004/10/07 14:08:51  jonen
20    //    + bufix related to save new-registered user-data
21    //
22    //    Revision 1.19  2004/06/22 09:18:47  jonen
23    //    removed debug dumps
24    //
25    //    Revision 1.17  2004/06/07 16:54:53  joko
26    //    modified cache-key
27    //    added cache-control
28    //
29    //    Revision 1.16  2004/05/06 13:02:09  jonen
30    //    + added/modified functions related to User-Messages
31    //
32    //    Revision 1.15  2004/03/11 21:04:48  jonen
33    //    +changed backend-functions to only get/save User ONLY not SOME object (security!)
34    //
35    //    Revision 1.14  2003/07/02 11:02:09  joko
36    //    + fixed bug with create/_create
37    //
38    //    Revision 1.13  2003/04/04 02:15:09  joko
39    //    renamed method of helper object
40    //
41    //    Revision 1.12  2003/03/03 21:20:47  joko
42    //    mungled the namespaces
43    //
44    //    Revision 1.11  2003/02/14 14:22:06  joko
45    //    + always (re-)tries to connect
46    //
47    //    Revision 1.10  2003/02/13 21:58:39  joko
48    //    + caching mechanisms more configurable now
49    //
50    //    Revision 1.9  2003/02/09 17:46:26  joko
51    //    + now utilizing DesignPattern::RemoteProxy and Data::Deep
52    //
53    //    Revision 1.8  2002/12/28 01:16:42  jonen
54    //    + added clear of $this->state[autologout] at 'hadTimeout()'
55    //
56    //    Revision 1.7  2002/12/23 11:32:28  jonen
57    //    + added inserting of uservars on '_create' to frontend db(needed to login user after create!)
58    //      + added hard link to page 'pub/register', TODO: move this out here
59    //
60    //    Revision 1.6  2002/12/18 22:46:06  jonen
61    //    + added function 'getUserGuid()'
62    //       (returns user's 'guid' read from database at function 'login()'  (now))
63    //    + function '_loadData()' loads user remote now via 'getUserGuid()'
64    //
65  //    Revision 1.5  2002/12/12 21:34:32  joko  //    Revision 1.5  2002/12/12 21:34:32  joko
66  //    + fix in 'function update': invalidate data only if it's not for caching purposes  //    + fix in 'function update': invalidate data only if it's not for caching purposes
67  //  //
# Line 59  Line 118 
118  //  //
119  //    -----------------------------------------------------------------------------  //    -----------------------------------------------------------------------------
120    
121    
122    /**
123     * This is the User class.
124     *
125     * @author Andreas Motl <andreas.motl@ilo.de>
126     * @package org.netfrag.flib
127     * @name Tracker::User
128     *
129     */
130  class User {  class User {
131        
132    var $state;    var $state;
# Line 93  class User { Line 161  class User {
161    
162    
163    function _loadData() {    function _loadData() {
     $this->pObject = new ProxyObject($this->state[id]);  
     if ($this->state[id]) {  
       $this->data = $this->pObject->getAttributes();  
     }  
164      $this->meta[data_ready] = 1;      $this->meta[data_ready] = 1;
165        //$this->pObject = new ProxyObject($this->getUserGuid(), array( remote => 1, classname => "NetPerson", guid => 1) );
166        $rpcinfo = $this->site->configuration->get("rpcinfo");
167        //$this->pObject = mkObject('DesignPattern::RemoteProxy', $this->getUserGuid(), array( remote => 1, classname => "NetPerson", guid => 1, rpcinfo => $rpcinfo, cache => array( db => 1, session => 1 ), connect => 1 ) );
168        $cache_key = $this->getUserGuid() . "_user";
169        $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 ) );
170         if ($this->getUserGuid()) {
171          $this->data = $this->pObject->getResult();
172        }
173    }    }
174    
175    function _saveData($newRawData) {    function _saveData($newRawData) {
176    
177        //print "newRawData: " . Dumper($newRawData) . "<br>";
178      foreach ($newRawData as $key => $val) {      foreach ($newRawData as $key => $val) {
179        //print "$key => $val<br>";        //print "$key => $val<br>";
180        $this->set($key, $val);        $this->set($key, $val);
181      }      }
182    
183      $this->_save("cache");      $this->_save("cache");
184        //$this->_save("commit");
185            
186      //$this->pObject->flushProxy();     // done in "pObject->save"      //$this->pObject->flushProxy();     // done in "pObject->save"
187            
# Line 115  class User { Line 189  class User {
189        
190    function _save($type = '') {    function _save($type = '') {
191  //print Dumper($this->data);  //print Dumper($this->data);
192      $this->pObject->save($this->data, $type);      //$this->pObject->save($this->data, $type);
193        // new of 2004-03-08: don't use generic 'saveObject'!!
194        //   for security reasons disabled at ClientBackend!!!
195        if($type == 'commit') {
196          $args = array( 'guid' => $this->data[guid], 'data' => $this->data );
197          $this->pObject->backend->send('saveUser', $args, array( utf8 => 1) );
198          $this->_save_local();
199          $this->refresh();
200        }
201      // invalidate data only if it's not for caching purposes      // invalidate data only if it's not for caching purposes
202      if ($type != 'cache') {      if ($type != 'cache') {
203        $this->meta[data_ready] = 0;        $this->meta[data_ready] = 0;
204      }      }
205    }    }
206    
207      function _save_local() {
208            connectdb();
209            $username = $this->get('userData.username');
210            $password = $this->get('userData.password');
211            $sql = "UPDATE td_users SET pass='$password' WHERE uname='$username'";
212                $res = send_sql($sql);
213      }
214        
215    function save() {    function save() {
216      $this->_doDataReady();      $this->_doDataReady();
# Line 128  class User { Line 218  class User {
218    }    }
219        
220    function create() {    function create() {
221     $this->_save();      // How THIS can function??? we will fool ourselves...
222     $attr = $this->pObject->getAttributes();     //$this->_save();
223       //$attr = $this->pObject->getResult();
224       $this->_create($this->data);
225      }
226    
227      function createGuest() {
228        if($this->isLoggedOn) { return; }
229       //$this->_save();
230       //$attr = $this->pObject->getResult();
231     //print DumpVar($attr);     //print DumpVar($attr);
232     $this->_create($attr);     $data = $this->_createGuest();
233       return $data;
234    }    }
235    
236    function _create($result) {    function _create($result) {
237        global $site;
238      //print "saving to backend: " . dumpVar($result) . "<br>";      //print "saving to backend: " . dumpVar($result) . "<br>";
239      $response = $this->pObject->backend->send('createUser', array('data' => $result) );      $response = $this->pObject->backend->send('createUser', array('data' => $result) );
240      $objectId = $response[oid];      $objectId = $response[oid];
241        if($objectId) {
242            connectdb();
243            $guid = $response[guid];
244            $username = $this->get('userData.username');
245            $password = $this->get('userData.password');
246            $sql = "INSERT into td_users VALUES ( '$objectId', '$guid', '', '$username', '$password','' )";
247                $res = send_sql($sql);
248              }
249              else {
250                // TODO: handle this with a generic rpc-debug/pending function
251          $site->session->set('commit_error', array( form => getlt('page/register/notify/rpc_error') ));
252          $site->redirect( getlink('/pub/register/') );
253              }
254      //$this->_init($objectId);      //$this->_init($objectId);
255    }    }
256    
257    function _getHKR($key) {    function _createGuest() {
258      $attr_arr = split('\.', $key);      global $site;
259      $attr_hkr = '["' . join('"]["', $attr_arr) . '"]';      //print "saving to backend: " . dumpVar($result) . "<br>";
260      return $attr_hkr;      if(!$this->pObject) {
261          $cache_key = php::CreateGUID() . "_guest";
262          $rpcinfo = $this->site->configuration->get("rpcinfo");
263          $pObject = mkObject('DesignPattern::RemoteProxy', $cache_key, array( key => 1, command => 'createGuestUser', '', remote => 1, rpcinfo => $rpcinfo, cache => array( db => 1, session => 1 ), connect => 1 ) );
264          $response = $pObject->getResult();
265        } else {
266          $response = $this->pObject->backend->send('createGuestUser');
267        }
268        //print "response: " . Dumper($response) . "<br>";
269        $objectId = $response[oid];
270        if($objectId) {
271          return $response;
272              }
273              else {
274                // TODO: handle this with a generic rpc-debug/pending function
275          $site->session->set('login_error', 'rpc_error');
276          $site->redirect( getlink('/pub/login/') );
277              }
278        //$this->_init($objectId);
279    }    }
280    
281    function get($attr) {    function get($attr) {
282      $this->_doDataReady();      $this->_doDataReady();
283      $hkr = $this->_getHKR($attr);      $deep = new Data_Deep($this->data);
284      $evalstr = 'return $this->data' . $hkr . ';';      return $deep->get($attr);
     $val = eval($evalstr);  
     return $val;  
285    }    }
286    function set($attr, $val) {    function set($attr, $val) {
287      $this->_doDataReady();      $this->_doDataReady();
288      $hkr = $this->_getHKR($attr);      $deep = new Data_Deep($this->data);
289      $evalstr = '$this->data' . $hkr . ' = \'' . $val . '\';';      $deep->set($attr, $val);
     eval($evalstr);  
290    }    }
291        
292    function isLoggedOn() {    function isLoggedOn() {
# Line 170  class User { Line 298  class User {
298    
299    //===== function userlogin =========================    //===== function userlogin =========================
300    function login($user,$passwd) {    function login($user,$passwd) {
301          connectdb();            connectdb();
302          //$sql = "SELECT * FROM td_users WHERE uname='$user'";            //$sql = "SELECT * FROM td_users WHERE uname='$user'";
303          $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'";
304          if ($res=send_sql($sql)) {            if ($res=send_sql($sql)) {
305                  $row = mysql_fetch_array($res,MYSQL_ASSOC);                  $row = mysql_fetch_array($res,MYSQL_ASSOC);
306                  if (!is_array($row)) { return 0; }                  if (!is_array($row)) { return 0; }
307          }            }
308          if ($row[pass] == $passwd) {            if ($row[pass] == $passwd) {
309        //return $uservars_db;        //return $uservars_db;
310        // store 1st priority user-data to state        // store 1st priority user-data to state
311          $this->state[id] = $row[user_oid];          $this->state[id] = $row[user_oid];
312            $this->state[guid] = $row[guid];
313          $this->state[status] = $this->meta[logontoken];          $this->state[status] = $this->meta[logontoken];
314          $this->_saveState();          $this->_saveState();
315        $this->site->log( get_class($this) . "->login ok", LOG_DEBUG );        $this->site->log( get_class($this) . "->login ok", PEAR_LOG_NOTICE );
316        return 1;        return 1;
317      } else {      } else {
318        return 0;        return 0;
319      }      }
320  }    }
321    
322      //===== function guestlogin =========================
323      function loginGuest($data) {
324          // store 1st priority user-data to state
325            $this->state[id] = $data[oid];
326            $this->state[guid] = $data[guid];
327            $this->state[status] = $this->meta[logontoken];
328            $this->_saveState();
329          $this->site->log( get_class($this) . "->guest-login ok", PEAR_LOG_NOTICE );
330          return 1;
331      }
332    
333    function exists($string) {    function exists($string) {
334          connectdb();          connectdb();
# Line 206  class User { Line 346  class User {
346    
347    function update($vars) {    function update($vars) {
348      $this->setPostVars($vars);      $this->setPostVars($vars);
349  //print Dumper($vars);      //print Dumper($vars);
350      $data = $this->_transformInputData($vars);      $data = $this->_transformInputData($vars);
351        //print Dumper($data);
352      $this->_saveData($data);      $this->_saveData($data);
353    }    }
354    
# Line 216  class User { Line 357  class User {
357      $mapping_uservars2data = array_flip($def_mapping[data2uservars]);      $mapping_uservars2data = array_flip($def_mapping[data2uservars]);
358      foreach ($uservars as $key => $val) {      foreach ($uservars as $key => $val) {
359        $key_target = $mapping_uservars2data[$key];        $key_target = $mapping_uservars2data[$key];
360        //print "$key => $key_target: $val<br>";        if($key_target != '') {
361        $target[$key_target] = $val;          //print "$key => $key_target: $val<br>";
362            $target[$key_target] = $val;
363          }
364      }      }
365      return $target;      return $target;
366    }    }
# Line 227  class User { Line 370  class User {
370      global $site;      global $site;
371    
372      // get information about user from site      // get information about user from site
373        $userid = $this->state[id];        $userid = $this->getUserId();
374    
375        $this->site->log( get_class($this) . "->logout: userid $userid", LOG_DEBUG );        $this->site->log( get_class($this) . "->logout: userid $userid", PEAR_LOG_NOTICE );
376            
377      // get information about session from php      // get information about session from php
378        $session_id = session_id();        $session_id = session_id();
# Line 278  class User { Line 421  class User {
421    }    }
422        
423    function refresh() {    function refresh() {
424      if ($this->pObject) {$this->pObject->flushState();}      if ($this->pObject) {$this->pObject->flush();}
425      $this->meta[data_ready] = 0;      $this->meta[data_ready] = 0;
426    }    }
427        
# Line 306  class User { Line 449  class User {
449      return $this->state[id];      return $this->state[id];
450    }    }
451    
452      function getUserGuid() {
453        return $this->state[guid];
454      }
455    
456    function getPostVars() {    function getPostVars() {
457      return $this->state[postvars];      return $this->state[postvars];
# Line 321  class User { Line 467  class User {
467    }    }
468        
469    function hadTimeout() {    function hadTimeout() {
470      if ($this->state[autologout]) { return 1; }      if ($this->state[autologout]) { $this->state[autologout] = ''; return 1; }
471      }
472      
473      function getNewMessages() {
474        $messages = array();
475        $userguid = $this->getUserGuid();
476        connectdb();
477        $sql = "SELECT * FROM td_message WHERE target_guid='$userguid' AND new='1'";
478              if ($res=send_sql($sql)) {
479          while($row = mysql_fetch_array($res,MYSQL_ASSOC)) {
480                        if (!is_array($row)) { return 0; }
481                        array_push($messages, $row);
482          }
483            }
484            return $messages;
485      }
486      
487      function markNewMessage($mid) {
488        connectdb();
489        $sql = "UPDATE td_message SET new='0' WHERE mid='$mid'";
490              if(!$res=send_sql($sql)) {
491                return "Message not found!";
492              }
493    }    }
494    
495  }  }

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.21

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