Location: PHPKode > projects > Write2Left > Base/Login.php
<?php
/*
+------------------------------------------------------
| Write2Left
| (c) timdorr
| http://www.write2left.com
| hide@address.com
| See License.txt for license info
|------------------------------------------------------
| Script: Login.php
| Description:
|   Handles the login of a user and the login page.
| Created Jun-28-03
+------------------------------------------------------
*/

/* Class: Login
 * Description:
 *   Driver for logins
 */
class Login
{
	var $skin = "";
	var $menu = false;
	
	function run()
	{
	    global $W2L, $userinfo;

        // Do some skin stuff
		require( "./Skin/Login.php" );
		$this->skin = new Skin_Login();

        // Are we attempting a login?
		if ( array_key_exists( 'login_user', $W2L->input ) )
		{
			$this->check_user( $W2L->input['login_user'], $W2L->input['login_pass'] );
		}
		// If not, show the login screen
		else
		{
		    $this->display_login();
		}
	}

	//================
	// Shows our login box as it is skinned.
	//================
	function display_login( $error = "")
	{
	    global $output;

		$output->page_title = "Login";
		$output->loc_add( "Login" );
		
		// Display an error if neccessary
		if ( $error != "" )
		{
			$output->add( $this->skin->display_login_error( $error ) );
		}
		else
		{
			$output->add( $this->skin->display_login() );
		}
	}
	

	//================
	// Checks our login info and logs in if correct.
	//================
	function check_user( $login_name, $login_pass )
	{
		global $W2L, $db, $userinfo;
        
        // Check if the data is kosher
		$validate_result = $db->query( "SELECT * FROM w2l_users WHERE name='$login_name' AND pass=MD5('$login_pass')" );

        // If so, do the login goodies :)
		if ( $db->num_rows( $validate_result ) == 1 ) 
		{
		    // Get the data we found and update the session
			$user_data = $db->fetch_array( $validate_result );
			$perms = array( 'can_login' 	=> $user_data['can_login'],
							'can_logs' 		=> $user_data['can_logs'],
							'can_users' 	=> $user_data['can_users'],
							'can_options' 	=> $user_data['can_options'],
							'can_install' 	=> $user_data['can_install'],
							'can_import' 	=> $user_data['can_import'] );
							
			// Check if they can actually log in
			if( $perms['can_login'] != 1 )
			{
				$this->display_login( "Your account has been locked. Please contact the system administrator." );
			}
			else	
			{
				$userinfo->convert_guest_session( $user_data['name'], $user_data['user_id'], $user_data['pass'], $user_data['email'], $perms );
				
				// Redirect back to Funtown, USA
				header( "Location: index.php" );
				exit;
			}
		}
		else
		{
			$this->display_login( "Your username/password is incorrect. Please try again!" );
		}
	}
}

$driver = new Login();
?>
Return current item: Write2Left