3 |
// $Id$ |
// $Id$ |
4 |
// ----------------------------------------------------------------------------- |
// ----------------------------------------------------------------------------- |
5 |
// $Log$ |
// $Log$ |
6 |
|
// Revision 1.7 2002/12/23 11:32:28 jonen |
7 |
|
// + added inserting of uservars on '_create' to frontend db(needed to login user after create!) |
8 |
|
// + added hard link to page 'pub/register', TODO: move this out here |
9 |
|
// |
10 |
|
// Revision 1.6 2002/12/18 22:46:06 jonen |
11 |
|
// + added function 'getUserGuid()' |
12 |
|
// (returns user's 'guid' read from database at function 'login()' (now)) |
13 |
|
// + function '_loadData()' loads user remote now via 'getUserGuid()' |
14 |
|
// |
15 |
|
// Revision 1.5 2002/12/12 21:34:32 joko |
16 |
|
// + fix in 'function update': invalidate data only if it's not for caching purposes |
17 |
|
// |
18 |
// Revision 1.4 2002/12/06 04:10:28 joko |
// Revision 1.4 2002/12/06 04:10:28 joko |
19 |
// + replaced 'xyzCache' through 'xyzProxy' |
// + replaced 'xyzCache' through 'xyzProxy' |
20 |
// |
// |
102 |
|
|
103 |
|
|
104 |
function _loadData() { |
function _loadData() { |
105 |
$this->pObject = new ProxyObject($this->state[id]); |
$this->pObject = new ProxyObject($this->getUserGuid(), array( remote => 1, classname => "NetPerson", guid => 1) ); |
106 |
if ($this->state[id]) { |
if ($this->getUserGuid()) { |
107 |
$this->data = $this->pObject->getAttributes(); |
$this->data = $this->pObject->getAttributes(); |
108 |
} |
} |
109 |
$this->meta[data_ready] = 1; |
$this->meta[data_ready] = 1; |
123 |
} |
} |
124 |
|
|
125 |
function _save($type = '') { |
function _save($type = '') { |
126 |
|
//print Dumper($this->data); |
127 |
$this->pObject->save($this->data, $type); |
$this->pObject->save($this->data, $type); |
128 |
$this->meta[data_ready] = 0; |
// invalidate data only if it's not for caching purposes |
129 |
|
if ($type != 'cache') { |
130 |
|
$this->meta[data_ready] = 0; |
131 |
|
} |
132 |
} |
} |
133 |
|
|
134 |
function save() { |
function save() { |
147 |
//print "saving to backend: " . dumpVar($result) . "<br>"; |
//print "saving to backend: " . dumpVar($result) . "<br>"; |
148 |
$response = $this->pObject->backend->send('createUser', array('data' => $result) ); |
$response = $this->pObject->backend->send('createUser', array('data' => $result) ); |
149 |
$objectId = $response[oid]; |
$objectId = $response[oid]; |
150 |
|
if($objectId) { |
151 |
|
connectdb(); |
152 |
|
$guid = $response[guid]; |
153 |
|
$username = $this->get('userData.username'); |
154 |
|
$password = $this->get('userData.password'); |
155 |
|
$sql = "INSERT into td_users VALUES ( '$objectId', '$guid', '', '$username', '$password','' )"; |
156 |
|
$res = send_sql($sql); |
157 |
|
} |
158 |
|
else { |
159 |
|
// TODO: handle this with a generic rpc-debug/pending function |
160 |
|
$site->session->set('register_error', 'rpc_error'); |
161 |
|
$site->redirect( getlink('/pub/register/') ); |
162 |
|
} |
163 |
//$this->_init($objectId); |
//$this->_init($objectId); |
164 |
} |
} |
165 |
|
|
194 |
function login($user,$passwd) { |
function login($user,$passwd) { |
195 |
connectdb(); |
connectdb(); |
196 |
//$sql = "SELECT * FROM td_users WHERE uname='$user'"; |
//$sql = "SELECT * FROM td_users WHERE uname='$user'"; |
197 |
$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'"; |
198 |
if ($res=send_sql($sql)) { |
if ($res=send_sql($sql)) { |
199 |
$row = mysql_fetch_array($res,MYSQL_ASSOC); |
$row = mysql_fetch_array($res,MYSQL_ASSOC); |
200 |
if (!is_array($row)) { return 0; } |
if (!is_array($row)) { return 0; } |
203 |
//return $uservars_db; |
//return $uservars_db; |
204 |
// store 1st priority user-data to state |
// store 1st priority user-data to state |
205 |
$this->state[id] = $row[user_oid]; |
$this->state[id] = $row[user_oid]; |
206 |
|
$this->state[guid] = $row[guid]; |
207 |
$this->state[status] = $this->meta[logontoken]; |
$this->state[status] = $this->meta[logontoken]; |
208 |
$this->_saveState(); |
$this->_saveState(); |
209 |
$this->site->log( get_class($this) . "->login ok", LOG_DEBUG ); |
$this->site->log( get_class($this) . "->login ok", LOG_DEBUG ); |
227 |
} |
} |
228 |
|
|
229 |
|
|
230 |
function update(&$uservars) { |
function update($vars) { |
231 |
$this->setPostVars($uservars); |
$this->setPostVars($vars); |
232 |
$data = $this->_transformInputData($uservars); |
//print Dumper($vars); |
233 |
|
$data = $this->_transformInputData($vars); |
234 |
$this->_saveData($data); |
$this->_saveData($data); |
235 |
} |
} |
236 |
|
|
239 |
$mapping_uservars2data = array_flip($def_mapping[data2uservars]); |
$mapping_uservars2data = array_flip($def_mapping[data2uservars]); |
240 |
foreach ($uservars as $key => $val) { |
foreach ($uservars as $key => $val) { |
241 |
$key_target = $mapping_uservars2data[$key]; |
$key_target = $mapping_uservars2data[$key]; |
242 |
//print "$key => $key_target: $val<br>"; |
if($key_target != '') { |
243 |
$target[$key_target] = $val; |
//print "$key => $key_target: $val<br>"; |
244 |
|
$target[$key_target] = $val; |
245 |
|
} |
246 |
} |
} |
247 |
return $target; |
return $target; |
248 |
} |
} |
252 |
global $site; |
global $site; |
253 |
|
|
254 |
// get information about user from site |
// get information about user from site |
255 |
$userid = $this->state[id]; |
$userid = $this->getUserId(); |
256 |
|
|
257 |
$this->site->log( get_class($this) . "->logout: userid $userid", LOG_DEBUG ); |
$this->site->log( get_class($this) . "->logout: userid $userid", LOG_DEBUG ); |
258 |
|
|
331 |
return $this->state[id]; |
return $this->state[id]; |
332 |
} |
} |
333 |
|
|
334 |
|
function getUserGuid() { |
335 |
|
return $this->state[guid]; |
336 |
|
} |
337 |
|
|
338 |
function getPostVars() { |
function getPostVars() { |
339 |
return $this->state[postvars]; |
return $this->state[postvars]; |