/[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.13 by joko, Fri Apr 4 02:15:09 2003 UTC revision 1.17 by joko, Mon Jun 7 16:54:53 2004 UTC
# Line 13  Line 13 
13  //    $Id$  //    $Id$
14  //    -----------------------------------------------------------------------------  //    -----------------------------------------------------------------------------
15  //    $Log$  //    $Log$
16    //    Revision 1.17  2004/06/07 16:54:53  joko
17    //    modified cache-key
18    //    added cache-control
19    //
20    //    Revision 1.16  2004/05/06 13:02:09  jonen
21    //    + added/modified functions related to User-Messages
22    //
23    //    Revision 1.15  2004/03/11 21:04:48  jonen
24    //    +changed backend-functions to only get/save User ONLY not SOME object (security!)
25    //
26    //    Revision 1.14  2003/07/02 11:02:09  joko
27    //    + fixed bug with create/_create
28    //
29  //    Revision 1.13  2003/04/04 02:15:09  joko  //    Revision 1.13  2003/04/04 02:15:09  joko
30  //    renamed method of helper object  //    renamed method of helper object
31  //  //
# Line 142  class User { Line 155  class User {
155      $this->meta[data_ready] = 1;      $this->meta[data_ready] = 1;
156      //$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) );
157      $rpcinfo = $this->site->configuration->get("rpcinfo");      $rpcinfo = $this->site->configuration->get("rpcinfo");
158      $this->pObject = mkObject('DesignPattern::RemoteProxy', $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 ) );
159      if ($this->getUserGuid()) {      $cache_key = $this->getUserGuid() . "_user";
160        $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 ) );
161         if ($this->getUserGuid()) {
162        $this->data = $this->pObject->getResult();        $this->data = $this->pObject->getResult();
163      }      }
164    }    }
165    
166    function _saveData($newRawData) {    function _saveData($newRawData) {
167    
168        //print "newRawData: " . Dumper($newRawData) . "<br>";
169      foreach ($newRawData as $key => $val) {      foreach ($newRawData as $key => $val) {
170        //print "$key => $val<br>";        //print "$key => $val<br>";
171        $this->set($key, $val);        $this->set($key, $val);
# Line 163  class User { Line 179  class User {
179        
180    function _save($type = '') {    function _save($type = '') {
181  //print Dumper($this->data);  //print Dumper($this->data);
182      $this->pObject->save($this->data, $type);      //$this->pObject->save($this->data, $type);
183        // new of 2004-03-08: don't use generic 'saveObject'!!
184        //   for security reasons disabled at ClientBackend!!!
185        if($type == 'commit') {
186          $args = array( 'guid' => $this->data[guid], 'data' => $this->data );
187          $this->pObject->backend->send('saveUser', $args, array( utf8 => 1) );
188          $this->_save_local();
189          $this->refresh();
190        }
191      // invalidate data only if it's not for caching purposes      // invalidate data only if it's not for caching purposes
192      if ($type != 'cache') {      if ($type != 'cache') {
193        $this->meta[data_ready] = 0;        $this->meta[data_ready] = 0;
194      }      }
195    }    }
196    
197      function _save_local() {
198            connectdb();
199            $username = $this->get('userData.username');
200            $password = $this->get('userData.password');
201            $sql = "UPDATE td_users SET pass='$password' WHERE uname='$username'";
202                $res = send_sql($sql);
203      }
204        
205    function save() {    function save() {
206      $this->_doDataReady();      $this->_doDataReady();
# Line 177  class User { Line 209  class User {
209        
210    function create() {    function create() {
211     $this->_save();     $this->_save();
212     $attr = $this->pObject->getAttributes();     $attr = $this->pObject->getResult();
213     //print DumpVar($attr);     //print DumpVar($attr);
214     $this->_create($attr);     $this->_create($attr);
215    }    }
216    
217      function createGuest() {
218        if($this->isLoggedOn) { return; }
219       //$this->_save();
220       //$attr = $this->pObject->getResult();
221       //print DumpVar($attr);
222       $data = $this->_createGuest();
223       return $data;
224      }
225    
226    function _create($result) {    function _create($result) {
227        global $site;
228      //print "saving to backend: " . dumpVar($result) . "<br>";      //print "saving to backend: " . dumpVar($result) . "<br>";
229      $response = $this->pObject->backend->send('createUser', array('data' => $result) );      $response = $this->pObject->backend->send('createUser', array('data' => $result) );
230      $objectId = $response[oid];      $objectId = $response[oid];
# Line 202  class User { Line 244  class User {
244      //$this->_init($objectId);      //$this->_init($objectId);
245    }    }
246    
247      function _createGuest() {
248        global $site;
249        //print "saving to backend: " . dumpVar($result) . "<br>";
250        if(!$this->pObject) {
251          $rpcinfo = $this->site->configuration->get("rpcinfo");
252          $pObject = mkObject('DesignPattern::RemoteProxy', 'guest', array( key => 1, command => 'createGuestUser', '', remote => 1, rpcinfo => $rpcinfo, cache => array( db => 1, session => 1 ), connect => 1 ) );
253          $response = $pObject->getResult();
254        } else {
255          $response = $this->pObject->backend->send('createGuestUser');
256        }
257        //print "response: " . Dumper($response) . "<br>";
258        $objectId = $response[oid];
259        if($objectId) {
260          return $response;
261              }
262              else {
263                // TODO: handle this with a generic rpc-debug/pending function
264          $site->session->set('login_error', 'rpc_error');
265          $site->redirect( getlink('/pub/login/') );
266              }
267        //$this->_init($objectId);
268      }
269    
270    function get($attr) {    function get($attr) {
271      $this->_doDataReady();      $this->_doDataReady();
272      $deep = new Data_Deep($this->data);      $deep = new Data_Deep($this->data);
# Line 222  class User { Line 287  class User {
287    
288    //===== function userlogin =========================    //===== function userlogin =========================
289    function login($user,$passwd) {    function login($user,$passwd) {
290          connectdb();            connectdb();
291          //$sql = "SELECT * FROM td_users WHERE uname='$user'";            //$sql = "SELECT * FROM td_users WHERE uname='$user'";
292          $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'";
293          if ($res=send_sql($sql)) {            if ($res=send_sql($sql)) {
294                  $row = mysql_fetch_array($res,MYSQL_ASSOC);                  $row = mysql_fetch_array($res,MYSQL_ASSOC);
295                  if (!is_array($row)) { return 0; }                  if (!is_array($row)) { return 0; }
296          }            }
297          if ($row[pass] == $passwd) {            if ($row[pass] == $passwd) {
298        //return $uservars_db;        //return $uservars_db;
299        // store 1st priority user-data to state        // store 1st priority user-data to state
300          $this->state[id] = $row[user_oid];          $this->state[id] = $row[user_oid];
# Line 241  class User { Line 306  class User {
306      } else {      } else {
307        return 0;        return 0;
308      }      }
309  }    }
310    
311      //===== function guestlogin =========================
312      function loginGuest($data) {
313          // store 1st priority user-data to state
314            $this->state[id] = $data[oid];
315            $this->state[guid] = $data[guid];
316            $this->state[status] = $this->meta[logontoken];
317            $this->_saveState();
318          $this->site->log( get_class($this) . "->guest-login ok", PEAR_LOG_NOTICE );
319          return 1;
320      }
321    
322    function exists($string) {    function exists($string) {
323          connectdb();          connectdb();
# Line 259  class User { Line 335  class User {
335    
336    function update($vars) {    function update($vars) {
337      $this->setPostVars($vars);      $this->setPostVars($vars);
338  //print Dumper($vars);      //print Dumper($vars);
339      $data = $this->_transformInputData($vars);      $data = $this->_transformInputData($vars);
340        //print Dumper($data);
341      $this->_saveData($data);      $this->_saveData($data);
342    }    }
343    
# Line 333  class User { Line 410  class User {
410    }    }
411        
412    function refresh() {    function refresh() {
413      if ($this->pObject) {$this->pObject->flushState();}      if ($this->pObject) {$this->pObject->flush();}
414      $this->meta[data_ready] = 0;      $this->meta[data_ready] = 0;
415    }    }
416        
# Line 381  class User { Line 458  class User {
458    function hadTimeout() {    function hadTimeout() {
459      if ($this->state[autologout]) { $this->state[autologout] = ''; return 1; }      if ($this->state[autologout]) { $this->state[autologout] = ''; return 1; }
460    }    }
461      
462      function getNewMessages() {
463        $messages = array();
464        $userguid = $this->getUserGuid();
465        connectdb();
466        $sql = "SELECT * FROM td_message WHERE target_guid='$userguid' AND new='1'";
467              if ($res=send_sql($sql)) {
468          while($row = mysql_fetch_array($res,MYSQL_ASSOC)) {
469                        if (!is_array($row)) { return 0; }
470                        array_push($messages, $row);
471          }
472            }
473            return $messages;
474      }
475      
476      function markNewMessage($mid) {
477        connectdb();
478        $sql = "UPDATE td_message SET new='0' WHERE mid='$mid'";
479              if(!$res=send_sql($sql)) {
480                return "Message not found!";
481              }
482      }
483    
484  }  }
485    

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

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