Thread: [phpMP-CVS] CVS: phpMP/includes auth.php,1.26,1.27 user.php,1.9,1.10
Status: Pre-Alpha
Brought to you by:
heimidal
From: Brian R. <hei...@us...> - 2003-02-04 02:34:39
|
Update of /cvsroot/phpmp/phpMP/includes In directory sc8-pr-cvs1:/tmp/cvs-serv17250/includes Modified Files: auth.php user.php Log Message: Fixed a few small bugs. Index: auth.php =================================================================== RCS file: /cvsroot/phpmp/phpMP/includes/auth.php,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -r1.26 -r1.27 *** auth.php 5 Dec 2002 00:33:42 -0000 1.26 --- auth.php 4 Feb 2003 02:34:35 -0000 1.27 *************** *** 1,62 **** ! <? ! ! class Auth // Authenticates user. Only included if user auth is set to be used. ! { ! ! var $curr_user; ! var $SESSID; ! ! function Auth() ! { ! ! global $DB; ! ! // Session ID is contained in the URL. ! if( isset( $_GET['SESSID'] ) ! { ! define("C_SESSID_LOC", 1); ! ! $session_id = $_GET['SESSID']; ! ! } ! // We're using the cookie set by the previous session. ! elseif( isset( $_COOKIE[C_COOKIE_NAME] ) ! { ! ! define("C_SESSID_LOC", 2); ! ! $session_id = $_COOKIE[C_COOKIE_NAME]; ! ! } ! ! $sql = "SELECT * FROM " . C_SESSIONS_TABLE . " WHERE sessid=" . $session_id . " AND expiry<" . time(); ! $result = $DB->query($sql); ! ! $numrows = $DB->numRows($result); ! ! if($numrows >= 1) ! { ! ! $sess_data = $DB->fetchArray($result); ! ! } ! else // The session doesn't exist or has expired. ! { ! ! die("Your session has expired."); ! ! } ! ! if( C_SESSID_LOC == 2 ) // We need to set up the cookie. ! { ! ! ! // Set up cookie/url procedures and such. ! ! } ! ! } ! ! } ! ! ?> \ No newline at end of file --- 1 ---- ! <? class Auth // Authenticates user. Only included if user auth is set to be used. { var $curr_user; var $SESSID; function Auth() { global $DB; // Session ID is contained in the URL. if( isset( $_GET['SESSID'] ) ) { define("C_SESSID_LOC", 1); $session_id = $_GET['SESSID']; } // We're using the cookie set by the previous session. elseif( isset( $_COOKIE[C_COOKIE_NAME] ) ) { define("C_SESSID_LOC", 2); $session_id = $_COOKIE[C_COOKIE_NAME]; } $sql = "SELECT * FROM " . C_SESSIONS_TABLE . " WHERE sessid=" . $session_id . " AND expiry<" . time(); $result = $DB->query($sql); $numrows = $DB->numRows($result); if($numrows >= 1) { $sess_data = $DB->fetchArray($result); } else // The session doesn't exist or has expired. { die("Your session has expired."); } if( C_SESSID_LOC == 2 ) // We need to set up the cookie. { // Set up cookie/url procedures and such. } } } ?> \ No newline at end of file Index: user.php =================================================================== RCS file: /cvsroot/phpmp/phpMP/includes/user.php,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -r1.9 -r1.10 *** user.php 31 Jan 2003 07:01:05 -0000 1.9 --- user.php 4 Feb 2003 02:34:35 -0000 1.10 *************** *** 1,95 **** ! <? ! ! class User // Creates a barrier between the Auth class and the outside world. ! // If user doesn't need to be auth'ed, he isn't. ! { ! ! // Fetches user information/variables from the database. ! // Author: Brian 'Heimidal' Rose ! // Accepts: $user (integer). ! // Returns: boolean. ! function _snapshot( $user ) ! { ! ! global $DB; ! ! $sql = "SELECT * FROM " . C_USERS_TABLE . " WHERE userid=" . $DB->escapeString($user) . "; ! ! $qry = $DB->query($sql); ! ! if( $DB->numRows( $qry ) < 1 ) { ! ! return false; ! ! } ! else { ! $user_array = $DB->fetchArray($qry); ! ! while( list ($key, $val) = each ($user_array) ) ! { ! if( $val != '' ) ! { ! define( "U_" . strtoupper($key), $val ); ! } ! } ! ! return true; ! } ! } ! ! // Session cleanup routine. ! // Author: Brian 'Heimidal' Rose ! // Accepts: none. ! // Returns: none. ! function sessionClean() ! { ! ! global $DB; ! ! $rand = rand(0,10); ! if($rand >= 1) // 1:10 chance of session cleanup. This may later become a setting. ! { ! ! $sql = "DELETE FROM " . C_SESSIONS_TABLE . " WHERE expiry<" . time(); ! $DB->query($sql); ! ! } ! ! } ! ! // User initialization function. Does -EVERYTHING- except explicit session cleanup. ! // Author: Brian 'Heimidal' Rose ! // Accepts: none. ! // Returns: none. ! function User() ! { ! ! $this->sessionClean(); ! ! // Must decide is this is an anonymous user or a registered user. ! ! if( ( C_USE_PERMS == 1 ) || ( P_ADMIN_REQ ) ) // Checks for use_perms setting and makes sure we're not entering the admin area. ! { ! ! // We want to use authentication. ! ! global $Auth; ! ! include_once( C_PHPMP_ROOT . 'includes/auth.php' ); ! $Auth = new Auth(); // Initializes Auth, which also authenticates the user. ! ! $this->_snapshot( $Auth->curr_user ); // Gets snapshot of user info/vars. ! ! } ! else // We're not going to bother auth'ing the user. ! { ! ! $this->_snapshot('1'); // Gets snapshot of anon user info/vars. ! ! } ! ! } ! ! } ! ! ?> --- 1 ---- ! <?php class User // Creates a barrier between the Auth class and the outside world. // If user doesn't need to be auth'ed, he isn't. { // Fetches user information/variables from the database. // Author: Brian 'Heimidal' Rose // Accepts: $user (integer). // Returns: boolean. function _snapshot( $user ) { global $DB; $sql = "SELECT * FROM " . C_USERS_TABLE . " WHERE userid=" . $DB->escapeString($user); $qry = $DB->query($sql); if( $DB->numRows( $qry ) < 1 ) { return false; } else { $user_array = $DB->fetchArray($qry); while( list ($key, $val) = each ($user_array) ) { define( "U_" . strtoupper($key), "$val" ); } return true; } } // Session cleanup routine. // Author: Brian 'Heimidal' Rose // Accepts: none. // Returns: none. function sessionClean() { global $DB; $rand = rand(0,10); if($rand >= 1) // 1:10 chance of session cleanup. This may later become a setting. { $sql = "DELETE FROM " . C_SESSIONS_TABLE . " WHERE expiry<" . time(); $DB->query($sql); } } // User initialization function. Does -EVERYTHING- except explicit session cleanup. // Author: Brian 'Heimidal' Rose // Accepts: none. // Returns: none. function User() { $this->sessionClean(); // Must decide is this is an anonymous user or a registered user. if( ( C_USE_PERMS == 1 ) || ( defined( P_ADMIN_REQ ) ) ) // Checks for use_perms setting and makes sure we're not entering the admin area. { // We want to use authentication. global $Auth; include_once( C_PHPMP_ROOT . 'includes/auth.php' ); $Auth = new Auth(); // Initializes Auth, which also authenticates the user. $this->_snapshot( $Auth->curr_user ); // Gets snapshot of user info/vars. } else // We're not going to bother auth'ing the user. { $this->_snapshot('1'); // Gets snapshot of anon user info/vars. } } } ?> \ No newline at end of file |