1
0
mirror of https://github.com/cydrobolt/polr.git synced 2024-11-09 11:42:28 +01:00

Refactor some code and remove unused segments

This commit is contained in:
Chaoyi Zha 2015-09-13 13:05:57 -04:00
parent 4235da2ce5
commit 192015304d

View File

@ -12,48 +12,40 @@ if ($regtype == "none") {
require_once 'layout-headerlg.php';
echo "Registration is disabled. <br><br><a href='register.php'>Go Back</a>";
require_once 'layout-footerlg.php';
die(); //prevent user from registering
die(); // prevent user from registering
}
if (!$isemail) {
require_once 'layout-headerlg.php';
echo "Please enter a valid email. <br><br><a href='register.php'>Go Back</a>";
require_once 'layout-footerlg.php';
die(); //prevent user from registering
die();
}
if ((strlen($_POST['username']) > 15) || (strlen($_POST['password']) > 25) || (strlen($_POST['email']) > 50)) {
require_once 'layout-headerlg.php';
echo "Your username must not be over 15 characters, password must be under 25 characters but over 6 characters, and email must be under 50 charcaters. <br><br><a href='register.php'>Go Back</a>";
require_once 'layout-footerlg.php';
die(); //prevent user from registering
die();
}
if (strlen($_POST['username']) == 0 || strlen($_POST['password']) < 4 || strlen($_POST['email']) == 0) {
require_once 'layout-headerlg.php';
echo "Fields may not be left blank, password must be over 4 characters. <br><br><a href='register.php'>Go Back</a>";
require_once 'layout-footerlg.php';
die(); //prevent user from registering
die();
}
if (!ctype_alnum($_POST['username'])) {
require_once 'layout-headerlg.php';
echo "Your username must be alphanumerical (numbers and letters only). <br><br><a href='register.php'>Go Back</a>";
require_once 'layout-footerlg.php';
die(); //prevent user from registering
die();
}
/*
if ($_POST['tos']!='accept') {
require_once 'layout-headerlg.php';
echo "You must accept the <a href='tos.php'>Terms of Service</a> in order to register.<br><br><a href='register.php'>Go Back</a>";
require_once 'layout-footerlg.php';
die();
}
*/
$salt = mcrypt_create_iv(23, MCRYPT_DEV_URANDOM); //create salt
$salt = mcrypt_create_iv(23, MCRYPT_DEV_URANDOM); // create salt
$rstr = mcrypt_create_iv(23, MCRYPT_DEV_URANDOM);
$reg = array("username" => $mysqli->real_escape_string($_POST['username']),"email" => $mysqli->real_escape_string($_POST['email']), "password" => $mysqli->real_escape_string($_POST['password']), "rkey" => sha1($mysqli->real_escape_string($_POST['username']) . date('zjDygs') . $rstr));
//check if already exists
// check if user or email already exists
$ireg;
$ireg['1'] = sqlex('auth', 'email', 'username', $reg['username']);
$ireg['2'] = sqlex('auth', 'username', 'email', $reg['email']);
@ -65,7 +57,7 @@ if (($ireg['1'] == true || $ireg['2'] == true) && $ireg['3'] == 1) {
require_once 'layout-headerlg.php';
echo "Username/email already in use. <br><br><a href='register.php'>Go Back</a>";
require_once 'layout-footerlg.php';
die(); //prevent user from registering
die();
}
$opts = array(
@ -84,8 +76,6 @@ else {
$active = "0";
}
//$qr = "INSERT INTO `auth` (username,email,password,rkey,valid,ip) VALUES ('{$reg['username']}','{$reg['email']}','{$hashed}','{$reg['rkey']}','{$active}', '{$ip}');";
//$rr = $mysqli->query($qr) or showerror();
$qp = "INSERT INTO `auth` (username,email,password,rkey,valid,ip) VALUES (?,?,?,?,?,?)";
$st = $mysqli->prepare($qp) or showerror();
$st->bind_param('ssssss', $reg['username'], $reg['email'], $hashed, $reg['rkey'], $active, $ip) or showerror();