109 lines
No EOL
5.7 KiB
PHP
109 lines
No EOL
5.7 KiB
PHP
<?php // users.php :: Handles user account functions.
|
|
|
|
// TODO: remove when porting to real boot files
|
|
define('DS', DIRECTORY_SEPARATOR);
|
|
define('PATH_ROOT', __DIR__.DS);
|
|
define('PATH_BOOT', PATH_ROOT.'kernel'.DS.'boot'.DS);
|
|
|
|
include('kernel/lib.php');
|
|
$link = opendb();
|
|
|
|
if (isset($_GET["do"])) {
|
|
|
|
$do = $_GET["do"];
|
|
if ($do == "register") { register(); }
|
|
elseif ($do == "verify") { verify(); }
|
|
elseif ($do == "lostpassword") { lostpassword(); }
|
|
elseif ($do == "changepassword") { changepassword(); }
|
|
|
|
}
|
|
|
|
function verify() {
|
|
|
|
if (isset($_POST["submit"])) {
|
|
extract($_POST);
|
|
$userquery = doquery("SELECT username,email,verify FROM {{table}} WHERE username='$username' LIMIT 1","users");
|
|
if (mysqli_num_rows($userquery) != 1) { die("No account with that username."); }
|
|
$userrow = mysqli_fetch_array($userquery);
|
|
if ($userrow["verify"] == 1) { die("Your account is already verified."); }
|
|
if ($userrow["email"] != $email) { die("Incorrect email address."); }
|
|
if ($userrow["verify"] != $verify) { die("Incorrect verification code."); }
|
|
// If we've made it this far, should be safe to update their account.
|
|
$updatequery = doquery("UPDATE {{table}} SET verify='1' WHERE username='$username' LIMIT 1","users");
|
|
display("Your account was verified successfully.<br /><br />You may now continue to the <a href=\"login.php?do=login\">Login Page</a> and start playing the game.<br /><br />Thanks for playing!","Verify Email",false,false,false);
|
|
}
|
|
$page = gettemplate("verify");
|
|
$topnav = "<a href=\"login.php?do=login\"><img src=\"templates/assets/img/button_login.gif\" alt=\"Log In\" border=\"0\" /></a><a href=\"users.php?do=register\"><img src=\"templates/assets/img/button_register.gif\" alt=\"Register\" border=\"0\" /></a><a href=\"help.php\"><img src=\"templates/assets/img/button_help.gif\" alt=\"Help\" border=\"0\" /></a>";
|
|
display($page, "Verify Email", false, false, false);
|
|
|
|
}
|
|
|
|
function lostpassword() {
|
|
|
|
if (isset($_POST["submit"])) {
|
|
extract($_POST);
|
|
$userquery = doquery("SELECT email FROM {{table}} WHERE email='$email' LIMIT 1","users");
|
|
if (mysqli_num_rows($userquery) != 1) { die("No account with that email address."); }
|
|
$newpass = "";
|
|
for ($i=0; $i<8; $i++) {
|
|
$newpass .= chr(rand(65,90));
|
|
}
|
|
$md5newpass = md5($newpass);
|
|
$updatequery = doquery("UPDATE {{table}} SET password='$md5newpass' WHERE email='$email' LIMIT 1","users");
|
|
if (sendpassemail($email,$newpass) == true) {
|
|
display("Your new password was emailed to the address you provided.<br /><br />Once you receive it, you may <a href=\"login.php?do=login\">Log In</a> and continue playing.<br /><br />Thank you.","Lost Password",false,false,false);
|
|
} else {
|
|
display("There was an error sending your new password.<br /><br />Please check with the game administrator for more information.<br /><br />We apologize for the inconvience.","Lost Password",false,false,false);
|
|
}
|
|
die();
|
|
}
|
|
$page = gettemplate("lostpassword");
|
|
$topnav = "<a href=\"login.php?do=login\"><img src=\"templates/assets/img/button_login.gif\" alt=\"Log In\" border=\"0\" /></a><a href=\"users.php?do=register\"><img src=\"templates/assets/img/button_register.gif\" alt=\"Register\" border=\"0\" /></a><a href=\"help.php\"><img src=\"templates/assets/img/button_help.gif\" alt=\"Help\" border=\"0\" /></a>";
|
|
display($page, "Lost Password", false, false, false);
|
|
|
|
}
|
|
|
|
function changepassword() {
|
|
|
|
if (isset($_POST["submit"])) {
|
|
extract($_POST);
|
|
$userquery = doquery("SELECT * FROM {{table}} WHERE username='$username' LIMIT 1","users");
|
|
if (mysqli_num_rows($userquery) != 1) { die("No account with that username."); }
|
|
$userrow = mysqli_fetch_array($userquery);
|
|
if ($userrow["password"] != md5($oldpass)) { die("The old password you provided was incorrect."); }
|
|
if (preg_match("/[^A-z0-9_\-]/", $newpass1)==1) { die("New password must be alphanumeric."); } // Thanks to "Carlos Pires" from php.net!
|
|
if ($newpass1 != $newpass2) { die("New passwords don't match."); }
|
|
$realnewpass = md5($newpass1);
|
|
$updatequery = doquery("UPDATE {{table}} SET password='$realnewpass' WHERE username='$username' LIMIT 1","users");
|
|
if (isset($_COOKIE["dkgame"])) { setcookie("dkgame", "", time()-100000, "/", "", 0); }
|
|
display("Your password was changed successfully.<br /><br />You have been logged out of the game to avoid cookie errors.<br /><br />Please <a href=\"login.php?do=login\">log back in</a> to continue playing.","Change Password",false,false,false);
|
|
die();
|
|
}
|
|
$page = gettemplate("changepassword");
|
|
$topnav = "<a href=\"login.php?do=login\"><img src=\"templates/assets/img/button_login.gif\" alt=\"Log In\" border=\"0\" /></a><a href=\"users.php?do=register\"><img src=\"templates/assets/img/button_register.gif\" alt=\"Register\" border=\"0\" /></a><a href=\"help.php\"><img src=\"templates/assets/img/button_help.gif\" alt=\"Help\" border=\"0\" /></a>";
|
|
display($page, "Change Password", false, false, false);
|
|
|
|
}
|
|
|
|
function sendpassemail($emailaddress, $password) {
|
|
|
|
$controlquery = doquery("SELECT * FROM {{table}} WHERE id='1' LIMIT 1", "control");
|
|
$controlrow = mysqli_fetch_array($controlquery);
|
|
extract($controlrow);
|
|
|
|
$email = <<<END
|
|
You or someone using your email address submitted a Lost Password application on the $gamename server, located at $gameurl.
|
|
|
|
We have issued you a new password so you can log back into the game.
|
|
|
|
Your new password is: $password
|
|
|
|
Thanks for playing.
|
|
END;
|
|
|
|
$status = mymail($emailaddress, "$gamename Lost Password", $email);
|
|
return $status;
|
|
|
|
}
|
|
|
|
?>
|