| 3 |
// $Id$ |
// $Id$ |
| 4 |
// ----------------------------------------------------------------------------- |
// ----------------------------------------------------------------------------- |
| 5 |
// $Log$ |
// $Log$ |
| 6 |
|
// Revision 1.8 2002/12/28 01:16:42 jonen |
| 7 |
|
// + added clear of $this->state[autologout] at 'hadTimeout()' |
| 8 |
|
// |
| 9 |
|
// Revision 1.7 2002/12/23 11:32:28 jonen |
| 10 |
|
// + added inserting of uservars on '_create' to frontend db(needed to login user after create!) |
| 11 |
|
// + added hard link to page 'pub/register', TODO: move this out here |
| 12 |
|
// |
| 13 |
|
// Revision 1.6 2002/12/18 22:46:06 jonen |
| 14 |
|
// + added function 'getUserGuid()' |
| 15 |
|
// (returns user's 'guid' read from database at function 'login()' (now)) |
| 16 |
|
// + function '_loadData()' loads user remote now via 'getUserGuid()' |
| 17 |
|
// |
| 18 |
|
// Revision 1.5 2002/12/12 21:34:32 joko |
| 19 |
|
// + fix in 'function update': invalidate data only if it's not for caching purposes |
| 20 |
|
// |
| 21 |
|
// Revision 1.4 2002/12/06 04:10:28 joko |
| 22 |
|
// + replaced 'xyzCache' through 'xyzProxy' |
| 23 |
|
// |
| 24 |
|
// Revision 1.3 2002/12/04 07:42:54 jonen |
| 25 |
|
// + changes according to backend schema change |
| 26 |
|
// |
| 27 |
// Revision 1.2 2002/12/03 16:47:22 joko |
// Revision 1.2 2002/12/03 16:47:22 joko |
| 28 |
// - function preLogout() |
// - function preLogout() |
| 29 |
// + function preLogout($autologout = 0) |
// + function preLogout($autologout = 0) |
| 105 |
|
|
| 106 |
|
|
| 107 |
function _loadData() { |
function _loadData() { |
| 108 |
$this->pObject = new ProxyObject($this->state[id]); |
$this->pObject = new ProxyObject($this->getUserGuid(), array( remote => 1, classname => "NetPerson", guid => 1) ); |
| 109 |
if ($this->state[id]) { |
if ($this->getUserGuid()) { |
| 110 |
$this->data = $this->pObject->getAttributes(); |
$this->data = $this->pObject->getAttributes(); |
| 111 |
} |
} |
| 112 |
$this->meta[data_ready] = 1; |
$this->meta[data_ready] = 1; |
| 121 |
|
|
| 122 |
$this->_save("cache"); |
$this->_save("cache"); |
| 123 |
|
|
| 124 |
//$this->pObject->flushCache(); // done in "pObject->save" |
//$this->pObject->flushProxy(); // done in "pObject->save" |
| 125 |
|
|
| 126 |
} |
} |
| 127 |
|
|
| 128 |
function _save($type = '') { |
function _save($type = '') { |
| 129 |
|
//print Dumper($this->data); |
| 130 |
$this->pObject->save($this->data, $type); |
$this->pObject->save($this->data, $type); |
| 131 |
$this->meta[data_ready] = 0; |
// invalidate data only if it's not for caching purposes |
| 132 |
|
if ($type != 'cache') { |
| 133 |
|
$this->meta[data_ready] = 0; |
| 134 |
|
} |
| 135 |
} |
} |
| 136 |
|
|
| 137 |
function save() { |
function save() { |
| 150 |
//print "saving to backend: " . dumpVar($result) . "<br>"; |
//print "saving to backend: " . dumpVar($result) . "<br>"; |
| 151 |
$response = $this->pObject->backend->send('createUser', array('data' => $result) ); |
$response = $this->pObject->backend->send('createUser', array('data' => $result) ); |
| 152 |
$objectId = $response[oid]; |
$objectId = $response[oid]; |
| 153 |
|
if($objectId) { |
| 154 |
|
connectdb(); |
| 155 |
|
$guid = $response[guid]; |
| 156 |
|
$username = $this->get('userData.username'); |
| 157 |
|
$password = $this->get('userData.password'); |
| 158 |
|
$sql = "INSERT into td_users VALUES ( '$objectId', '$guid', '', '$username', '$password','' )"; |
| 159 |
|
$res = send_sql($sql); |
| 160 |
|
} |
| 161 |
|
else { |
| 162 |
|
// TODO: handle this with a generic rpc-debug/pending function |
| 163 |
|
$site->session->set('register_error', 'rpc_error'); |
| 164 |
|
$site->redirect( getlink('/pub/register/') ); |
| 165 |
|
} |
| 166 |
//$this->_init($objectId); |
//$this->_init($objectId); |
| 167 |
} |
} |
| 168 |
|
|
| 197 |
function login($user,$passwd) { |
function login($user,$passwd) { |
| 198 |
connectdb(); |
connectdb(); |
| 199 |
//$sql = "SELECT * FROM td_users WHERE uname='$user'"; |
//$sql = "SELECT * FROM td_users WHERE uname='$user'"; |
| 200 |
$sql = "SELECT user_oid, uname, pass FROM td_users WHERE uname='$user'"; |
$sql = "SELECT user_oid, guid, uname, pass FROM td_users WHERE uname='$user'"; |
| 201 |
if ($res=send_sql($sql)) { |
if ($res=send_sql($sql)) { |
| 202 |
$row = mysql_fetch_array($res,MYSQL_ASSOC); |
$row = mysql_fetch_array($res,MYSQL_ASSOC); |
| 203 |
if (!is_array($row)) { return 0; } |
if (!is_array($row)) { return 0; } |
| 206 |
//return $uservars_db; |
//return $uservars_db; |
| 207 |
// store 1st priority user-data to state |
// store 1st priority user-data to state |
| 208 |
$this->state[id] = $row[user_oid]; |
$this->state[id] = $row[user_oid]; |
| 209 |
|
$this->state[guid] = $row[guid]; |
| 210 |
$this->state[status] = $this->meta[logontoken]; |
$this->state[status] = $this->meta[logontoken]; |
| 211 |
$this->_saveState(); |
$this->_saveState(); |
| 212 |
$this->site->log( get_class($this) . "->login ok", LOG_DEBUG ); |
$this->site->log( get_class($this) . "->login ok", LOG_DEBUG ); |
| 230 |
} |
} |
| 231 |
|
|
| 232 |
|
|
| 233 |
function update(&$uservars) { |
function update($vars) { |
| 234 |
$this->setPostVars($uservars); |
$this->setPostVars($vars); |
| 235 |
$data = $this->_transformInputData($uservars); |
//print Dumper($vars); |
| 236 |
|
$data = $this->_transformInputData($vars); |
| 237 |
$this->_saveData($data); |
$this->_saveData($data); |
| 238 |
} |
} |
| 239 |
|
|
| 242 |
$mapping_uservars2data = array_flip($def_mapping[data2uservars]); |
$mapping_uservars2data = array_flip($def_mapping[data2uservars]); |
| 243 |
foreach ($uservars as $key => $val) { |
foreach ($uservars as $key => $val) { |
| 244 |
$key_target = $mapping_uservars2data[$key]; |
$key_target = $mapping_uservars2data[$key]; |
| 245 |
//print "$key => $key_target: $val<br>"; |
if($key_target != '') { |
| 246 |
$target[$key_target] = $val; |
//print "$key => $key_target: $val<br>"; |
| 247 |
|
$target[$key_target] = $val; |
| 248 |
|
} |
| 249 |
} |
} |
| 250 |
return $target; |
return $target; |
| 251 |
} |
} |
| 255 |
global $site; |
global $site; |
| 256 |
|
|
| 257 |
// get information about user from site |
// get information about user from site |
| 258 |
$userid = $this->state[id]; |
$userid = $this->getUserId(); |
| 259 |
|
|
| 260 |
$this->site->log( get_class($this) . "->logout: userid $userid", LOG_DEBUG ); |
$this->site->log( get_class($this) . "->logout: userid $userid", LOG_DEBUG ); |
| 261 |
|
|
| 289 |
function getAccountSum() { |
function getAccountSum() { |
| 290 |
// store additional user-data to state |
// store additional user-data to state |
| 291 |
if (!$this->state[accountSum]) { |
if (!$this->state[accountSum]) { |
| 292 |
$this->state[accountSum] = $this->get("financeInfo.accountSum"); |
$this->state[accountSum] = $this->get("account.amount"); |
| 293 |
$this->_saveState(); |
$this->_saveState(); |
| 294 |
} |
} |
| 295 |
return $this->state[accountSum]; |
return $this->state[accountSum]; |
| 298 |
function getAccountCurrency() { |
function getAccountCurrency() { |
| 299 |
// store additional user-data to state |
// store additional user-data to state |
| 300 |
if (!$this->state[accountCurrency]) { |
if (!$this->state[accountCurrency]) { |
| 301 |
$this->state[accountCurrency] = $this->get("financeInfo.currency"); |
$this->state[accountCurrency] = $this->get("account.currency"); |
| 302 |
$this->_saveState(); |
$this->_saveState(); |
| 303 |
} |
} |
| 304 |
//print "state: " . $this->get("financeInfo.currency") . "<br>"; |
//print "state: " . $this->get("financeInfo.currency") . "<br>"; |
| 334 |
return $this->state[id]; |
return $this->state[id]; |
| 335 |
} |
} |
| 336 |
|
|
| 337 |
|
function getUserGuid() { |
| 338 |
|
return $this->state[guid]; |
| 339 |
|
} |
| 340 |
|
|
| 341 |
function getPostVars() { |
function getPostVars() { |
| 342 |
return $this->state[postvars]; |
return $this->state[postvars]; |
| 352 |
} |
} |
| 353 |
|
|
| 354 |
function hadTimeout() { |
function hadTimeout() { |
| 355 |
if ($this->state[autologout]) { return 1; } |
if ($this->state[autologout]) { $this->state[autologout] = ''; return 1; } |
| 356 |
} |
} |
| 357 |
|
|
| 358 |
} |
} |