Skip to content

Commit

Permalink
Fixed account registration bugs
Browse files Browse the repository at this point in the history
Reworked the entire registration page backend to make it more user
friendly.
Fixed typo in reCAPTCHA text.  Should be working now as intended.
Fixed several SQL query functions that needed row counts.
Fixed the built in redirect function to correctly accommodate meta
redirects.
Added an option to disable the "email sent" notice on the webpage when
an email was sent.
Issue fixed #24 where SQL error was displayed when a user tried to
register an existing username.
  • Loading branch information
paintballrefjosh committed Mar 11, 2017
1 parent 0483746 commit 9ad4469
Show file tree
Hide file tree
Showing 5 changed files with 272 additions and 324 deletions.
26 changes: 13 additions & 13 deletions core/SDL/class.account.php
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ function register($params, $account_extend = NULL)
$email_text .= 'Password: '.$password."\n";
$email_text .= 'This is your activation key: '.$tmp_act_key."\n";
$email_text .= 'CLICK HERE : '.$act_link."\n";
send_email($params['email'],$params['username'],'== '.(string)$Config->get('site_title').' account activation ==',$email_text);
send_email($params['email'], $params['username'], '== '.(string)$Config->get('site_title').' account activation ==', $email_text, false);
return 1;
}

Expand Down Expand Up @@ -495,8 +495,8 @@ function isLoggedIn()

function isAvailableUsername($username)
{
$res = $this->DB->num_rows("SELECT COUNT(*) FROM `account` WHERE `username`='".$username."'");
if($res['COUNT(*)'] == 0)
$res = $this->DB->count("SELECT id FROM `account` WHERE `username`='".$username."'");
if($res == 0)
{
return TRUE; // username is available
}
Expand All @@ -512,8 +512,8 @@ function isAvailableUsername($username)

function isAvailableEmail($email)
{
$res = $this->DB->num_rows("SELECT COUNT(*) FROM `account` WHERE `email`='".$email."'");
if($res['COUNT(*)'] == 0)
$res = $this->DB->count("SELECT id FROM `account` WHERE `email`='".$email."'");
if($res == 0)
{
return TRUE; // email is available
}
Expand Down Expand Up @@ -581,8 +581,8 @@ function isValidActivationKey($key)
function isBannedAccount($account_id)
{
global $DB;
$check = $DB->num_rows("SELECT COUNT(*) FROM `account_banned` WHERE `id`='".$account_id."' AND `active`=1");
if ($check['COUNT(*)'] > 0)
$check = $DB->count("SELECT id FROM `account_banned` WHERE `id`='".$account_id."' AND `active`=1");
if ($check > 0)
{
return TRUE; // Account is banned
}
Expand All @@ -599,8 +599,8 @@ function isBannedAccount($account_id)
function isBannedIp()
{
global $DB;
$check = $DB->num_rows("SELECT COUNT(*) FROM `ip_banned` WHERE `ip`='".$_SERVER['REMOTE_ADDR']."'");
if ($check['COUNT(*)'] > 0)
$check = $DB->count("SELECT ip FROM `ip_banned` WHERE `ip`='".$_SERVER['REMOTE_ADDR']."'");
if ($check > 0)
{
return TRUE; // IP is banned
}
Expand Down Expand Up @@ -934,8 +934,8 @@ function onlinelist_add()
{
global $user;

$result = $this->DB->num_rows("SELECT COUNT(*) FROM `mw_online` WHERE `user_id`='".$this->user['id']."'");
if($result['COUNT(*)'] > 0)
$result = $this->DB->count("SELECT id FROM `mw_online` WHERE `user_id`='".$this->user['id']."'");
if($result > 0)
{
$this->DB->query("UPDATE `mw_online` SET
`user_ip`='".$this->user['ip']."',
Expand Down Expand Up @@ -969,8 +969,8 @@ function onlinelist_addguest()
{
global $user;

$result = $this->DB->num_rows("SELECT COUNT(*) FROM `mw_online` WHERE `user_id`='0' AND `user_ip`='".$this->user['ip']."'");
if($result['COUNT(*)'] > 0)
$result = $this->DB->count("SELECT id FROM `mw_online` WHERE `user_id`='0' AND `user_ip`='".$this->user['ip']."'");
if($result > 0)
{
$this->DB->query("UPDATE `mw_online` SET
`user_ip`='".$this->user['ip']."',
Expand Down
10 changes: 5 additions & 5 deletions core/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ function print_gold($gvar)
//===== MAIL FUNCTIONS =====//

// Send Mail
function send_email($goingto, $toname, $sbj, $messg)
function send_email($goingto, $toname, $sbj, $messg, $notice = true)
{
global $Config;
define('DISPLAY_XPM4_ERRORS', true); // display XPM4 errors
Expand All @@ -232,7 +232,7 @@ function send_email($goingto, $toname, $sbj, $messg)
$c = SMTP::MXconnect($h[1]); // connect to SMTP server (direct) from MX hosts list
$s = SMTP::Send($c, array($t), $m, $f); // send mail
// print result
if ($s) output_message('success', 'Mail Sent!');
if($notice)if ($s) output_message('success', 'Mail Sent!');
else output_message('error', print_r($_RESULT));
SMTP::Disconnect($c); // disconnect
}
Expand All @@ -245,7 +245,7 @@ function send_email($goingto, $toname, $sbj, $messg)
// send mail
$send = mail($goingto, $sbj, $mess['content'], 'From: '.$core_em.''."\n".$mess['header']);
// print result
echo $send ? output_message('success', 'Mail Sent!') : output_message('error', 'Error!');
if($notice)echo $send ? output_message('success', 'Mail Sent!') : output_message('error', 'Error!');
}
elseif($Config->get('email_type') == 2) // If email type "2" (MTA Relay)
{
Expand All @@ -270,7 +270,7 @@ function send_email($goingto, $toname, $sbj, $messg)
}

// send mail relay using the '$c' resource connection
echo $m->Send($c) ? output_message('success', 'Mail Sent!') : output_message('error', 'Error! Please check your config and make sure you inserted your MTA info correctly.');
if($notice)echo $m->Send($c) ? output_message('success', 'Mail Sent!') : output_message('error', 'Error! Please check your config and make sure you inserted your MTA info correctly.');

$m->Disconnect(); // disconnect from server
// print_r($m->History); // optional, for debugging
Expand Down Expand Up @@ -304,7 +304,7 @@ function redirect($linkto,$type=0,$wait_sec=0)
{
if($type==0)
{
$GLOBALS['redirect'] = '<meta http-equiv=refresh content="'.$wait_sec.';url='.$linkto.'">';
echo '<meta http-equiv=refresh content="'.$wait_sec.';url='.$linkto.'">';
}
else
{
Expand Down
1 change: 1 addition & 0 deletions inc/account/account.activate.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ function CheckKey()
$DB->query("UPDATE account SET locked=0 WHERE id='".$_GET['id']."' LIMIT 1");
$DB->query("UPDATE mw_account_extend SET activation_code=NULL WHERE account_id='".$_GET['id']."' LIMIT 1");
output_message('success', '<b>Account successfully activated! You may now log into the server and play.</b>');
redirect("?p=account&sub=login", 0, 2);
}
else
{
Expand Down
Loading

0 comments on commit 9ad4469

Please sign in to comment.