Location: PHPKode > projects > Mummi (Multi-user MOD_MP3 Interface) > mummi.0.6/htroot/forgotpass.php
<?

//  This get the document root specified in the virtual host of apache
$GLOBALS[int_path] = getenv(DOCUMENT_ROOT);

// This will be changed to look at a file that the user can set the prefrence of.
$GLOBALS[lib_path] = "$GLOBALS[int_path]/../lib";

include "$GLOBALS[lib_path]/config.inc";
include "$GLOBALS[lib_path]/mysql.inc";
include "$GLOBALS[lib_path]/overseer.inc";
include "$GLOBALS[lib_path]/user_db.inc";
include "$GLOBALS[lib_path]/design.inc";

// Setting the page title
$GLOBALS[page_title] = "Password Retrieval";

$os = new OVERSEER;
$os->connect("$GLOBALS[dbhost]","$GLOBALS[dbusername]","$GLOBALS[dbuserpassword]","$GLOBALS[dbname]");

$user_db = new USER_DB();
$user_db->connect("$GLOBALS[dbhost]","$GLOBALS[dbusername]","$GLOBALS[dbuserpassword]","$GLOBALS[dbname]");


$session_array = $os->decipher($HTTP_COOKIE_VARS[login_active], $GLOBALS[secret_key]);





// Set the user navbars.
if(!$HTTP_COOKIE_VARS[login_active]) $nav_array = array(main);
elseif($os->num_rows("SELECT user_name FROM users WHERE user_name='$session_array[user_name]' AND user_type='1'")) $nav_array = array_merge($GLOBALS[admin_navbox_array], $os->get_navbox_array($session_array[user_name]));
else $nav_array = array_merge($GLOBALS[basic_navbox_array], $os->get_navbox_array($session_array[user_name]));


// Setting the default page contents
$GLOBALS[contents00] = <<<ENDcontents00
	<font size="$GLOBALS[body_font_size]">
	<table width="100%" cellpadding="1" cellspacing="1" border="0"><tr>
	<td>
		Forgot your password?? No problem!!  Just fill in your email address and we will mail you a new password.
		Make sure you change your password once you log back in to keep your account secure.<br>
		<form action="$PHP_SELF" method="post">
			<table cellpadding="1" cellspacing="1" border="0"><tr>
				<td align="left" valign="top">
					Email Address:<br>
					<input type="text" name="user_email" value="" size="40" maxsize="15">
				</td><td align="left" valign="bottom">
					&nbsp;<input type="submit" name="forgotdt00" value="Submit">
				</td>
			</tr></table>
		</form>

	</td>
	</tr></table>
	</font>
ENDcontents00;


// Email field is empty
$GLOBALS[contents01] = <<<ENDcontents01
	<table width="100%" cellpadding="1" cellspacing="1" border="0"><tr>
	<td>
		<font color="red"><b>Required Field Missing</b></font><br>
		The email field was left blank.  Please enter you email address and click submit.<br>

		<form action="$PHP_SELF" method="post">
			<table cellpadding="1" cellspacing="1" border="0"><tr>
				<td align="left" valign="top">
					Email Address:<br>
					<input type="text" name="user_email" value="" size="40" maxsize="15">
				</td><td align="left" valign="bottom">
					&nbsp;<input type="submit" name="forgotdt00" value="Submit">
				</td>
			</tr></table>
		</form>

	</td>
	</tr></table>

ENDcontents01;


// Email Address supplied is an invalid email addy hide@address.com
$GLOBALS[contents02] = <<<ENDcontents02
	<table width="100%" cellpadding="1" cellspacing="1" border="0"><tr>
	<td>
		<font color="red"><b>Invalid Email Address</b></font><br>
		The email address you gave is not in the correct format..  Proper format is <i>hide@address.com</i>.<br>

		<form action="$PHP_SELF" method="post">
			<table cellpadding="1" cellspacing="1" border="0"><tr>
				<td align="left" valign="top">
					Email Address:<br>
					<input type="text" name="user_email" value="" size="40" maxsize="15">
				</td><td align="left" valign="bottom">
					&nbsp;<input type="submit" name="forgotdt00" value="Submit">
				</td>
			</tr></table>
		</form>

	</td>
	</tr></table>

ENDcontents02;


