Thread: [phpMP-CVS] CVS: phpMP/includes auth.php,1.28,1.29 constants.php,1.14,1.15 core.php,1.41,1.42 user.p
Status: Pre-Alpha
Brought to you by:
heimidal
From: Brian R. <hei...@us...> - 2003-02-06 01:46:53
|
Update of /cvsroot/phpmp/phpMP/includes In directory sc8-pr-cvs1:/tmp/cvs-serv24805/includes Modified Files: auth.php constants.php core.php user.php Log Message: Fixed an error in constants.php. Changed DB table constants back to DB_ prefix (no longer C_). Index: auth.php =================================================================== RCS file: /cvsroot/phpmp/phpMP/includes/auth.php,v retrieving revision 1.28 retrieving revision 1.29 diff -C2 -r1.28 -r1.29 *** auth.php 4 Feb 2003 21:43:19 -0000 1.28 --- auth.php 6 Feb 2003 01:46:50 -0000 1.29 *************** *** 1 **** ! <?php 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,62 ---- ! <?php ! ! 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 " . DB_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: constants.php =================================================================== RCS file: /cvsroot/phpmp/phpMP/includes/constants.php,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -r1.14 -r1.15 *** constants.php 4 Feb 2003 21:43:19 -0000 1.14 --- constants.php 6 Feb 2003 01:46:50 -0000 1.15 *************** *** 1 **** ! <?php define("C_DATE_NOW", date( C_DEFAULT_DATE_FORMAT ) ); define("ACTIVATE_DISABLED", 0); define("ACTIVATE_USER", 1); define("ACTIVATE_ADMIN", 2); define("AUTH_LVL_GUEST", 0); // Guest. define("AUTH_LVL_MEM", 1); // Standard Member define("AUTH_LVL_CONTRIB", 2); // Contributor define("AUTH_LVL_MOD", 3); // Moderator define("AUTH_LVL_ADMIN", 4); // Administrator ?> \ No newline at end of file --- 1,15 ---- ! <?php ! ! define("C_DATE_NOW", date( U_DATE_FORMAT ) ); ! ! define("ACTIVATE_DISABLED", 0); ! define("ACTIVATE_USER", 1); ! define("ACTIVATE_ADMIN", 2); ! ! define("AUTH_LVL_GUEST", 0); // Guest. ! define("AUTH_LVL_MEM", 1); // Standard Member ! define("AUTH_LVL_CONTRIB", 2); // Contributor ! define("AUTH_LVL_MOD", 3); // Moderator ! define("AUTH_LVL_ADMIN", 4); // Administrator ! ! ?> \ No newline at end of file Index: core.php =================================================================== RCS file: /cvsroot/phpmp/phpMP/includes/core.php,v retrieving revision 1.41 retrieving revision 1.42 diff -C2 -r1.41 -r1.42 *** core.php 4 Feb 2003 21:43:20 -0000 1.41 --- core.php 6 Feb 2003 01:46:50 -0000 1.42 *************** *** 1 **** ! <?php class Core // Does, literally, everything. { // Initiates configuration from database. // Author: Brian 'Heimidal' Rose // Accepts: none. // Returns: none. function _initConfig () { define("C_CONFIG_TABLE", DB_NAME . '.' . DB_TABLE_PREFIX . 'config'); define("C_USERS_TABLE", DB_NAME . '.' . DB_TABLE_PREFIX . 'users'); define("C_SESSIONS_TABLE", DB_NAME . '.' . DB_TABLE_PREFIX . 'sessions'); define("C_MODULES_TABLE", DB_NAME . '.' . DB_TABLE_PREFIX . 'modules'); define("C_BLOCK_TABLE", DB_NAME . '.' . DB_TABLE_PREFIX . 'blocks'); global $DB; $result = $DB->query( "SELECT * FROM " . C_CONFIG_TABLE ); // Loop through all config values from DB. // Define each key as its respective value. while( $row = $DB->fetchArray( $result ) ) { define( strtoupper( 'C_' . $row['config_key'] ), $row['config_value'] ); } } // Initiates all core components. // Author: Brian 'Heimidal' Rose // Accepts: $optional_files (string of needed files separated by commas). // Returns: none. function init ( $optional_files = array() ) { include_once( C_PHPMP_ROOT . 'config.php' ); include_once( C_PHPMP_ROOT . 'includes/debug.php' ); $Debug = new Debug(); global $DB; include_once( C_PHPMP_ROOT . 'dba/' . DB_TYPE . '.dba' ); $DB = new DB(); $DB->connect(); $this->_initConfig(); // Grab DB-stored config values. include_once(C_PHPMP_ROOT . 'includes/functions.php'); include_once(C_PHPMP_ROOT . 'includes/user.php'); $User = new User(); // Create an instance of User. include_once(C_PHPMP_ROOT . 'includes/language.php'); $Language = new Language(); createConstants(); include_once(C_PHPMP_ROOT . 'includes/constants.php'); include_once(C_PHPMP_ROOT . 'includes/mpcode.php'); // This while() statement will loop through the // $optional_files and include each file. $i = 0; while( $my_file = $optional_files[$i] ) { include_once(C_PHPMP_ROOT . 'includes/' . $my_file . '.php'); $i++; } include_once(C_PHPMP_ROOT . 'includes/Smarty.class.php'); include_once(C_PHPMP_ROOT . 'includes/template.php'); $Template = new Template(); // Create an instance of Template. // Globalize all major class-containing variables. global $Debug, $User, $MPCode, $Template; } } ?> \ No newline at end of file --- 1,86 ---- ! <?php ! ! class Core // Does, literally, everything. ! { ! ! // Initiates configuration from database. ! // Author: Brian 'Heimidal' Rose ! // Accepts: none. ! // Returns: none. ! function _initConfig () ! { ! ! define("DB_CONFIG_TABLE", DB_NAME . '.' . DB_TABLE_PREFIX . 'config'); ! define("DB_USERS_TABLE", DB_NAME . '.' . DB_TABLE_PREFIX . 'users'); ! define("DB_SESSIONS_TABLE", DB_NAME . '.' . DB_TABLE_PREFIX . 'sessions'); ! define("DB_MODULES_TABLE", DB_NAME . '.' . DB_TABLE_PREFIX . 'modules'); ! define("DB_BLOCK_TABLE", DB_NAME . '.' . DB_TABLE_PREFIX . 'blocks'); ! ! global $DB; ! ! $result = $DB->query( "SELECT * FROM " . DB_CONFIG_TABLE ); ! ! // Loop through all config values from DB. ! // Define each key as its respective value. ! while( $row = $DB->fetchArray( $result ) ) ! { ! define( strtoupper( 'C_' . $row['config_key'] ), $row['config_value'] ); ! } ! ! } ! ! // Initiates all core components. ! // Author: Brian 'Heimidal' Rose ! // Accepts: $optional_files (string of needed files separated by commas). ! // Returns: none. ! function init ( $optional_files = array() ) ! { ! include_once( C_PHPMP_ROOT . 'config.php' ); ! ! include_once( C_PHPMP_ROOT . 'includes/debug.php' ); ! $Debug = new Debug(); ! ! global $DB; ! ! include_once( C_PHPMP_ROOT . 'dba/' . DB_TYPE . '.dba' ); ! $DB = new DB(); ! $DB->connect(); ! ! $this->_initConfig(); // Grab DB-stored config values. ! ! include_once(C_PHPMP_ROOT . 'includes/functions.php'); ! ! include_once(C_PHPMP_ROOT . 'includes/user.php'); ! $User = new User(); // Create an instance of User. ! ! include_once(C_PHPMP_ROOT . 'includes/language.php'); ! $Language = new Language(); ! ! createConstants(); ! include_once(C_PHPMP_ROOT . 'includes/constants.php'); ! ! include_once(C_PHPMP_ROOT . 'includes/mpcode.php'); ! ! // This while() statement will loop through the ! // $optional_files and include each file. ! $i = 0; ! while( $my_file = $optional_files[$i] ) ! { ! ! include_once(C_PHPMP_ROOT . 'includes/' . $my_file . '.php'); ! $i++; ! ! } ! ! include_once(C_PHPMP_ROOT . 'includes/Smarty.class.php'); ! include_once(C_PHPMP_ROOT . 'includes/template.php'); ! $Template = new Template(); // Create an instance of Template. ! ! // Globalize all major class-containing variables. ! global $Debug, $User, $MPCode, $Template; ! ! } ! ! } ! ! ?> \ No newline at end of file Index: user.php =================================================================== RCS file: /cvsroot/phpmp/phpMP/includes/user.php,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -r1.11 -r1.12 *** user.php 4 Feb 2003 21:43:28 -0000 1.11 --- user.php 6 Feb 2003 01:46:50 -0000 1.12 *************** *** 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_PORTAL_PERMS == 1 ) || ( defined( P_USE_ADMIN_PERMS ) ) ) // 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 --- 1,92 ---- ! <?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 " . DB_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 " . DB_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_PORTAL_PERMS == 1 ) || ( defined( P_USE_ADMIN_PERMS ) ) ) // 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 |