[Logicampus-cvs] logicampus/src/logicreate/lib LC_mysql.php, 1.21, 1.22 LC_user.php, 1.33, 1.34 Use
Brought to you by:
trilexcom
From: Mark K <har...@us...> - 2008-01-26 02:09:17
|
Update of /cvsroot/logicampus/logicampus/src/logicreate/lib In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv16993 Modified Files: LC_mysql.php LC_user.php User.php pellet.php Log Message: cleaning up login and session functionality. removing cruft, reworking the idea of saving the user object each request. Index: pellet.php =================================================================== RCS file: /cvsroot/logicampus/logicampus/src/logicreate/lib/pellet.php,v retrieving revision 1.31 retrieving revision 1.32 diff -C2 -d -r1.31 -r1.32 *** pellet.php 3 Oct 2007 02:07:53 -0000 1.31 --- pellet.php 26 Jan 2008 02:09:13 -0000 1.32 *************** *** 486,491 **** $lcUser->activeClassTaught->id_classes != $lcObj->getvars['id_classes'] ) { - //__FIXME__ add constraint against classesTaught array; - foreach ( $lcUser->classesTaught as $k => $v) { if ($v->id_classes == $lcObj->getvars['id_classes']) { --- 486,489 ---- Index: LC_mysql.php =================================================================== RCS file: /cvsroot/logicampus/logicampus/src/logicreate/lib/LC_mysql.php,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** LC_mysql.php 8 Oct 2007 14:49:08 -0000 1.21 --- LC_mysql.php 26 Jan 2008 02:09:13 -0000 1.22 *************** *** 290,296 **** /** ! * Return the number of rows affected by the last query * ! * @return int number of affected rows */ function getNumRows() { --- 290,296 ---- /** ! * Return the number of rows retruned by the last query * ! * @return int number of rows returned */ function getNumRows() { *************** *** 299,302 **** --- 299,310 ---- } + /** + * Return the number of rows affected by the last query + * + * @return int number of affected rows + */ + function getAffectedRows() { + return @mysql_affected_rows(); + } /** Index: LC_user.php =================================================================== RCS file: /cvsroot/logicampus/logicampus/src/logicreate/lib/LC_user.php,v retrieving revision 1.33 retrieving revision 1.34 diff -C2 -d -r1.33 -r1.34 *** LC_user.php 8 Oct 2007 14:35:28 -0000 1.33 --- LC_user.php 26 Jan 2008 02:09:13 -0000 1.34 *************** *** 74,77 **** --- 74,78 ---- } + /* if (rand(1,20) >= 20 ) { //gc cleanup, mysql specific with DATE_SUB *************** *** 80,87 **** --- 81,90 ---- $db->freeResult(); } + */ $db->query("select * from lcSessions where sesskey = '$sessID'",false); $j = $db->nextRecord(); $db->freeResult(); + if (!$j) { //trigger_error('second try to get session for: '.$sessID); *************** *** 92,127 **** if (function_exists("gzuncompress")) { ! $temp2 = unserialize(gzuncompress(base64_decode($db->record['sessdata']))); } else { ! $temp2 = unserialize(base64_decode($db->record['sessdata'])); } ! if (!$temp2) { ! $temp2 = unserialize(base64_decode($db->record['sessdata'])); } ! ! if ($temp2['_userobj']->username!='anonymous') { ! $tt = 'got valid user obj back with user name = '.$temp2['_userobj']->username; } if ($j) { - $sessArr = $temp2; - /* - $sessArr = unserialize(gzuncompress(base64_decode($db->record["sessdata"]))); - if (!$sessArr) { - $sessArr = unserialize((base64_decode($db->record["sessdata"]))); - } - */ $origSession = crc32($db->record['sessdata']); ! if ( is_object($sessArr['_userobj']) && $sessArr['_userobj']->userType > 0) { ! $temp = $sessArr['_userobj']; ! $temp = lcUser::getUserByUsername($sessArr['_userobj']->username); ! unset($sessArr['_userobj']); $temp->sessionvars = $sessArr; $temp->_sessionKey = $sessID; $temp->_origChecksum = $origSession; $temp->loggedIn = true; ! } else ! if ($sessArr["_username"] != "") { $temp = lcUser::getUserByUsername($sessArr["_username"]); $temp->sessionvars = $sessArr; --- 95,123 ---- if (function_exists("gzuncompress")) { ! $sessArr = unserialize(gzuncompress(base64_decode($db->record['sessdata']))); } else { ! $sessArr = unserialize(base64_decode($db->record['sessdata'])); } ! //maybe it wasn't gzipped ! if (!$sessArr) { ! $sessArr = unserialize(base64_decode($db->record['sessdata'])); } ! if (!$sessArr) { ! $sessArr = unserialize($db->record['sessdata']); } if ($j) { $origSession = crc32($db->record['sessdata']); ! //DEPRECATED ! if ($sessArr["_userId"] != "") { ! $temp = lcUser::getUserByPkey($sessArr["_userId"]); $temp->sessionvars = $sessArr; $temp->_sessionKey = $sessID; $temp->_origChecksum = $origSession; $temp->loggedIn = true; ! $temp->loadProfile(); ! } ! else if ($sessArr["_username"] != "") { $temp = lcUser::getUserByUsername($sessArr["_username"]); $temp->sessionvars = $sessArr; *************** *** 168,172 **** if ( !$db->nextRecord() ) { return new lcUser(); } $db->freeResult(); ! $temp = new lcUser(); $temp->username = $db->record['username']; $temp->password = $db->record['password']; --- 164,180 ---- if ( !$db->nextRecord() ) { return new lcUser(); } $db->freeResult(); ! switch($db->record['userType']) { ! case USERTYPE_FACULTY: ! $temp = new FacultyUser($db->record['username']); ! break; ! case USERTYPE_STUDENT: ! $temp = new StudentUser($db->record['username']); ! break; ! case USERTYPE_STANDARD: ! $temp = new StandardUser($db->record['username']); ! break; ! default: ! $temp = new lcUser(); ! } $temp->username = $db->record['username']; $temp->password = $db->record['password']; *************** *** 174,177 **** --- 182,186 ---- $temp->groups = array_merge($temp->groups,explode("|",$db->record['groups'])); $temp->userId = $db->record['pkey']; + $temp->loadProfile(); return $temp; } *************** *** 299,303 **** * Remove from proflie_course_family */ - function deleteUser() { --- 308,311 ---- *************** *** 371,374 **** --- 379,385 ---- } + function commitSessionVars() { + $this->sessionvars['_userId'] = $this->userId; + } *************** *** 385,391 **** if ($this->_sessionKey == "") { return false; } if ($this->username == "") { return false; /*print "no username"; exit();*/} ! //unhook session from user, reverse rolse $sessBlob = $this->sessionvars; ! unset($this->sessionvars); // combatting access denied issue // 8/5/03 mgk --- 396,404 ---- if ($this->_sessionKey == "") { return false; } if ($this->username == "") { return false; /*print "no username"; exit();*/} ! //save userID to the session ! $this->commitSessionVars(); ! $sessBlob = $this->sessionvars; ! // unset($this->sessionvars); // combatting access denied issue // 8/5/03 mgk *************** *** 394,398 **** //$this->newval = crc32($val); - $sessBlob['_userobj'] = $this; if (function_exists("gzcompress")) { $val = gzcompress(serialize($sessBlob)); --- 407,410 ---- *************** *** 400,415 **** $val = serialize($sessBlob); } ! if ( crc32($val) == $this->_origChecksum) { return; } $db = DB::getHandle(); $sessid = $this->_sessionKey; ! $val=base64_encode($val); $s="UPDATE lcSessions SET username =\"".$this->username."\", sessdata = \"".$val."\" WHERE sesskey = '".$sessid."'"; if ($this->username == "anonymous" ) { ! $s="UPDATE lcSessions SET username =\"".$this->username."\", sessdata = \"".$val."\" WHERE sesskey = '".$sessid."'"; } ! if (!$db->query($s)) { ! die('no update'); ! //no update record, try insert $s="INSERT into lcSessions (username,sessdata,sesskey) values ('".$this->username."','$val','$sessid')"; if ($this->username == "anonymous" ) { --- 412,436 ---- $val = serialize($sessBlob); } + /* + */ + $val = serialize($sessBlob); ! if ( crc32($val) == $this->_origChecksum) { return true; } $db = DB::getHandle(); $sessid = $this->_sessionKey; ! // $val=base64_encode($val); ! $val = addslashes($val); $s="UPDATE lcSessions SET username =\"".$this->username."\", sessdata = \"".$val."\" WHERE sesskey = '".$sessid."'"; if ($this->username == "anonymous" ) { ! $s="UPDATE lcSessions SET sessdata = \"".$val."\" WHERE sesskey = '".$sessid."'"; } ! $queryWorked = $db->query($s); ! $updateWorked = $db->getAffectedRows(); ! if ($updateWorked < 0) { ! $e = ErrorStack::pullError('php'); ! ! $s="DELETE FROM lcSessions WHERE username = '".$this->username."'"; ! $queryWorked = $db->query($s); ! $e = ErrorStack::pullError('php'); $s="INSERT into lcSessions (username,sessdata,sesskey) values ('".$this->username."','$val','$sessid')"; if ($this->username == "anonymous" ) { *************** *** 418,424 **** $db->query($s); } //sess_close(DB::getHandle(),$this->uid,serialize($this->session)); ! $sessBlob['_userobj'] = ''; ! $this->sessionvars = $sessBlob; } --- 439,446 ---- $db->query($s); } + return true; //sess_close(DB::getHandle(),$this->uid,serialize($this->session)); ! // $sessBlob['_userobj'] = ''; ! // $this->sessionvars = $sessBlob; } *************** *** 435,438 **** --- 457,461 ---- if ($this->username == "" ){ $this->username = 'anonymous'; return false; } global $tail; + /* if (!$this->isAnonymous()) { $PHPSESSID=md5 (uniqid (rand())); *************** *** 440,443 **** --- 463,467 ---- $this->_sessionKey = $PHPSESSID; } + */ $this->sessionvars['_username'] = $this->username; if (function_exists("gzcompress")) { *************** *** 447,456 **** } $this->_origChecksum = crc32($val); - $sessid = $this->_sessionKey; ! $s="replace into lcSessions (username,sessdata,sesskey) values ('".$this->username."','$val','$sessid')"; ! $db = DB::getHandle(); ! $db->query($s,false); return true; } --- 471,480 ---- } + /* + */ + $val = serialize($this->sessionvars); $this->_origChecksum = crc32($val); ! $this->saveSession(); return true; } *************** *** 478,481 **** --- 502,506 ---- function endSession($db) { $this->sessionvars["_username"] = ""; + $this->sessionvars["_userId"] = ""; setCookie("PHPSESSID","",0); } *************** *** 520,531 **** $this->password = $db->record['password']; $this->username = $db->record['username']; ! //__FIXME__ what is this fields for?? ! //$this->fields = $db->record; ! $this->sessionvars['_username'] = $username; $this->groups = array_merge($this->groups,explode("|",substr($db->record['groups'],1,-1))); $this->userId = $db->record['pkey']; ! // $this->userType = $db->record['userType']; return true; } else { $this->groups[] = 'public'; return false; --- 545,556 ---- $this->password = $db->record['password']; $this->username = $db->record['username']; ! $this->sessionvars['_userId'] = $db->record['pkey']; $this->groups = array_merge($this->groups,explode("|",substr($db->record['groups'],1,-1))); $this->userId = $db->record['pkey']; ! $this->loadProfile(); return true; } else { + $this->password = ''; + $this->username = 'anonymous'; $this->groups[] = 'public'; return false; Index: User.php =================================================================== RCS file: /cvsroot/logicampus/logicampus/src/logicreate/lib/User.php,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** User.php 8 Oct 2007 14:35:29 -0000 1.8 --- User.php 26 Jan 2008 02:09:13 -0000 1.9 *************** *** 84,93 **** var $classesTaken = array(); var $classesTaught = array(); ! var $activeClassTaught = 0; var $profileTable = 'profile_faculty'; ! # Constructor ! # Grabs all classes the faculty member teaches? Maybe? ! #only gets called on login function FacultyUser ($userid) { --- 84,95 ---- var $classesTaken = array(); var $classesTaught = array(); ! var $activeClassTaught = null; var $profileTable = 'profile_faculty'; ! /** ! * FacultyUser Constructor ! * Grabs all classes the faculty member teaches ! * only gets called on login ! */ function FacultyUser ($userid) { *************** *** 144,147 **** --- 146,150 ---- if ($v->id_classes == $classID) return true; } + reset($lcUser->classesTaught); return false; } |