//there is already someone with same account name
if ($sqlr->num_rows($result))
{
$sqlr->close();
redirect("register.php?err=3&usr=$user_name");
}
else
{
if ($expansion_select)
$expansion = (isset($_POST['expansion'])) ? $sqlr->quote_smart($_POST['expansion']) : 0;
else
$expansion = $defaultoption;
if ($require_account_verify)
{
$sqlm = new SQL;
$sqlm->connect($mmfpm_db['addr'], $mmfpm_db['user'], $mmfpm_db['pass'], $mmfpm_db['name']);
$result2 = $sqlm->query("
SELECT *
FROM mm_account_verification
WHERE username = '$user_name' OR email = '$mail'");
if ($sqlm->num_rows($result2) > 0)
{
redirect("register.php?err=15");
}
else
{
$client_ip = $_SERVER['REMOTE_ADDR'];
$authkey = sha1($client_ip . time());
$result = $sqlm->query("
INSERT INTO mm_account_verification
(username,
sha_pass_hash,
gmlevel,email,
joindate,
last_ip,
failed_logins,
locked,
last_login,
active_realm_id,
expansion,
authkey)
VALUES
(UPPER('$user_name'),
'$pass',
'0',
'$mail',
now(),
'$last_ip',
'0',
'$create_acc_locked',
'NULL',
'0',
'$expansion',
'$authkey')");
$sqlm->close();
require_once './libs/mailer/class.phpmailer.php';
$mailer = new PHPMailer();
$mailer->Mailer = $mailer_type;
if ($mailer_type == "smtp")
{
$mailer->Host = $smtp_cfg['host'];
$mailer->Port = $smtp_cfg['port'];
if($smtp_cfg['user'] != '')
{
$mailer->SMTPAuth = true;
$mailer->Username = $smtp_cfg['user'];
$mailer->Password = $smtp_cfg['pass'];
}
}
$file_name = "core/mail_templates/verify_mail.tpl";
$fh = fopen($file_name, 'r');
$subject = fgets($fh, 4096);
$body = fread($fh, filesize($file_name));
fclose($fh);
$subject = str_replace("<title>", $title, $subject);
$body = str_replace("\n", "<br />", $body);
$body = str_replace("\r", " ", $body);
$body = str_replace("<base_url>", $_SERVER['SERVER_NAME'], $body);
$body = str_replace("<username>", $user_name, $body);
$body = str_replace("<password>", $pass1, $body);
$body = str_replace("<authkey>", $authkey, $body);
$mailer->WordWrap = 50;
$mailer->From = $from_mail;
$mailer->FromName = "$title Admin";
$mailer->Subject = $subject;
$mailer->IsHTML(true);
$mailer->Body = $body;
$mailer->AddAddress($mail);
if(!$mailer->Send())
{
$mailer->ClearAddresses();
redirect("register.php?&err=11&usr=".$mailer->ErrorInfo);
}
else
{
$mailer->ClearAddresses();
redirect("register.php?&err=16");
}
}
unset($mailer);
}
else
{
$result = $sqlr->query("
INSERT INTO account
(username,
sha_pass_hash,
gmlevel,
email,
joindate,
last_ip,
failed_logins,
locked,
last_login,
active_realm_id,
expansion)
VALUES
(UPPER('$user_name'),
'$pass',
0,
'$mail',
now(),
'$last_ip',
0,
$create_acc_locked,
NULL,
0,
$expansion)");
if ($invited_by)
{
$user_id = $sqlr->result($sqlr->query('
SELECT id
FROM account
WHERE username = \''.$user_name.'\''), 'id');
$referredby = $_POST['referredby'];
$referred_by = $sqlr->result($sqlr->query('
SELECT id
FROM account
WHERE username = \''.$referredby.'\''), 'id');
$sqlm = new SQL;
$sqlm->connect($mmfpm_db['addr'], $mmfpm_db['user'], $mmfpm_db['pass'], $mmfpm_db['name']);
if ($referred_by == NULL);
else
{
if ($referred_by == $user_id);
else
{
$sqlm->query('
INSERT INTO mm_point_system_invites
(PlayersAccount, InviterAccount)
VALUES
(\''.$user_id.'\', \''.$referred_by.'\')');
}
}
redirect("register.php?err=17");
$sqlm->close();
}
}
$sqlr->close();
setcookie ("terms", "", time() - 3600);
if ($send_mail_on_creation)
{
require_once './libs/mailer/class.phpmailer.php';
$mailer = new PHPMailer();
$mailer->Mailer = $mailer_type;
if ($mailer_type == "smtp")
{
$mailer->Host = $smtp_cfg['host'];
$mailer->Port = $smtp_cfg['port'];
if($smtp_cfg['user'] != '')
{
$mailer->SMTPAuth = true;
$mailer->Username = $smtp_cfg['user'];
$mailer->Password = $smtp_cfg['pass'];
}
}
$file_name = "core/mail_templates/mail_welcome.tpl";
$fh = fopen($file_name, 'r');
$subject = fgets($fh, 4096);
$body = fread($fh, filesize($file_name));
fclose($fh);
$subject = str_replace("<title>", $title, $subject);
$body = str_replace("\n", "<br />", $body);
$body = str_replace("\r", " ", $body);
$body = str_replace("<base_url>", $_SERVER['SERVER_NAME'], $body);
$body = str_replace("<username>", $user_name, $body);
$body = str_replace("<password>", $pass1, $body);
$mailer->WordWrap = 50;
$mailer->From = $from_mail;
$mailer->FromName = "$title Admin";
$mailer->Subject = $subject;
$mailer->IsHTML(true);
$mailer->Body = $body;
$mailer->AddAddress($mail);
$mailer->Send();
$mailer->ClearAddresses();
}
unset($mailer);
if ($result) redirect("login.php?error=6");
}
}
//#####################################################################################################
// PRINT PASSWORD RECOVERY FORM
//#####################################################################################################
function pass_recovery()
{
global $lang_register, $lang_global, $output;
$output .= "
<center>
<fieldset class=\"half_frame\">
<legend>{$lang_register['recover_acc_password']}</legend>
<form method=\"post\" action=\"register.php?action=do_pass_recovery\" name=\"form\">
<table class=\"flat\">
<tr>
<td valign=\"top\">{$lang_register['username']} :</td>
<td><input type=\"text\" name=\"username\" size=\"45\" maxlength=\"14\" /><br />
{$lang_register['user_pass_rec_desc']}<br />
</td>
</tr>
<tr>
<td valign=\"top\">{$lang_register['email']} :</td>
<td><input type=\"text\" name=\"email\" size=\"45\" maxlength=\"225\" /><br />
{$lang_register['mail_pass_rec_desc']}
</td>
</tr>
<tr>
<td>";
makebutton($lang_register['recover_pass'], "javascript:do_submit()",150);
$output .= "
</td>
<td>";
makebutton($lang_global['back'], "javascript:window.history.back()", 328);
$output .= "
</td>
</tr>
</table>
</form>
</fieldset>
<br /><br />
</center>";
}
//#####################################################################################################
// DO RECOVER PASSWORD
//#####################################################################################################
function do_pass_recovery()
{
global $lang_global,
$realm_db,
$from_mail, $mailer_type, $smtp_cfg, $title;
if ( empty($_POST['username']) || empty($_POST['email']) ) redirect("register.php?action=pass_recovery&err=1");
$sql = new SQL;
$sql->connect($realm_db['addr'], $realm_db['user'], $realm_db['pass'], $realm_db['name']);
$user_name = $sql->quote_smart(trim($_POST['username']));
$mail = $sql->quote_smart($_POST['email']);
$result = $sql->query("
SELECT sha_pass_hash
FROM account
WHERE username = '$user_name' AND email = '$mail'");
if ($sql->num_rows($result) == 1)
{
require_once './libs/mailer/class.phpmailer.php';
$mailer = new PHPMailer();
$mailer->Mailer = $mailer_type;
if ($mailer_type == "smtp")
{
$mailer->Host = $smtp_cfg['host'];
$mailer->Port = $smtp_cfg['port'];
if($smtp_cfg['user'] != '')
{
$mailer->SMTPAuth = true;
$mailer->Username = $smtp_cfg['user'];
$mailer->Password = $smtp_cfg['pass'];
}
}