/[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.11 by joko, Fri Feb 14 14:22:06 2003 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  //    Revision 1.11  2003/02/14 14:22:06  joko
45  //    + always (re-)tries to connect  //    + always (re-)tries to connect
46  //  //
# Line 10  Line 48 
48  //    + caching mechanisms more configurable now  //    + caching mechanisms more configurable now
49  //  //
50  //    Revision 1.9  2003/02/09 17:46:26  joko  //    Revision 1.9  2003/02/09 17:46:26  joko
51  //    + now utilizing Data::Driver::Proxy and Data::Deep  //    + now utilizing DesignPattern::RemoteProxy and Data::Deep
52  //  //
53  //    Revision 1.8  2002/12/28 01:16:42  jonen  //    Revision 1.8  2002/12/28 01:16:42  jonen
54  //    + added clear of $this->state[autologout] at 'hadTimeout()'  //    + added clear of $this->state[autologout] at 'hadTimeout()'
# Line 80  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 117  class User { Line 164  class User {
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) );      //$this->pObject = new ProxyObject($this->getUserGuid(), array( remote => 1, classname => "NetPerson", guid => 1) );
166      $rpcinfo = $this->site->configuration->get("rpcinfo");      $rpcinfo = $this->site->configuration->get("rpcinfo");
167      $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 ) );      //$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      if ($this->getUserGuid()) {      $cache_key = $this->getUserGuid() . "_user";
169        $this->data = $this->pObject->getAttributes();      $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 138  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 151  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];
# Line 171  class User { Line 248  class User {
248            }            }
249            else {            else {
250              // TODO: handle this with a generic rpc-debug/pending function              // TODO: handle this with a generic rpc-debug/pending function
251        $site->session->set('register_error', 'rpc_error');        $site->session->set('commit_error', array( form => getlt('page/register/notify/rpc_error') ));
252        $site->redirect( getlink('/pub/register/') );        $site->redirect( getlink('/pub/register/') );
253            }            }
254      //$this->_init($objectId);      //$this->_init($objectId);
255    }    }
256    
257      function _createGuest() {
258        global $site;
259        //print "saving to backend: " . dumpVar($result) . "<br>";
260        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      $deep = new Data_Deep($this->data);      $deep = new Data_Deep($this->data);
# Line 197  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, guid, 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];
# Line 216  class User { Line 317  class User {
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 234  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 308  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 356  class User { Line 469  class User {
469    function hadTimeout() {    function hadTimeout() {
470      if ($this->state[autologout]) { $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  }  }
496    

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

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