/////////////////////////////////////////////////////////////////////////////
//
// login.php
//
// This page has functions for account retrieval, user login and user
// initialisation which occurs on the first login.
//
///////////////////////////////////////////////////////////////////////////////
require("common.inc.php");
connect_db();
// Login and authentication script
// Switch on the Action from the previous form. If we have been in login.php
// before then Action will be either Log In or Retrieve Password. If we
// have arrived here from another page then the default is to show the
// login fields.
switch ($_POST['Action'])
{
case "Log In":
userLogin($_POST['Email'], $_POST['Password']);
exit;
case "Retrieve Password":
retrievePasswd($_POST['Email']);
exit;
default:
// Default Action
showLoginForm();
exit;
}
////////////////////////////////////////////////////////////////////////////////
//
// function showLoginForm
// Displays the initial form prompting the user for their email address and pword
//
////////////////////////////////////////////////////////////////////////////////
function showLoginForm()
{
//Logs the user out to prevent any dodgy business.
logout_user();
$output = "This area allows you to update your alumni information. ";
$output .= "You can also change your password or delete your entry. ";
$output .= "Please log in with your email address and password.
\n ";
$output .= "If you have lost your password, type the email address ".
"you log in with and click \"Retrieve Password\". ";
// This form will re-call the login page
$this_script = $_SERVER['PHP_SELF'];
$output .= "
\n";
showpage ("Log in", $output);
}
////////////////////////////////////////////////////////////////////////////////
//
// function userLogin
//
//
////////////////////////////////////////////////////////////////////////////////
function userLogin($PriEmail, $Password)
{
//Logs the user out to prevent any dodgy business.
logout_user();
// use addslashes() to prevent any nasty surprises or dodgy things.
$PriEmail = addslashes($PriEmail);
$Password = addslashes($Password);
// $LastLoginIP and $LastLoginTime are Call By reference values
// they will be updated to become the last login time.
$LoginOK = login_user(
$PriEmail, // in
$Password, // in
$LastLoginIP, // output (call by reference)
$LastLoginTime, // output
$Pending); // output
// Parse the timestamp so it's legible
$LastLoginTime = parseTimeStamp($LastLoginTime);
// Retrieve the StudentID - it is needed in a minute
$SID = getSID($PriEmail);
if ($LoginOK)
{
if ($Pending == "Y")
{
// If this is the first login, treat as an account activation and
// guide the user through the steps.
$output .= "Welcome! I see that this is your first time using the FPA Registry!
\n";
$output .= "To proceed, you must fill in the information you want to be ".
"placed in the registry.
\n" ;
$output .= "You will be guided through a 3-step process of inputting your ".
"personal information, contact information, ".
"and you will also be asked to input a secondary email address. You ".
"must complete all the steps before ".
"your record will be displayed on the Registry.
\n";
$output .= "
\n";
}
else
{
// Formulate output
$pgTitle = "Login Successful";
$output = "\n";
$output .= "Login Successful.
\n";
$output .= "Last Logged in at $LastLoginTime from ".
"$LastLoginIP
\n";
$output .= "If your browser doesn't redirect you automatically, ";
$output .= "click here.";
}
}
else
{
$pgTitle = "Error";
$output = "Login Failed. Please press the Back button on your ".
"browser and try again.
\n";
if (!$PriEmail) { $output .= "Email address must be provided.
\n";}
if (!$Password) { $output .= "Password must be provided.
\n";}
}
showpage ($pgTitle, $output);
}
////////////////////////////////////////////////////////////////////////////////
//
// function retrievePasswd
//
//
////////////////////////////////////////////////////////////////////////////////
function retrievePasswd($Email)
{
// Find out what the SID is
$SID = getSID($Email);
// Get the password hint
$sql = "SELECT * FROM tblAccess ";
$sql .= "WHERE SID = '$SID' ";
$sql .= "LIMIT 1 ";
$result_set = mysql_query($sql)
or die(showpage("Error", "Query failed: " . mysql_error()));
if (mysql_num_rows($result_set) == 0)
{
// If no results found, show this.
$output .= "Sorry, no record found for that email address. \n";
}
else
{
$results = mysql_fetch_array($result_set);
$output .= "Note that your password will not be recovered to your ".
"old one. It will be changed to a new password, ";
$output .= "and you will be informed of the new password on screen ".
"(if you answer the question) ";
$output .= "or via email to your primary or secondary email account.
\n";
$output .= "\n";
}
showpage ("Retrieve Lost Password", $output);
}
?>