Требование: PHP => 5.3, часть 2
[cswow.git] / module / registration / script.php
blobb4143a29f9bfb54d3d8b9de57ac6ec7ebfed9df6
1 <?php
2 if (@$config == NULL) die ("");
4 function checkAddress($ip)
6 global $rDB, $config;
7 // Не проверяем IP если не требуется
8 if ($config['limit_account_from_one_ip'] == 0)
9 return 0;
10 $list = $rDB->selectCell("SELECT `last_ip` FROM `account` WHERE `last_ip` = ?", $ip);
11 if ($list == "")
12 return 0;
13 return 1;
16 function checkName($username)
18 global $rDB;
19 $list = $rDB->selectCell("SELECT `username` FROM `account` WHERE `username` = ?", $username);
20 if ($list == "")
21 return 0;
22 return 1;
24 //==============================================================
25 // Скрипт регистрации
26 //==============================================================
28 $show = true;
29 $ip = @$_SERVER['REMOTE_ADDR'];
31 if ($rDB == NULL)
33 echo $lang['reg_err_db'];
34 $show = false;
36 else if (checkAddress($ip))
38 echo $lang['reg_err_one_ip'];
39 $show = false;
41 else if(@$_POST['script'] == 'reg')
43 $name = @$_POST['account_name'];
44 $username = strtoupper(@$_POST['account_name']);
45 $password = strtoupper(@$_POST['account_pass']);
46 $email = @$_POST['account_email'];
47 $nameLen = strlen($name);
48 $passLen = strlen($password);
50 if (empty($username) OR empty($password))
51 echo $lang['reg_err_name_pass'];
52 else if ($nameLen < 3 OR $nameLen > 16)
53 echo $lang['reg_err_name_size'];
54 else if ($passLen < 3 OR $passLen > 16)
55 echo $lang['reg_err_pass_size'];
56 else if (!preg_match("/^\w*$/","$username$password"))
57 echo $lang['reg_err_charset'];
58 else if (preg_match("/[(а-я)|(А-Я)]/","$username$password"))
59 echo $lang['reg_err_charset'];
60 else if ($username == $password)
61 echo $lang['reg_err_name_is_pass'];
62 else if (!eregi("^[a-z0-9\._-]+@[a-z0-9\._-]+\.[a-z]{2,4}$", $email))
63 echo $lang['reg_err_mail'];
64 else if (checkName($username))
65 echo $lang['reg_err_name_in_use'];
66 else
68 $res = $rDB->query("INSERT INTO `account` (`username`, `sha_pass_hash`, `email`, `last_ip`, `expansion`) VALUES (?, SHA1(?), ?, ?, '2')", $username, $username.":".$password, $email, $ip);
69 if ($res)
71 echo $lang['reg_success'];
72 $show = false;
74 else
75 echo $lang['reg_err_query'];
78 if ($show == true)
80 echo '<br>';
81 echo '<form method="post" action="?register" name="acc">';
82 echo '<input type="hidden" name="script" value="reg">';
83 echo '<table class=find>';
84 echo '<tr><td class=top colspan=2>';
85 echo '<table class=findtop><tr><td class=topleft>&nbsp;</td><td class=top>'.$lang['reg_register'].'</td><td class=topright>&nbsp;</td></tr></table>';
86 echo '</td></tr>';
87 echo '<tr><td>'.$lang['reg_name'].'</td><td><input type="text" name="account_name" maxlength="16" size="30" value="'.@$name.'"></td></tr>';
88 echo '<tr><td>'.$lang['reg_password'].'</td><td><input type="password" name="account_pass" maxlength="16" size="30"></td></tr>';
89 echo '<tr><td>E-Mail</td><td><input type="text" name="account_email" size="30" maxlength="32" value="'.@$email.'"></td></tr>';
90 echo '<tr><td class=bottom colspan=2><input type=submit value="'.$lang['reg_ok_register'].'"></td></tr>';
91 echo '</table>';
92 echo '</form>';
93 echo "<br>";