[COLOR="#ff0000"][B]Register PHP[/B][/COLOR]
<?php
if (!defined('KODEVS') || KODEVS != 1)
die();
class Page
{
private $site, $database, $content;
private $cacheable = FALSE;
private $cacheTime = 0;
function __construct($site)
{
$this->site = $site;
$this->config = $site->config;
$this->database = $site->database;
Template::SetVar('title', $this->config['SITE']['TITLE'] . Template::GetLangVar('PAGE_REGISTER_TITLE'));
if (isset($_GET['act']))
$this->cacheable = FALSE;
}
function Run()
{
Template::SetVar('reg_error', NULL);
if ($this->site->loggedIn)
{
$this->content = Template::Load('error', array('errmsg' => Template::GetLangVar('REG_ALREADY_REGGED')));
return;
}
switch (@$_GET['act'])
{
case 'process':
$this->Process();
break;
case 'verify':
break;
default:
$this->content = Template::Load('register');
}
}
function Process()
{
$s = $this->site;
$db = $this->database[ADB];
if (!@isset($_POST['submit']))
{
Template::SetVar('reg_error', NULL);
$this->content = Template::Load('register');
return;
}
$user = $s->SanitizeName(@$_POST['user']);
$pass1 = $s->SanitizeName(@$_POST['passwd1'], 12);
$pass2 = $s->SanitizeName(@$_POST['passwd2'], 12);
$wpass1 = $s->SanitizeName(@$_POST['wpasswd1'], 16);
$wpass2 = $s->SanitizeName(@$_POST['wpasswd2'], 16);
if (strlen(@$_POST['user']) > 20 || strlen($user) < 3)
{
$this->Error('REG_ACC_SIZE');
return;
}
if (!preg_match("/^[a-zA-Z0-9]+$/", $_POST['user']))
{
$this->Error('REG_ACC_INVALID');
return;
}
if (strlen($pass1) > 12 || strlen($pass1) < 5)
{
$this->Error('REG_PASS_SIZE');
return;
}
if ($pass1 != $pass2)
{
$this->Error('REQ_PASS_MATCH');
return;
}
if (strlen($wpass1) > 16 || strlen($wpass1) < 6)
{
$this->Error('REG_WPASS_SIZE');
return;
}
if ($wpass1 != $wpass2)
{
$this->Error('REQ_WPASS_MATCH');
return;
}
$num_rows = $db->doQuery('SELECT strAccountID FROM TB_USER WHERE strAccountID = ?', $user);
if ($num_rows == -1)
{
$this->Error('DB_ERROR');
$db->getError();
return;
}
elseif ($num_rows > 0)
{
$this->Error('REG_ACCOUNT_IN_USE');
return;
}
$pass1 = $this->site->doHashPassword($pass1);
$num_rows = $db->doQuery('INSERT INTO TB_USER (strAccountID, strPasswd) VALUES(?, ?)', $user, $pass1);
if ($num_rows == -1)
{
$this->Error('DB_ERROR');
$db->getError();
return;
}
$num_rows = $db->doQuery('INSERT INTO WAREHOUSE (strAccountID, nMoney, dwTime, WarehouseData, strSerial, strWarehousePW) VALUES(?, 0, 0, NULL, NULL, ?)', $user, $wpass1);
if ($num_rows == -1)
{
$this->Error('DB_ERROR');
$db->getError();
return;
}
$this->content = Template::Load('register-complete');
}
function Error($error)
{
Template::SetVar('reg_error', '<@register-error@>');
Template::SetVar('reg_errmsg', Template::GetLangVar($error));
$this->content = Template::Load('register');
}
function GetTemplate()
{
return $this->content;
}
function IsCacheable()
{
return $this->cacheable;
}
function CacheTime()
{
return $this->cacheTime;
}
function __destruct()
{
}
}
?>