--- nfo/php/libs/org.netfrag.flib/Tracker/User.php 2004/03/11 21:04:48 1.15
+++ nfo/php/libs/org.netfrag.flib/Tracker/User.php 2004/05/06 13:02:09 1.16
@@ -10,9 +10,12 @@
// -----------------------------------------------------------------------------
-// $Id: User.php,v 1.15 2004/03/11 21:04:48 jonen Exp $
+// $Id: User.php,v 1.16 2004/05/06 13:02:09 jonen Exp $
// -----------------------------------------------------------------------------
// $Log: User.php,v $
+// Revision 1.16 2004/05/06 13:02:09 jonen
+// + added/modified functions related to User-Messages
+//
// Revision 1.15 2004/03/11 21:04:48 jonen
// +changed backend-functions to only get/save User ONLY not SOME object (security!)
//
@@ -157,6 +160,7 @@
function _saveData($newRawData) {
+ //print "newRawData: " . Dumper($newRawData) . "
";
foreach ($newRawData as $key => $val) {
//print "$key => $val
";
$this->set($key, $val);
@@ -176,12 +180,21 @@
if($type == 'commit') {
$args = array( 'guid' => $this->data[guid], 'data' => $this->data );
$this->pObject->backend->send('saveUser', $args, array( utf8 => 1) );
- }
+ $this->_save_local();
+ }
// invalidate data only if it's not for caching purposes
if ($type != 'cache') {
$this->meta[data_ready] = 0;
}
}
+
+ function _save_local() {
+ connectdb();
+ $username = $this->get('userData.username');
+ $password = $this->get('userData.password');
+ $sql = "UPDATE td_users SET pass='$password' WHERE uname='$username'";
+ $res = send_sql($sql);
+ }
function save() {
$this->_doDataReady();
@@ -195,6 +208,15 @@
$this->_create($attr);
}
+ function createGuest() {
+ if($this->isLoggedOn) { return; }
+ //$this->_save();
+ //$attr = $this->pObject->getResult();
+ //print DumpVar($attr);
+ $data = $this->_createGuest();
+ return $data;
+ }
+
function _create($result) {
global $site;
//print "saving to backend: " . dumpVar($result) . "
";
@@ -216,6 +238,29 @@
//$this->_init($objectId);
}
+ function _createGuest() {
+ global $site;
+ //print "saving to backend: " . dumpVar($result) . "
";
+ if(!$this->pObject) {
+ $rpcinfo = $this->site->configuration->get("rpcinfo");
+ $pObject = mkObject('DesignPattern::RemoteProxy', 'guest', array( key => 1, command => 'createGuestUser', '', remote => 1, rpcinfo => $rpcinfo, cache => array( db => 1, session => 1 ), connect => 1 ) );
+ $response = $pObject->getResult();
+ } else {
+ $response = $this->pObject->backend->send('createGuestUser');
+ }
+ //print "response: " . Dumper($response) . "
";
+ $objectId = $response[oid];
+ if($objectId) {
+ return $response;
+ }
+ else {
+ // TODO: handle this with a generic rpc-debug/pending function
+ $site->session->set('login_error', 'rpc_error');
+ $site->redirect( getlink('/pub/login/') );
+ }
+ //$this->_init($objectId);
+ }
+
function get($attr) {
$this->_doDataReady();
$deep = new Data_Deep($this->data);
@@ -236,14 +281,14 @@
//===== function userlogin =========================
function login($user,$passwd) {
- connectdb();
- //$sql = "SELECT * FROM td_users WHERE uname='$user'";
- $sql = "SELECT user_oid, guid, uname, pass FROM td_users WHERE uname='$user'";
- if ($res=send_sql($sql)) {
- $row = mysql_fetch_array($res,MYSQL_ASSOC);
- if (!is_array($row)) { return 0; }
- }
- if ($row[pass] == $passwd) {
+ connectdb();
+ //$sql = "SELECT * FROM td_users WHERE uname='$user'";
+ $sql = "SELECT user_oid, guid, uname, pass FROM td_users WHERE uname='$user'";
+ if ($res=send_sql($sql)) {
+ $row = mysql_fetch_array($res,MYSQL_ASSOC);
+ if (!is_array($row)) { return 0; }
+ }
+ if ($row[pass] == $passwd) {
//return $uservars_db;
// store 1st priority user-data to state
$this->state[id] = $row[user_oid];
@@ -255,7 +300,18 @@
} else {
return 0;
}
-}
+ }
+
+ //===== function guestlogin =========================
+ function loginGuest($data) {
+ // store 1st priority user-data to state
+ $this->state[id] = $data[oid];
+ $this->state[guid] = $data[guid];
+ $this->state[status] = $this->meta[logontoken];
+ $this->_saveState();
+ $this->site->log( get_class($this) . "->guest-login ok", PEAR_LOG_NOTICE );
+ return 1;
+ }
function exists($string) {
connectdb();
@@ -273,8 +329,9 @@
function update($vars) {
$this->setPostVars($vars);
-//print Dumper($vars);
+ //print Dumper($vars);
$data = $this->_transformInputData($vars);
+ //print Dumper($data);
$this->_saveData($data);
}
@@ -395,6 +452,28 @@
function hadTimeout() {
if ($this->state[autologout]) { $this->state[autologout] = ''; return 1; }
}
+
+ function getNewMessages() {
+ $messages = array();
+ $userguid = $this->getUserGuid();
+ connectdb();
+ $sql = "SELECT * FROM td_message WHERE target_guid='$userguid' AND new='1'";
+ if ($res=send_sql($sql)) {
+ while($row = mysql_fetch_array($res,MYSQL_ASSOC)) {
+ if (!is_array($row)) { return 0; }
+ array_push($messages, $row);
+ }
+ }
+ return $messages;
+ }
+
+ function markNewMessage($mid) {
+ connectdb();
+ $sql = "UPDATE td_message SET new='0' WHERE mid='$mid'";
+ if(!$res=send_sql($sql)) {
+ return "Message not found!";
+ }
+ }
}