/[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.15 by jonen, Thu Mar 11 21:04:48 2004 UTC revision 1.16 by jonen, Thu May 6 13:02:09 2004 UTC
# Line 13  Line 13 
13  //    $Id$  //    $Id$
14  //    -----------------------------------------------------------------------------  //    -----------------------------------------------------------------------------
15  //    $Log$  //    $Log$
16    //    Revision 1.16  2004/05/06 13:02:09  jonen
17    //    + added/modified functions related to User-Messages
18    //
19  //    Revision 1.15  2004/03/11 21:04:48  jonen  //    Revision 1.15  2004/03/11 21:04:48  jonen
20  //    +changed backend-functions to only get/save User ONLY not SOME object (security!)  //    +changed backend-functions to only get/save User ONLY not SOME object (security!)
21  //  //
# Line 157  class User { Line 160  class User {
160    
161    function _saveData($newRawData) {    function _saveData($newRawData) {
162    
163        //print "newRawData: " . Dumper($newRawData) . "<br>";
164      foreach ($newRawData as $key => $val) {      foreach ($newRawData as $key => $val) {
165        //print "$key => $val<br>";        //print "$key => $val<br>";
166        $this->set($key, $val);        $this->set($key, $val);
# Line 176  class User { Line 180  class User {
180      if($type == 'commit') {      if($type == 'commit') {
181        $args = array( 'guid' => $this->data[guid], 'data' => $this->data );        $args = array( 'guid' => $this->data[guid], 'data' => $this->data );
182        $this->pObject->backend->send('saveUser', $args, array( utf8 => 1) );        $this->pObject->backend->send('saveUser', $args, array( utf8 => 1) );
183      }              $this->_save_local();
184        }
185      // invalidate data only if it's not for caching purposes      // invalidate data only if it's not for caching purposes
186      if ($type != 'cache') {      if ($type != 'cache') {
187        $this->meta[data_ready] = 0;        $this->meta[data_ready] = 0;
188      }      }
189    }    }
190    
191      function _save_local() {
192            connectdb();
193            $username = $this->get('userData.username');
194            $password = $this->get('userData.password');
195            $sql = "UPDATE td_users SET pass='$password' WHERE uname='$username'";
196                $res = send_sql($sql);
197      }
198        
199    function save() {    function save() {
200      $this->_doDataReady();      $this->_doDataReady();
# Line 195  class User { Line 208  class User {
208     $this->_create($attr);     $this->_create($attr);
209    }    }
210    
211      function createGuest() {
212        if($this->isLoggedOn) { return; }
213       //$this->_save();
214       //$attr = $this->pObject->getResult();
215       //print DumpVar($attr);
216       $data = $this->_createGuest();
217       return $data;
218      }
219    
220    function _create($result) {    function _create($result) {
221      global $site;      global $site;
222      //print "saving to backend: " . dumpVar($result) . "<br>";      //print "saving to backend: " . dumpVar($result) . "<br>";
# Line 216  class User { Line 238  class User {
238      //$this->_init($objectId);      //$this->_init($objectId);
239    }    }
240    
241      function _createGuest() {
242        global $site;
243        //print "saving to backend: " . dumpVar($result) . "<br>";
244        if(!$this->pObject) {
245          $rpcinfo = $this->site->configuration->get("rpcinfo");
246          $pObject = mkObject('DesignPattern::RemoteProxy', 'guest', array( key => 1, command => 'createGuestUser', '', remote => 1, rpcinfo => $rpcinfo, cache => array( db => 1, session => 1 ), connect => 1 ) );
247          $response = $pObject->getResult();
248        } else {
249          $response = $this->pObject->backend->send('createGuestUser');
250        }
251        //print "response: " . Dumper($response) . "<br>";
252        $objectId = $response[oid];
253        if($objectId) {
254          return $response;
255              }
256              else {
257                // TODO: handle this with a generic rpc-debug/pending function
258          $site->session->set('login_error', 'rpc_error');
259          $site->redirect( getlink('/pub/login/') );
260              }
261        //$this->_init($objectId);
262      }
263    
264    function get($attr) {    function get($attr) {
265      $this->_doDataReady();      $this->_doDataReady();
266      $deep = new Data_Deep($this->data);      $deep = new Data_Deep($this->data);
# Line 236  class User { Line 281  class User {
281    
282    //===== function userlogin =========================    //===== function userlogin =========================
283    function login($user,$passwd) {    function login($user,$passwd) {
284          connectdb();            connectdb();
285          //$sql = "SELECT * FROM td_users WHERE uname='$user'";            //$sql = "SELECT * FROM td_users WHERE uname='$user'";
286          $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'";
287          if ($res=send_sql($sql)) {            if ($res=send_sql($sql)) {
288                  $row = mysql_fetch_array($res,MYSQL_ASSOC);                  $row = mysql_fetch_array($res,MYSQL_ASSOC);
289                  if (!is_array($row)) { return 0; }                  if (!is_array($row)) { return 0; }
290          }            }
291          if ($row[pass] == $passwd) {            if ($row[pass] == $passwd) {
292        //return $uservars_db;        //return $uservars_db;
293        // store 1st priority user-data to state        // store 1st priority user-data to state
294          $this->state[id] = $row[user_oid];          $this->state[id] = $row[user_oid];
# Line 255  class User { Line 300  class User {
300      } else {      } else {
301        return 0;        return 0;
302      }      }
303  }    }
304    
305      //===== function guestlogin =========================
306      function loginGuest($data) {
307          // store 1st priority user-data to state
308            $this->state[id] = $data[oid];
309            $this->state[guid] = $data[guid];
310            $this->state[status] = $this->meta[logontoken];
311            $this->_saveState();
312          $this->site->log( get_class($this) . "->guest-login ok", PEAR_LOG_NOTICE );
313          return 1;
314      }
315    
316    function exists($string) {    function exists($string) {
317          connectdb();          connectdb();
# Line 273  class User { Line 329  class User {
329    
330    function update($vars) {    function update($vars) {
331      $this->setPostVars($vars);      $this->setPostVars($vars);
332  //print Dumper($vars);      //print Dumper($vars);
333      $data = $this->_transformInputData($vars);      $data = $this->_transformInputData($vars);
334        //print Dumper($data);
335      $this->_saveData($data);      $this->_saveData($data);
336    }    }
337    
# Line 395  class User { Line 452  class User {
452    function hadTimeout() {    function hadTimeout() {
453      if ($this->state[autologout]) { $this->state[autologout] = ''; return 1; }      if ($this->state[autologout]) { $this->state[autologout] = ''; return 1; }
454    }    }
455      
456      function getNewMessages() {
457        $messages = array();
458        $userguid = $this->getUserGuid();
459        connectdb();
460        $sql = "SELECT * FROM td_message WHERE target_guid='$userguid' AND new='1'";
461              if ($res=send_sql($sql)) {
462          while($row = mysql_fetch_array($res,MYSQL_ASSOC)) {
463                        if (!is_array($row)) { return 0; }
464                        array_push($messages, $row);
465          }
466            }
467            return $messages;
468      }
469      
470      function markNewMessage($mid) {
471        connectdb();
472        $sql = "UPDATE td_message SET new='0' WHERE mid='$mid'";
473              if(!$res=send_sql($sql)) {
474                return "Message not found!";
475              }
476      }
477    
478  }  }
479    

Legend:
Removed from v.1.15  
changed lines
  Added in v.1.16

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