Размер файла: 5.41Kb
<?php
/**********************************
* @package: PerfCMS *
* @year: 2012 *
* @author: Artas *
* @link: http://perfcms.pp.ua *
**********************************/
$page = 'reg';
$title = $lang->word('sign_up');
require_once(SYS .'/view/header.php');
if($system['open_reg'] == 'no') {
$tpl->div('menu', $lang->word('reg_closed'));
echo '<div class="block">
'. NAV .' <a href="/sign_in/">'.$lang->word('sign_in').'</a><br/>
'. HICO .' <a href="/">'.$lang->word('home').'</a>
</div>';
require_once(SYS .'/view/footer.php');
exit;
}
if (isset($_POST['user_reg'])) {
$nick = htmlspecialchars(trim($_POST['nick']));
$name = htmlspecialchars(trim($_POST['name']));
$email = htmlspecialchars(trim($_POST['email']));
$password = htmlspecialchars(trim($_POST['password']));
$password2 = htmlspecialchars(trim($_POST['password2']));
if (empty($nick)) $err .= $lang->word('no_nick').'<br />';
if (empty($name)) $err .= $lang->word('no_name').'<br />';
if (empty($email)) $err .= $lang->word('no_email').'<br />';
if (empty($password)) $err .= $lang->word('no_pass').'<br />';
if (empty($password2)) $err .= $lang->word('no_pass2').'<br />';
if (!empty($nick) && (mb_strlen($nick, 'UTF-8') < 3 || mb_strlen($nick, 'UTF-8') > 32)) $err .= $lang->word('e_nick').'<br />';
if (!empty($nick) && !preg_match("#^([A-zА-я0-9\-\_\ ])+$#ui", $nick)) $err .= $lang->word('b_nick').'<br />';
if (!empty($name) && (mb_strlen($name, 'UTF-8') > 32)) $err .= $lang->word('e_name').'<br />';
if (!empty($email) && (mb_strlen($email, 'UTF-8') < 3 || mb_strlen($email, 'UTF-8') > 72)) $err .= $lang->word('b_mail').'<br />';
if (!empty($email) && !preg_match('|^([a-z0-9_\.\-]{1,20})@([a-z0-9\.\-]{1,20})\.([a-z]{2,4})$|ius', $email)) $err .= $lang->word('e_email').'<br />';
if (!empty($password) && (mb_strlen($password, 'UTF-8') < 5 || mb_strlen($password, 'UTF-8') > 64)) $err .= $lang->word('e_pass').'<br />';
if (!empty($password) && !empty($password2) && $password != $password2) $err .= $lang->word('e_pass2').'<br />';
if($db->query("SELECT * FROM `users` WHERE `nick` = '$nick'")->rowCount() == 1) $err .= $lang->word('ex_nick').'<br/>';
if($db->query("SELECT * FROM `users` WHERE `email` = '$email'")->rowCount() == 1) $err .= $lang->word('ex_mail').'<br/>';
if($_SESSION['captcha'] != $_POST['captcha']) $err .= $lang->word('error_captcha').'<br/>';
if (!isset($err)) {
$password = crypto($password);
$db->query("INSERT INTO `users` SET `name` = '". escape(trim($name)) ."', `nick` = '". escape(trim($nick)) ."', `password` = '". escape(trim($password)) ."', `reg_time` = '". time() ."', `time` = '". time() ."', `email` = '". escape(trim($email)) ."', `level` = '1', `gender` = '0'");
$language = $system['lang'];
$db->query("INSERT INTO `settings` SET `user_id` = '". $db->lastInsertId() ."', `lang` = '". $language ."', `ames` = '10', `theme` = 'default', `web_theme` = 'default', `fast_mess` = 'no', `view_profile` = 'all', `show_email` = 'no', `timezone` = '". $system['timezone']."'");
session_destroy();
echo '<div class="title">'.$lang->word('sign_up').'</div>
<div class="menu">
'.$lang->word('end_r_t').'<br/>
<a href="/sign_in/?nick='. $nick .'&password='. $password2 .'">'.$lang->word('sign_in').'</a>
</div>
<div class="block">
'. NAV .' <a href="/sign_in/">'.$lang->word('sign_in').'</a><br/>
'. HICO .' <a href="/">'.$lang->word('home').'</a>
</div> ';
require_once(SYS .'/view/footer.php');
exit();
}
}
if (isset($err)) echo '<div class="error">'. $err .'</div>';
echo '<form method="post" action="?">
<div class="title">'.$lang->word('sign_up').'</div>
<div class="menu">
'.$lang->word('nick').':<br />
<input type="text" name="nick" value="'. (isset($_POST['nick']) ? htmlspecialchars($_POST['nick']) : NULL) .'" /><br />
'.$lang->word('name').':<br />
<input type="text" name="name" value="'. (isset($_POST['name']) ? htmlspecialchars($_POST['name']) : NULL) .'" /><br />
E-Mail:<br />
<input type="text" name="email" value="'. (isset($_POST['email']) ? htmlspecialchars($_POST['email']) : NULL) .'" /><br />
'.$lang->word('password').':<br />
<input type="password" name="password" /><br />
'.$lang->word('password2').':<br />
<input type="password" name="password2" /><br />
'.$lang->word('enter_captcha').':<br />
<script>
function captcha_reload() {
document.getElementById(\'captcha\').src = "/system/view/captcha.php?" + Math.random();
}
</script>
<img id="captcha" src="'. URL .'/system/view/captcha.php" alt="captcha" /><br />
<a href="javascript:captcha_reload();">'.$lang->word('refresh').'</a><br />
<input type="text" name="captcha" size="6" /><br/>
<input type="submit" name="user_reg" value="'.$lang->word('sign_up').'" />
</div>
</form>
<div class="block">
'. NAV .' <a href="/sign_in/">'.$lang->word('sign_in').'</a><br/>
'. HICO .' <a href="/">'.$lang->word('home').'</a>
</div>';
require_once(SYS .'/view/footer.php');
?>