//------------------------------------------------
// Includes
//------------------------------------------------
include SYS_PATH . 'includes/languages/' . SYS_LANG . '/lang.lib.account_lostpass.php';
include SYS_PATH . 'includes/core/core.email.php';
include SYS_PATH . 'includes/fns/fns.validate.php';
//------------------------------------------------
// Check if the user is logged in
//------------------------------------------------
if ($SESSION->auth)
redirect(VIR_PATH);
//------------------------------------------------
// Resend hash
//------------------------------------------------
show_resendhash();
//------------------------------------------------
// Resend hash
//------------------------------------------------
function show_resendhash()
{
global $DB, $LANG, $TEMPLATE, $SESSION, $PREFS;
//------------------------------------------------
// Set template file
//------------------------------------------------
$TEMPLATE->set_template("account_sendhash.tpl");
//------------------------------------------------
// Assign page title
//------------------------------------------------
$TEMPLATE->assign('app_page', ($LANG['forgotpassword']['app_resendhash']));
//------------------------------------------------
// Set default values
//------------------------------------------------
$username = isset($_POST['username']) && $_POST['username'] ? $DB->strip_slashes(trim($_POST['username'])) : "";
$email = isset($_POST['email']) && $_POST['email'] ? $DB->strip_slashes(trim($_POST['email'])) : "";
//------------------------------------------------
// Check if the user has clicked on Submit
//------------------------------------------------
if ( isset($_POST['losthash']) && $_POST['losthash'] ) {
do_resendhash($username, $email);
}
//------------------------------------------------
// Assign template vars
//------------------------------------------------
$TEMPLATE->assign("username", htmlentities2utf8($username));
$TEMPLATE->assign("email", htmlentities2utf8($email));
return 1;
}
// End Function
//------------------------------------------------
// Send hash
//------------------------------------------------
function do_resendhash($username, $email)
{
global $DB, $LANG, $TEMPLATE, $PREFS;
// *system demo admin label* //
//------------------------------------------------
// Validate username
//------------------------------------------------
if ( ($username == "" && $email == "") || ($PREFS->conf['lostpass_username_email'] == 'both' && ($username == "" || $email == "")) )
{
$TEMPLATE->set_message("error", ($LANG['forgotpassword']['invalid_input']), 0, 0);
return 0;
}
//------------------------------------------------
// Validate username
//------------------------------------------------
if ($username != "")
{
$valid_username = validate_username($username, $PREFS->conf['min_username_length']);
if ($valid_username == 1)
{
$TEMPLATE->set_message("error", str_replace("%1%", $PREFS->conf['min_username_length'], ($LANG['forgotpassword']['username_too_long'])), 0, 0);
return 0;
}
elseif ($valid_username == 2 || $valid_username == 3)
{
$TEMPLATE->set_message("error", ($LANG['forgotpassword']['invalid_username']), 0, 0);
return 0;
}
}
//------------------------------------------------
// Validate email
//------------------------------------------------
if ($email != "")
{
$valid_email = validate_email($email);
if ($valid_email == 1)
{
$TEMPLATE->set_message("error", str_replace("%1%", 4, ($LANG['forgotpassword']['email_too_long'])), 0, 0);
return 0;
}
elseif ($valid_email == 2)
{
$TEMPLATE->set_message("error", ($LANG['forgotpassword']['invalid_email']), 0, 0);
return 0;
}
}
//------------------------------------------------
// Convert username to lower case
//------------------------------------------------
$username = mysql_real_escape_string($username);
$email = mysql_real_escape_string($email);
//------------------------------------------------
// Where clause
//------------------------------------------------
$where = array();
if ($username) {
$where[] = "username='$username'";
}
if ($email) {
$where[] = "email='$email'";
}
$where = implode(($PREFS->conf['lostpass_username_email'] == 'both' ? ' AND ' : ' OR '), $where);
//------------------------------------------------
// Get member info
//------------------------------------------------
$result = $DB->query("SELECT member_id, group_id, username, email, active FROM " . DB_PREFIX . "members WHERE ($where) AND group_id!=" . $PREFS->conf['canceled_member_group'] . " LIMIT 1");
//------------------------------------------------
// Check if resultset contains rows
//------------------------------------------------
if ($DB->num_rows($result) == 1)
{
//------------------------------------------------
// Fetch result set
//------------------------------------------------
$obj = $DB->fetch_object($result);
if ( $obj->group_id != $PREFS->conf['pending_member_group'] )
{
$TEMPLATE->set_message("error", ($LANG['forgotpassword']['already_active']), 0, 0);
redirect(VIR_PATH . ($PREFS->conf['fancy_urls'] ? "account/login/" : "index.php?m=account_login"));
}
elseif ($PREFS->conf['activation_type'] != 3)
{
//------------------------------------------------
// Set values
//------------------------------------------------
$member_id = $obj->member_id;
$email = $obj->email;
$username = $obj->username;
$hash = random_string(32, 0);
$DB->query("UPDATE " . DB_PREFIX . "members SET sessionhash='".mysql_real_escape_string($hash)."' WHERE member_id=$member_id LIMIT 1");
}
else
{
//------------------------------------------------
// Set message
//------------------------------------------------
$TEMPLATE->set_message("error", ($LANG['forgotpassword']['invalid_username_email']), 0, 0);
return 0;
}
}
else
{
//------------------------------------------------
// Set message
//------------------------------------------------
$TEMPLATE->set_message("error", ($LANG['forgotpassword']['invalid_username_email']), 0, 0);
return 0;
}
//------------------------------------------------
// Clean up
//------------------------------------------------
unset($obj);
unset($result);
//--------------------------------------------
// Get email templates
//--------------------------------------------
$PREFS->get_email_templates(array('member_activation_instructions'));
//------------------------------------------------
// Create email class
//------------------------------------------------
$EMAIL = new Email();
//------------------------------------------------
// Replace email body with tagged values
$PREFS->conf['member_activation_instructions_body'] = str_replace("{username}", $username, $PREFS->conf['member_activation_instructions_body']);
$PREFS->conf['member_activation_instructions_body'] = str_replace("{password}", "*hidden*", $PREFS->conf['member_activation_instructions_body']);
$PREFS->conf['member_activation_instructions_body'] = str_replace("{email}", $email, $PREFS->conf['member_activation_instructions_body']);
$PREFS->conf['member_activation_instructions_body'] = str_replace("{hash}", $hash,$PREFS->conf['member_activation_instructions_body']);
$PREFS->conf['member_activation_instructions_body'] = str_replace("{website}", VIR_PATH, $PREFS->conf['member_activation_instructions_body']);
$PREFS->conf['member_activation_instructions_body'] = str_replace("{activation_link}", VIR_PATH . ($PREFS->conf['fancy_urls'] ? "account/activate/$member_id/$hash/" : "index.php?m=account_activate&id=$member_id&hash=$hash&a=1"), $PREFS->conf['member_activation_instructions_body']);
//------------------------------------------------
// Send out an email to the member
//------------------------------------------------
$EMAIL->send($PREFS->conf['return_email'], $PREFS->conf['return_email_name'], $email, $PREFS->conf['member_activation_instructions_subject'], $PREFS->conf['member_activation_instructions_body']);
//------------------------------------------------
// Set the message
//------------------------------------------------
$TEMPLATE->set_message("info", ($LANG['forgotpassword']['hash_resent']), 0, 0);
redirect(VIR_PATH . ($PREFS->conf['fancy_urls'] ? "account/login/" : "index.php?m=account_login"));
return 1;
}
// End Function