// Email Address supplied is not in the database
$GLOBALS[contents03] = <<<ENDcontents03
	<table width="100%" cellpadding="1" cellspacing="1" border="0"><tr>
	<td>
		<font color="red"><b>Invalid Email Address</b></font><br>
		The email address you gave is not in the batabase.  Please enter another email address and try again.<br>

		<form action="$PHP_SELF" method="post">
			<table cellpadding="1" cellspacing="1" border="0"><tr>
				<td align="left" valign="top">
					Email Address:<br>
					<input type="text" name="user_email" value="" size="40" maxsize="15">
				</td><td align="left" valign="bottom">
					&nbsp;<input type="submit" name="forgotdt00" value="Submit">
				</td>
			</tr></table>
		</form>
		username: $GLOBALS[user_name]
	</td>
	</tr></table>

ENDcontents03;


// Problem updating the password in the database
$GLOBALS[contents04] = <<<ENDcontents04
	<table width="100%" cellpadding="1" cellspacing="1" border="0"><tr>
	<td>
		<font color="red"><b>Problems updating password</b></font><br>
		There was a problem updaing your password. Please try again later.<br>

		<form action="$PHP_SELF" method="post">
			<table cellpadding="1" cellspacing="1" border="0"><tr>
				<td align="left" valign="top">
					Email Address:<br>
					<input type="text" name="user_email" value="" size="40" maxsize="15">
				</td><td align="left" valign="bottom">
					&nbsp;<input type="submit" name="forgotdt00" value="Submit">
				</td>
			</tr></table>
		</form>

	</td>
	</tr></table>

ENDcontents04;


// Final allgood page
$GLOBALS[contents05] = <<<ENDcontents05
	<table width="100%" cellpadding="1" cellspacing="1" border="0"><tr>
	<td>
		A new passord for your account has been sent to <b>$HTTP_POST_VARS[user_email]</b>.  Thank you.<br>

	</td>
	</tr></table>

ENDcontents05;

// Start the processing
if($HTTP_POST_VARS[forgotdt00]){

	// Check to see if the password fields are empty
	if(empty($HTTP_POST_VARS[user_email])) $contents = array("$GLOBALS[page_title]"=>"$GLOBALS[contents01]");


	// if the email is already taken by somebody else.
	elseif(!$user_db->chk_email($HTTP_POST_VARS[user_email])) $contents = array("$GLOBALS[page_title]"=>"$GLOBALS[contents02]");

	// Check to see if the email is valid and get the username
	elseif(!$GLOBALS[user_name] = $user_db->get_user_name_from_email($HTTP_POST_VARS[user_email])) $contents = array("$GLOBALS[page_title]"=>"$GLOBALS[contents03]");

	// else it all worked.. change the password in the database
	else{
			$GLOBALS[new_pass] = $user_db->pass_gen(8);


// The email text sent to the new user.
$email_str = <<<ENDemail_str

THIS IS AN AUTOMATED EMAIL SYSTEM.
PLEASE DO NOT REPLY TO THIS EMAIL.

Your being sent this email because you, or someone else, said they forgot their password that is associated with this
email address at $GLOBALS[url_path].  If you have not done so, then please disregard this email, and sorry to inconvienence you.

You can login at $GLOBALS[url_path]/login.php to enter your account with the following informaion.
	Username: $GLOBALS[user_name]
	     Key: $GLOBALS[new_pass]


ENDemail_str;

		// Making the password an md5 password
		$GLOBALS[new_pass] = md5($GLOBALS[new_pass]);

		// the new user class has the tmp_user function
		if(!$user_db->update_user_pass($user_name, $GLOBALS[new_pass])) $contents = array("$GLOBALS[page_title]"=>"$GLOBALS[contents04]");
		else mail("$HTTP_POST_VARS[user_email]",
			"AudioDevil member signup.",
			"$email_str",
			"From:hide@address.com\nX-Mailer:apache");

		$contents = array("$GLOBALS[page_title]"=>"$GLOBALS[contents05]");
		$GLOBALS[new_pass] = NULL;




	}

}else{
	// This is the first page that the user will see
	$contents = array("$GLOBALS[page_title]"=>"$GLOBALS[contents00]");
}




// an array for the draw_page function.
//$page_table = array("$GLOBALS[page_title]"=>"$GLOBALS[contents00]");





draw_header("$GLOBALS[page_title]");
draw_nav($nav_array);
draw_sect($contents);
draw_footer();
ob_end_flush();
?>
Return current item: Mummi (Multi-user MOD_MP3 Interface)