115 lines
No EOL
5.7 KiB
PHP
115 lines
No EOL
5.7 KiB
PHP
<?php
|
|
|
|
function index() {
|
|
global $renderer;
|
|
$renderer->display('login');
|
|
}
|
|
|
|
function index_post() {
|
|
global $renderer;
|
|
global $router;
|
|
// TODO: change the password encryption method
|
|
$query = doquery("SELECT * FROM {{table}} WHERE username='".$_POST["username"]."' AND password='".md5($_POST["password"])."' LIMIT 1", "users");
|
|
if (mysqli_num_rows($query) != 1) {
|
|
$renderer->simple("Connexion error", "Invalid username or password. Please go back and try again.");
|
|
}
|
|
$row = mysqli_fetch_array($query);
|
|
if (isset($_POST["rememberme"])) { $expiretime = time()+31536000; $rememberme = 1; } else { $expiretime = 0; $rememberme = 0; }
|
|
$cookie = $row["id"] . " " . $row["username"] . " " . md5($row["password"] . "--" . $dbsettings["secretword"]) . " " . $rememberme;
|
|
setcookie("dkgame", $cookie, $expiretime, "/", "", 0);
|
|
$router->redirect("/");
|
|
}
|
|
|
|
function register() { // Register a new account.
|
|
global $controlrow;
|
|
global $renderer;
|
|
|
|
if ($controlrow["verifyemail"] == 1) {
|
|
$renderer->prepare("verifytext", "A verification code will be sent to the address above, and you will not be able to log in without first entering the code. Please be sure to enter your correct email address.");
|
|
}
|
|
|
|
$renderer->prepare("class1name", $controlrow["class1name"]);
|
|
$renderer->prepare("class2name", $controlrow["class2name"]);
|
|
$renderer->prepare("class3name", $controlrow["class3name"]);
|
|
$renderer->prepare("diff1name", $controlrow["diff1name"]);
|
|
$renderer->prepare("diff2name", $controlrow["diff2name"]);
|
|
$renderer->prepare("diff3name", $controlrow["diff3name"]);
|
|
|
|
$renderer->display("register");
|
|
}
|
|
|
|
function register_post() {
|
|
global $renderer;
|
|
global $messages;
|
|
global $router;
|
|
global $controlrow;
|
|
global $postData;
|
|
|
|
$postData->addField("Username", ["required", "alphanumeric", "unique"], "username", ["field"=>"username", "table"=>"users"]);
|
|
$postData->addField("Character Name", ["required", "alphanumeric", "unique"], "charname", ["field"=>"charname", "table"=>"users"]);
|
|
$postData->addFields("Email", ["required", "mail", "equals", "unique"], ["email1", "email2"], ["field"=>"email", "table"=>"users"]);
|
|
$postData->addFields("Password", ["required", "alphanumeric", "equals"], ["password1", "password2"]);
|
|
$postData->addField("Difficulty", [], "difficulty");
|
|
$postData->addField("Character Class", [], "charclass");
|
|
|
|
if ($postData->validate() == false) {
|
|
$renderer->addPostFields(["username", "charname", "email1", "charclass", "difficulty"]);
|
|
|
|
$renderer->prepare("class1name", $controlrow["class1name"]);
|
|
$renderer->prepare("class2name", $controlrow["class2name"]);
|
|
$renderer->prepare("class3name", $controlrow["class3name"]);
|
|
$renderer->prepare("diff1name", $controlrow["diff1name"]);
|
|
$renderer->prepare("diff2name", $controlrow["diff2name"]);
|
|
$renderer->prepare("diff3name", $controlrow["diff3name"]);
|
|
|
|
$messages->putList("danger", "The following error(s) occurred when your account was being made:", $postData->errors);
|
|
$renderer->display("register");
|
|
}
|
|
|
|
$username = $postData->getField("username");
|
|
$email = $postData->getField("email1");
|
|
$charname = $postData->getField("charname");
|
|
$charclass = $postData->getField("charclass");
|
|
$difficulty = $postData->getField("difficulty");
|
|
|
|
$password = md5($password1);
|
|
|
|
$verifycode = ($controlrow["verifyemail"] == 1)
|
|
? substr(str_shuffle(str_repeat('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-', 8)), 0, 8)
|
|
: '1';
|
|
|
|
$query = doquery("INSERT INTO {{table}} SET regdate=NOW(),verify='$verifycode',username='$username',password='$password',email='$email',charname='$charname',charclass='$charclass',difficulty='$difficulty'", "users") or die(mysql_error());
|
|
|
|
if ($controlrow["verifyemail"] == 1) {
|
|
if (__sendregmail($email, $verifycode) == true) {
|
|
$messages->put("success", "Your account was created successfully.<br /><br />You should receive an Account Verification email shortly. You will need the verification code contained in that email before you are allowed to log in. Once you have received the email, please visit the <a href=\"users.php?do=verify\">Verification Page</a> to enter your code and start playing.");
|
|
} else {
|
|
$messages->put("danger", "Your account was created succesfully.<br /><br />However, there was a problem sending your verification email. Please check with the game administrator to help resolve this problem.");
|
|
}
|
|
} else {
|
|
$messages->put("success", "Your account was created succesfully.<br /><br />You may now continue to the <a href=\"login.php?do=login\">Login Page</a> and start playing ".$controlrow["gamename"]."!");
|
|
}
|
|
$router->redirect();
|
|
}
|
|
|
|
function __sendregmail($emailaddress, $vercode) {
|
|
|
|
$controlquery = doquery("SELECT * FROM {{table}} WHERE id='1' LIMIT 1", "control");
|
|
$controlrow = mysqli_fetch_array($controlquery);
|
|
extract($controlrow);
|
|
$verurl = $gameurl . "?do=verify";
|
|
|
|
$email = <<<END
|
|
You or someone using your email address recently signed up for an account on the $gamename server, located at $gameurl.
|
|
|
|
This email is sent to verify your registration email. In order to begin using your account, you must verify your email address.
|
|
Please visit the Verification Page ($verurl) and enter the code below to activate your account.
|
|
Verification code: $vercode
|
|
|
|
If you were not the person who signed up for the game, please disregard this message. You will not be emailed again.
|
|
END;
|
|
|
|
$status = mymail($emailaddress, "$gamename Account Verification", $email);
|
|
return $status;
|
|
|
|
} |