/[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.6 by jonen, Wed Dec 18 22:46:06 2002 UTC revision 1.14 by joko, Wed Jul 2 11:02:09 2003 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.14  2003/07/02 11:02:09  joko
17    //    + fixed bug with create/_create
18    //
19    //    Revision 1.13  2003/04/04 02:15:09  joko
20    //    renamed method of helper object
21    //
22    //    Revision 1.12  2003/03/03 21:20:47  joko
23    //    mungled the namespaces
24    //
25    //    Revision 1.11  2003/02/14 14:22:06  joko
26    //    + always (re-)tries to connect
27    //
28    //    Revision 1.10  2003/02/13 21:58:39  joko
29    //    + caching mechanisms more configurable now
30    //
31    //    Revision 1.9  2003/02/09 17:46:26  joko
32    //    + now utilizing DesignPattern::RemoteProxy and Data::Deep
33    //
34    //    Revision 1.8  2002/12/28 01:16:42  jonen
35    //    + added clear of $this->state[autologout] at 'hadTimeout()'
36    //
37    //    Revision 1.7  2002/12/23 11:32:28  jonen
38    //    + added inserting of uservars on '_create' to frontend db(needed to login user after create!)
39    //      + added hard link to page 'pub/register', TODO: move this out here
40    //
41  //    Revision 1.6  2002/12/18 22:46:06  jonen  //    Revision 1.6  2002/12/18 22:46:06  jonen
42  //    + added function 'getUserGuid()'  //    + added function 'getUserGuid()'
43  //       (returns user's 'guid' read from database at function 'login()'  (now))  //       (returns user's 'guid' read from database at function 'login()'  (now))
# Line 64  Line 99 
99  //  //
100  //    -----------------------------------------------------------------------------  //    -----------------------------------------------------------------------------
101    
102    
103    /**
104     * This is the User class.
105     *
106     * @author Andreas Motl <andreas.motl@ilo.de>
107     * @package org.netfrag.flib
108     * @name Tracker::User
109     *
110     */
111  class User {  class User {
112        
113    var $state;    var $state;
# Line 98  class User { Line 142  class User {
142    
143    
144    function _loadData() {    function _loadData() {
145      $this->pObject = new ProxyObject($this->getUserGuid(), array( remote => 1, classname => "NetPerson", guid => 1) );      $this->meta[data_ready] = 1;
146        //$this->pObject = new ProxyObject($this->getUserGuid(), array( remote => 1, classname => "NetPerson", guid => 1) );
147        $rpcinfo = $this->site->configuration->get("rpcinfo");
148        $this->pObject = mkObject('DesignPattern::RemoteProxy', $this->getUserGuid(), array( remote => 1, classname => "NetPerson", guid => 1, rpcinfo => $rpcinfo, cache => array( db => 1, session => 1 ), connect => 1 ) );
149      if ($this->getUserGuid()) {      if ($this->getUserGuid()) {
150        $this->data = $this->pObject->getAttributes();        $this->data = $this->pObject->getResult();
151      }      }
     $this->meta[data_ready] = 1;  
152    }    }
153    
154    function _saveData($newRawData) {    function _saveData($newRawData) {
# Line 134  class User { Line 180  class User {
180        
181    function create() {    function create() {
182     $this->_save();     $this->_save();
183     $attr = $this->pObject->getAttributes();     $attr = $this->pObject->getResult();
184     //print DumpVar($attr);     //print DumpVar($attr);
185     $this->_create($attr);     $this->_create($attr);
186    }    }
187    
188    function _create($result) {    function _create($result) {
189        global $site;
190      //print "saving to backend: " . dumpVar($result) . "<br>";      //print "saving to backend: " . dumpVar($result) . "<br>";
191      $response = $this->pObject->backend->send('createUser', array('data' => $result) );      $response = $this->pObject->backend->send('createUser', array('data' => $result) );
192      $objectId = $response[oid];      $objectId = $response[oid];
193        if($objectId) {
194            connectdb();
195            $guid = $response[guid];
196            $username = $this->get('userData.username');
197            $password = $this->get('userData.password');
198            $sql = "INSERT into td_users VALUES ( '$objectId', '$guid', '', '$username', '$password','' )";
199                $res = send_sql($sql);
200              }
201              else {
202                // TODO: handle this with a generic rpc-debug/pending function
203          $site->session->set('register_error', 'rpc_error');
204          $site->redirect( getlink('/pub/register/') );
205              }
206      //$this->_init($objectId);      //$this->_init($objectId);
207    }    }
208    
   function _getHKR($key) {  
     $attr_arr = split('\.', $key);  
     $attr_hkr = '["' . join('"]["', $attr_arr) . '"]';  
     return $attr_hkr;  
   }  
   
209    function get($attr) {    function get($attr) {
210      $this->_doDataReady();      $this->_doDataReady();
211      $hkr = $this->_getHKR($attr);      $deep = new Data_Deep($this->data);
212      $evalstr = 'return $this->data' . $hkr . ';';      return $deep->get($attr);
     $val = eval($evalstr);  
     return $val;  
213    }    }
214    function set($attr, $val) {    function set($attr, $val) {
215      $this->_doDataReady();      $this->_doDataReady();
216      $hkr = $this->_getHKR($attr);      $deep = new Data_Deep($this->data);
217      $evalstr = '$this->data' . $hkr . ' = \'' . $val . '\';';      $deep->set($attr, $val);
     eval($evalstr);  
218    }    }
219        
220    function isLoggedOn() {    function isLoggedOn() {
# Line 189  class User { Line 240  class User {
240          $this->state[guid] = $row[guid];          $this->state[guid] = $row[guid];
241          $this->state[status] = $this->meta[logontoken];          $this->state[status] = $this->meta[logontoken];
242          $this->_saveState();          $this->_saveState();
243        $this->site->log( get_class($this) . "->login ok", LOG_DEBUG );        $this->site->log( get_class($this) . "->login ok", PEAR_LOG_NOTICE );
244        return 1;        return 1;
245      } else {      } else {
246        return 0;        return 0;
# Line 222  class User { Line 273  class User {
273      $mapping_uservars2data = array_flip($def_mapping[data2uservars]);      $mapping_uservars2data = array_flip($def_mapping[data2uservars]);
274      foreach ($uservars as $key => $val) {      foreach ($uservars as $key => $val) {
275        $key_target = $mapping_uservars2data[$key];        $key_target = $mapping_uservars2data[$key];
276        //print "$key => $key_target: $val<br>";        if($key_target != '') {
277        $target[$key_target] = $val;          //print "$key => $key_target: $val<br>";
278            $target[$key_target] = $val;
279          }
280      }      }
281      return $target;      return $target;
282    }    }
# Line 235  class User { Line 288  class User {
288      // get information about user from site      // get information about user from site
289        $userid = $this->getUserId();        $userid = $this->getUserId();
290    
291        $this->site->log( get_class($this) . "->logout: userid $userid", LOG_DEBUG );        $this->site->log( get_class($this) . "->logout: userid $userid", PEAR_LOG_NOTICE );
292            
293      // get information about session from php      // get information about session from php
294        $session_id = session_id();        $session_id = session_id();
# Line 330  class User { Line 383  class User {
383    }    }
384        
385    function hadTimeout() {    function hadTimeout() {
386      if ($this->state[autologout]) { return 1; }      if ($this->state[autologout]) { $this->state[autologout] = ''; return 1; }
387    }    }
388    
389  }  }

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.14

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