/[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.10 by joko, Thu Feb 13 21:58:39 2003 UTC revision 1.20 by jonen, Thu Oct 7 14:08:51 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.20  2004/10/07 14:08:51  jonen
17    //    + bufix related to save new-registered user-data
18    //
19    //    Revision 1.19  2004/06/22 09:18:47  jonen
20    //    removed debug dumps
21    //
22    //    Revision 1.17  2004/06/07 16:54:53  joko
23    //    modified cache-key
24    //    added cache-control
25    //
26    //    Revision 1.16  2004/05/06 13:02:09  jonen
27    //    + added/modified functions related to User-Messages
28    //
29    //    Revision 1.15  2004/03/11 21:04:48  jonen
30    //    +changed backend-functions to only get/save User ONLY not SOME object (security!)
31    //
32    //    Revision 1.14  2003/07/02 11:02:09  joko
33    //    + fixed bug with create/_create
34    //
35    //    Revision 1.13  2003/04/04 02:15:09  joko
36    //    renamed method of helper object
37    //
38    //    Revision 1.12  2003/03/03 21:20:47  joko
39    //    mungled the namespaces
40    //
41    //    Revision 1.11  2003/02/14 14:22:06  joko
42    //    + always (re-)tries to connect
43    //
44  //    Revision 1.10  2003/02/13 21:58:39  joko  //    Revision 1.10  2003/02/13 21:58:39  joko
45  //    + caching mechanisms more configurable now  //    + caching mechanisms more configurable now
46  //  //
47  //    Revision 1.9  2003/02/09 17:46:26  joko  //    Revision 1.9  2003/02/09 17:46:26  joko
48  //    + now utilizing Data::Driver::Proxy and Data::Deep  //    + now utilizing DesignPattern::RemoteProxy and Data::Deep
49  //  //
50  //    Revision 1.8  2002/12/28 01:16:42  jonen  //    Revision 1.8  2002/12/28 01:16:42  jonen
51  //    + added clear of $this->state[autologout] at 'hadTimeout()'  //    + added clear of $this->state[autologout] at 'hadTimeout()'
# Line 77  Line 115 
115  //  //
116  //    -----------------------------------------------------------------------------  //    -----------------------------------------------------------------------------
117    
118    
119    /**
120     * This is the User class.
121     *
122     * @author Andreas Motl <andreas.motl@ilo.de>
123     * @package org.netfrag.flib
124     * @name Tracker::User
125     *
126     */
127  class User {  class User {
128        
129    var $state;    var $state;
# Line 114  class User { Line 161  class User {
161      $this->meta[data_ready] = 1;      $this->meta[data_ready] = 1;
162      //$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) );
163      $rpcinfo = $this->site->configuration->get("rpcinfo");      $rpcinfo = $this->site->configuration->get("rpcinfo");
164      $this->pObject = mkObject('Data::Driver::Proxy', $this->getUserGuid(), array( remote => 1, classname => "NetPerson", guid => 1, rpcinfo => $rpcinfo, cache => array( db => 1, session => 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 ) );
165      if ($this->getUserGuid()) {      $cache_key = $this->getUserGuid() . "_user";
166        $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 ) );
167         if ($this->getUserGuid()) {
168          $this->data = $this->pObject->getResult();
169      }      }
170    }    }
171    
172    function _saveData($newRawData) {    function _saveData($newRawData) {
173    
174        //print "newRawData: " . Dumper($newRawData) . "<br>";
175      foreach ($newRawData as $key => $val) {      foreach ($newRawData as $key => $val) {
176        //print "$key => $val<br>";        //print "$key => $val<br>";
177        $this->set($key, $val);        $this->set($key, $val);
178      }      }
179    
180      $this->_save("cache");      $this->_save("cache");
181        //$this->_save("commit");
182            
183      //$this->pObject->flushProxy();     // done in "pObject->save"      //$this->pObject->flushProxy();     // done in "pObject->save"
184            
# Line 135  class User { Line 186  class User {
186        
187    function _save($type = '') {    function _save($type = '') {
188  //print Dumper($this->data);  //print Dumper($this->data);
189      $this->pObject->save($this->data, $type);      //$this->pObject->save($this->data, $type);
190        // new of 2004-03-08: don't use generic 'saveObject'!!
191        //   for security reasons disabled at ClientBackend!!!
192        if($type == 'commit') {
193          $args = array( 'guid' => $this->data[guid], 'data' => $this->data );
194          $this->pObject->backend->send('saveUser', $args, array( utf8 => 1) );
195          $this->_save_local();
196          $this->refresh();
197        }
198      // invalidate data only if it's not for caching purposes      // invalidate data only if it's not for caching purposes
199      if ($type != 'cache') {      if ($type != 'cache') {
200        $this->meta[data_ready] = 0;        $this->meta[data_ready] = 0;
201      }      }
202    }    }
203    
204      function _save_local() {
205            connectdb();
206            $username = $this->get('userData.username');
207            $password = $this->get('userData.password');
208            $sql = "UPDATE td_users SET pass='$password' WHERE uname='$username'";
209                $res = send_sql($sql);
210      }
211        
212    function save() {    function save() {
213      $this->_doDataReady();      $this->_doDataReady();
# Line 148  class User { Line 215  class User {
215    }    }
216        
217    function create() {    function create() {
218     $this->_save();      // How THIS can function??? we will fool ourselves...
219     $attr = $this->pObject->getAttributes();     //$this->_save();
220       //$attr = $this->pObject->getResult();
221       $this->_create($this->data);
222      }
223    
224      function createGuest() {
225        if($this->isLoggedOn) { return; }
226       //$this->_save();
227       //$attr = $this->pObject->getResult();
228     //print DumpVar($attr);     //print DumpVar($attr);
229     $this->_create($attr);     $data = $this->_createGuest();
230       return $data;
231    }    }
232    
233    function _create($result) {    function _create($result) {
234        global $site;
235      //print "saving to backend: " . dumpVar($result) . "<br>";      //print "saving to backend: " . dumpVar($result) . "<br>";
236      $response = $this->pObject->backend->send('createUser', array('data' => $result) );      $response = $this->pObject->backend->send('createUser', array('data' => $result) );
237      $objectId = $response[oid];      $objectId = $response[oid];
# Line 174  class User { Line 251  class User {
251      //$this->_init($objectId);      //$this->_init($objectId);
252    }    }
253    
254      function _createGuest() {
255        global $site;
256        //print "saving to backend: " . dumpVar($result) . "<br>";
257        if(!$this->pObject) {
258          $cache_key = php::CreateGUID() . "_guest";
259          $rpcinfo = $this->site->configuration->get("rpcinfo");
260          $pObject = mkObject('DesignPattern::RemoteProxy', $cache_key, array( key => 1, command => 'createGuestUser', '', remote => 1, rpcinfo => $rpcinfo, cache => array( db => 1, session => 1 ), connect => 1 ) );
261          $response = $pObject->getResult();
262        } else {
263          $response = $this->pObject->backend->send('createGuestUser');
264        }
265        //print "response: " . Dumper($response) . "<br>";
266        $objectId = $response[oid];
267        if($objectId) {
268          return $response;
269              }
270              else {
271                // TODO: handle this with a generic rpc-debug/pending function
272          $site->session->set('login_error', 'rpc_error');
273          $site->redirect( getlink('/pub/login/') );
274              }
275        //$this->_init($objectId);
276      }
277    
278    function get($attr) {    function get($attr) {
279      $this->_doDataReady();      $this->_doDataReady();
280      $deep = new Data_Deep($this->data);      $deep = new Data_Deep($this->data);
# Line 194  class User { Line 295  class User {
295    
296    //===== function userlogin =========================    //===== function userlogin =========================
297    function login($user,$passwd) {    function login($user,$passwd) {
298          connectdb();            connectdb();
299          //$sql = "SELECT * FROM td_users WHERE uname='$user'";            //$sql = "SELECT * FROM td_users WHERE uname='$user'";
300          $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'";
301          if ($res=send_sql($sql)) {            if ($res=send_sql($sql)) {
302                  $row = mysql_fetch_array($res,MYSQL_ASSOC);                  $row = mysql_fetch_array($res,MYSQL_ASSOC);
303                  if (!is_array($row)) { return 0; }                  if (!is_array($row)) { return 0; }
304          }            }
305          if ($row[pass] == $passwd) {            if ($row[pass] == $passwd) {
306        //return $uservars_db;        //return $uservars_db;
307        // store 1st priority user-data to state        // store 1st priority user-data to state
308          $this->state[id] = $row[user_oid];          $this->state[id] = $row[user_oid];
# Line 213  class User { Line 314  class User {
314      } else {      } else {
315        return 0;        return 0;
316      }      }
317  }    }
318    
319      //===== function guestlogin =========================
320      function loginGuest($data) {
321          // store 1st priority user-data to state
322            $this->state[id] = $data[oid];
323            $this->state[guid] = $data[guid];
324            $this->state[status] = $this->meta[logontoken];
325            $this->_saveState();
326          $this->site->log( get_class($this) . "->guest-login ok", PEAR_LOG_NOTICE );
327          return 1;
328      }
329    
330    function exists($string) {    function exists($string) {
331          connectdb();          connectdb();
# Line 231  class User { Line 343  class User {
343    
344    function update($vars) {    function update($vars) {
345      $this->setPostVars($vars);      $this->setPostVars($vars);
346  //print Dumper($vars);      //print Dumper($vars);
347      $data = $this->_transformInputData($vars);      $data = $this->_transformInputData($vars);
348        //print Dumper($data);
349      $this->_saveData($data);      $this->_saveData($data);
350    }    }
351    
# Line 305  class User { Line 418  class User {
418    }    }
419        
420    function refresh() {    function refresh() {
421      if ($this->pObject) {$this->pObject->flushState();}      if ($this->pObject) {$this->pObject->flush();}
422      $this->meta[data_ready] = 0;      $this->meta[data_ready] = 0;
423    }    }
424        
# Line 353  class User { Line 466  class User {
466    function hadTimeout() {    function hadTimeout() {
467      if ($this->state[autologout]) { $this->state[autologout] = ''; return 1; }      if ($this->state[autologout]) { $this->state[autologout] = ''; return 1; }
468    }    }
469      
470      function getNewMessages() {
471        $messages = array();
472        $userguid = $this->getUserGuid();
473        connectdb();
474        $sql = "SELECT * FROM td_message WHERE target_guid='$userguid' AND new='1'";
475              if ($res=send_sql($sql)) {
476          while($row = mysql_fetch_array($res,MYSQL_ASSOC)) {
477                        if (!is_array($row)) { return 0; }
478                        array_push($messages, $row);
479          }
480            }
481            return $messages;
482      }
483      
484      function markNewMessage($mid) {
485        connectdb();
486        $sql = "UPDATE td_message SET new='0' WHERE mid='$mid'";
487              if(!$res=send_sql($sql)) {
488                return "Message not found!";
489              }
490      }
491    
492  }  }
493    

Legend:
Removed from v.1.10  
changed lines
  Added in v.1.20

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