".LAN_FPW10." ".LAN_LOGIN.". "; // .LAN_FPW12;
e107::getMessage()->addSuccess($txt);
e107::getRender()->tablerender(LAN_03, e107::getMessage()->render());
require_once(FOOTERF);
exit;
}
// The password reset code was not found
else
{
fpw_error(LAN_FPW7);
}
}
// Request to reset password
if (!empty($_POST['pwsubmit']))
{
require_once(e_HANDLER.'mail.php');
if ($pref['fpwcode'] && extension_loaded('gd'))
{
if (!$sec_img->verify_code($_POST['rand_num'], $_POST['code_verify']))
{
fpw_error(LAN_INVALID_CODE);
}
}
$email = $_POST['email'];
$clean_email = check_email($tp->toDB($_POST['email']));
$clean_username = $tp->toDB(varset($_POST['username'], ''));
$query = "`user_email`='{$clean_email}' ";
// Allow admins to remove 'username' from fpw_template.php if they wish.
$query .= (isset($_POST['username'])) ? " AND `user_loginname`='{$clean_username}'" : "";
if($sql->select('user', '*', $query))
{
// Found user in DB
$row = $sql->fetch();
// Main admin expected to be competent enough to never forget password! (And its a security check - so warn them)
// Sending email to admin alerting them of attempted admin password reset, and redirect user to homepage.
if(!getperms('0')) // disabled when testing as main-admin.
{
if (($row['user_admin'] == 1) && (($row['user_perms'] == '0') OR ($row['user_perms'] == '0.')))
{
sendemail($pref['siteadminemail'], LAN_06, LAN_07.' ['.e107::getIPHandler()->getIP(FALSE).'] '.e107::getIPHandler()->getIP(TRUE).' '.LAN_08);
e107::getRedirect()->redirect(SITEURL);
}
}
// Banned user, or not validated
switch($row['user_ban'])
{
case USER_BANNED:
e107::getRedirect()->redirect(SITEURL);
break;
case USER_VALIDATED:
break;
default:
fpw_error(LAN_02.':'.$row['user_ban']); // Intentionally rather a vague message
exit;
}
// Check if password reset was already requested
if ($result = $sql->select('tmp', '*', "`tmp_ip` = 'pwreset' AND `tmp_info` LIKE '".$row['user_loginname'].FPW_SEPARATOR."%'"))
{
fpw_error(LAN_FPW4);
exit;
}
// Set unique reset code
$datekey = microtime(true);
$rcode = e107::getUserSession()->generateRandomString( '############' );
// $rcode = crypt(($_SERVER['HTTP_USER_AGENT'] . serialize($pref). $clean_email . $datekey), e_TOKEN);
// Prepare email
$link = SITEURL.'fpw.php?'.$rcode;
$message = LAN_FPW5.' '.SITENAME.' '.LAN_FPW14.': '.e107::getIPHandler()->getIP(TRUE).".\n\n".LAN_FPW15."\n\n".LAN_FPW16."\n\n".LAN_FPW17."\n\n{$link}";
// Set timestamp two days ahead so it doesn't get auto-deleted
// $deltime = time()+86400 * 2;
$deltime = strtotime("+ 10 minutes");
// Insert the password reset request into the database
$insertQry = array(
'tmp_ip' => 'pwreset',
'tmp_time' => $deltime,
'tmp_info' => ($row['user_id'].FPW_SEPARATOR.$row['user_loginname'].FPW_SEPARATOR.$rcode)
);
$sql->insert('tmp', $insertQry);
// Setup the information to log
$do_log['password_action'] = LAN_FPW18;
$do_log['user_id'] = $row['user_id'];
$do_log['user_name'] = $row['user_name'];
$do_log['user_loginname'] = $row['user_loginname'];
$do_log['activation_code'] = $rcode;
if(getperms('0'))
{
$message .= "\n\nCaution: If you click the button below, you will follow the link the user receives in their email, and the password will actually be reset!"; // NO LAN
$message .= "\n\nClick to Continue with test"; // NO LAN
$ns->tablerender("Testing Mode", nl2br($message));
require_once(FOOTERF);
exit;
}
// Try to send the email
if(sendemail($clean_email, "".LAN_09."".SITENAME, $message))
{
e107::getMessage()->addInfo(LAN_FPW6);
$do_log['password_result'] = LAN_FPW20;
}
else
{
//$text = "