File: //home/awaldron/public_html/archive/ressyn/sign-in.php
<?php
$login_ok = false;
$login_att = false;
// Check if 'required' flag is set
$forced = (!empty($arg[2]));
if (!$forced) unset($_SESSION[force_referrer]);
// If user is already logged in,
// send them back to the home page.
if ($u->is_logged()) header("Location: ".BASE_URL);
// Attempt login if variables are set.
if (!$u->is_logged() && isset($_POST[username]) && isset($_POST[password])) {
// Setup form validation requirements
$valid[0] = array('username', 'Email Address', 'email', TRUE);
$valid[1] = array('password', 'Password', 'none', TRUE);
// Run Validation Function
$errors = form_validate($_POST, $valid, "525px");
if (isset($_POST[username]) && isset($_POST[password]) && !$errors) {
$login_att = true;
$login_ok = $u->login($_POST[username],$_POST[password],$_POST[cookie]);
} else {
$write_errors = TRUE;
}
}
// Login successful
if ($login_att && $login_ok) {
$pwchange = $db->quickSQL("SELECT user_pwchange FROM user WHERE uid=".$u->get_uid());
//$last_update = $db->quickSQL("SELECT user_last_update FROM user WHERE uid=".$u->get_uid());
// Redirect user to the proper location
if ($pwchange == 1) header("Location: /account/password/change");
else if (isset($_SESSION[force_referrer])) header("Location: ".$_SESSION[force_referrer]);
else header("Location: /account");
// Login failed, write useful error message.
} else if ($login_att && !$login_ok) {
// Find the problem with the login (username or password wrong, or account not activated)
// It's just mean to just say (Bad Login/Password)
$errors = '<div class="errors" style="width:525px;margin:0 auto;">Your login was not successful due to the following errors:<ul>'.EOL;
$email_ok = $db->quickSQL("SELECT COUNT(user_email) FROM user WHERE user_email='".$_POST[username]."'");
$regkey = $db->quickSQL("SELECT user_regkey FROM user WHERE user_email='".$_POST[username]."'");
if (!$email_ok) {
$errors .= '<li> The email address specified does not exist in our database.</li>';
$email_ok = FALSE;
} else if ($regkey != '0') {
$errors .= '<li> This account you are trying to access has not yet been activated.</li>';
$errors .= '<li> Please check your email for a message containing your activation link.</li>';
$errors .= '<li> This message may have been blocked by your SPAM filter. <a href="mailto:'.ADMIN_EMAIL.'">If so, please contact the administrator.</a></li>';
$email_ok = TRUE;
} else {
$errors .= '<li> The password you entered is incorrect.</li>';
$email_ok = TRUE;
}
$errors .= '</div>'.EOL;
}
include("_header.php");
echo '<div class="sp-content">'.EOL;
$msg = "";
//if (!$login_ok && $login_att) $msg = error("Invalid username/password.");
echo (!empty($errors)?$errors:'').EOL;
if ($forced) {
echo '<div class="warning" style="width:525px;margin:0 auto;">Authentication Required<ul><li>The page you are trying to access requires you to sign in.</li><li>Please enter your email address and password to continue.</li></ul></div><br/>'.EOL;
}
echo '<form action="sign-in" method="post">'.EOL;
echo '<div><input type="hidden" name="refer" value="'.(isset($_REQUEST[refer])?$_REQUEST[refer]:(isset($_SESSION[force_referrer])?$_SESSION[force_referrer]:BASE_URL)).'" /></div>'.EOL;
echo '<div><input type="hidden" name="force" value="'.($force?1:0).'" /></div>'.EOL;
echo '<br/>'.EOL;
echo '<fieldset title="Sign In" id="login-form"><legend> Sign In to Ressyn </legend>'.EOL;
echo '<div class="form-row">';
echo '<label for="username">Email Address:</label> ';
echo '<input type="text" name="username" style="width:150px" maxlength="32" class="login" '.($email_ok===FALSE?'':'value="'.$_POST[username].'" ').'/>';
echo '</div>'.EOL;
echo '<div class="form-row">';
echo '<label for="password">Password:</label> ';
echo '<input type="password" name="password" style="width:150px" maxlength="32" class="login" '.($email_ok===FALSE?'':'value="'.$_POST[username].'" ').'/>';
echo '</div>'.EOL;
echo '<div class="form-row" style="margin:15px 0;">';
echo '<input type="checkbox" value="yes" name="cookie" /> Keep me signed in on this computer.';
echo '</div>'.EOL;
echo '<div class="form-row">';
echo '<input type="submit" name="login" value="Sign In" class="submit" /> ';
echo '<input type="button" onclick="window.location.href=\'/home\';" value="Cancel" class="submit" />';
echo '</div>'.EOL;
echo '<div class="form-row" style="margin-top:25px;">';
echo '<p><a href="/account/password/forget">Forget your password? Click here to reset it.</a></p>'.EOL;
echo '<p><a href="/account/register">Not a member? Click here to register.</a></p>'.EOL;
echo '</div>'.EOL;
echo '</fieldset>'.EOL;
echo '</form>'.EOL;
echo '</div>'.EOL;
include("_footer.php");
?>