<?
include('../Code/confHeader.inc');
$Conf -> connect();
//
// In all cases, we need to look up the account information
// to determine if they user is registered
//

if ( IsSet($loginEmail) ) {
  $Me -> lookupByEmail($loginEmail, $Conf);
  if ( !IsSet($forgot) && IsSet($password)
       && $Me -> valid()
       && $Me -> password == $password) {
    $Me -> go("../index.php");
    exit;
  }
} else {
  $Me -> invalidate();
}
?>

<html>

<? $Conf->header("Account Authentication") ?>

<body>

<?
if ( IsSet($forgot) ) {
  if (! $Me -> valid() ) {
    $Conf->errorMsg(
		 "We did not locate an existing account for $loginEmail. "
		 . "Click <a href=\"login.php\"> here </a> to return to the "
		 . " login page to try again. "
		 );

  } else { 
    $Me -> sendAccountInfo($Conf);
    $Conf->confirmMsg(
		 "The account information for $loginEmail has been retrieved and "
		 . "sent <it> via </it> email. You can use that information to login. "
		 . "Click <a href=\"login.php\"> here </a> to return to the login page. "
		 );
    $Me -> invalidate();

  }
} else {
  //
  // Check the password
  //
  if ($Me -> password != $password) {
    $Me -> invalidate();
  }

  if ( ! $Me -> valid()) {
    $Conf->errorMsg(
		 "That password is not correct. "
		 . "-or- That email address ($loginEmail) is not registered. "
		 . "Please <a href=\"login.php\"> return to the login form </a> and "
		 . "either enter a valid email address or register an account."
		 );
  } else {
    $Conf->confirmMsg(
		      "Welcome " . $Me->fullname() . " "
		      . "you've successfully logged in.");
    
    print "<center>";
    $Conf->textButton("Go to Conference Submission And Review Index", "../index.php");
    print "</center>";
    //
    // Update their visit counts
    //
    $Me -> bumpVisits($Conf);
    //
    // Check their roles
    //
    $Me -> updateContactRoleInfo($Conf);

    $Conf->log("Login", $Me);
  }
}
?>

<? $Conf->footer() ?>

</body>
</html>
