This commit is contained in:
2023-11-02 15:57:39 +02:00
parent a14232a899
commit def933dca4
51 changed files with 8866 additions and 12429 deletions
+41 -42
View File
@@ -64,43 +64,6 @@ class Register
'Милосердие', 'Справедливость', 'Искушение', 'Вознесение',
];
public function hasMixedLatCur(string $txt): bool
{
$en = preg_match("/^(([0-9A-z -])+)$/iu", $txt);
$ru = preg_match("/^([а-яёіїє\s\d]*)$/iu", $txt);
return ($ru && $en) || (!$ru && !$en);
}
public function hasGoodLogin(string $login): bool
{
$isRestricted = in_array($login, $this->restrictedLogins);
$isRegistered = Db::getValue('select count(*) from users where login = ?', [$login]);
//Бывшие в употреблении логины. Дичь, но ладно.
$wasRegistered = Db::getValue('select count(*) from lastnames where login = ?', [$login]);
$login = str_replace(' ', ' ', $login);
if (mb_strlen($login) > 20) {
$this->error = 'Логин должен содержать не более 20 символов.';
}
if (mb_strlen($login) < 4) {
$this->error = 'Логин должен содержать не менее 4 символов.';
}
if ($this->hasMixedLatCur($login)) {
$this->error = 'В логине разрешено использовать только буквы одного алфавита русского или английского. Нельзя смешивать.';
}
if (substr_count($login, ' ') + substr_count($login, '-') + substr_count($login, '_') > 2) {
$this->error = 'Не более двух разделителей одновременно (пробел, тире, нижнее подчеркивание).';
}
if (!empty($this->error)) {
$this->error .= '<br>Пример правильного никнейма: Петя Убиватор, Коля, xalop.<br>Пример неправильного никнейма: )))), kolя)=-/.';
}
if ($isRegistered || $wasRegistered || $isRestricted) {
$this->error = 'Логин ' . $login . ' уже занят, выберите другой.';
}
return !$this->error;
}
public function hasGoodEmail(string $email): bool
{
$isRegistered = Db::getValue('select count(*) from users where mail = ?', [$email]);
@@ -167,7 +130,7 @@ class Register
]
);
$uid = Db::lastInsertId();
trigger_error('Db::lastInsertId= ' . $uid);
//trigger_error('Db::lastInsertId= ' . $uid);
$_SESSION['uid'] = $uid;
$this->setCookies($login);
$this->setStatsItemsEffects($uid);
@@ -176,7 +139,43 @@ class Register
return $uid;
}
private function setCookies($login)
public function hasGoodLogin(string $login): bool
{
$isRestricted = in_array($login, $this->restrictedLogins);
$isRegistered = Db::getValue('select count(*) from users where login = ?', [$login]);
//Бывшие в употреблении логины. Дичь, но ладно.
$wasRegistered = Db::getValue('select count(*) from lastnames where login = ?', [$login]);
$login = str_replace(' ', ' ', $login);
if (mb_strlen($login) > 20) {
$this->error = 'Логин должен содержать не более 20 символов.';
}
if (mb_strlen($login) < 4) {
$this->error = 'Логин должен содержать не менее 4 символов.';
}
if ($this->hasMixedLatCur($login)) {
$this->error = 'В логине разрешено использовать только буквы одного алфавита русского или английского. Нельзя смешивать.';
}
if (substr_count($login, ' ') + substr_count($login, '-') + substr_count($login, '_') > 2) {
$this->error = 'Не более двух разделителей одновременно (пробел, тире, нижнее подчеркивание).';
}
if (!empty($this->error)) {
$this->error .= '<br>Пример правильного никнейма: Петя Убиватор, Коля, xalop.<br>Пример неправильного никнейма: )))), kolя)=-/.';
}
if ($isRegistered || $wasRegistered || $isRestricted) {
$this->error = 'Логин ' . $login . ' уже занят, выберите другой.';
}
return !$this->error;
}
public function hasMixedLatCur(string $txt): bool
{
$en = preg_match("/^(([0-9A-z -])+)$/iu", $txt);
$ru = preg_match("/^([а-яёіїє\s\d]*)$/iu", $txt);
return ($ru && $en) || (!$ru && !$en);
}
private function setCookies($login): void
{
setcookie('login', 1, 1, '/', Config::get('host'), true);
setcookie('registrationModal', 1, 1, '/', Config::get('host'), true);
@@ -184,7 +183,7 @@ class Register
setcookie('registrationModal', 'true', strtotime('+7 days'), '/', Config::get('host'), true);
}
private function setStatsItemsEffects($uid)
private function setStatsItemsEffects($uid): void
{
if ($_SESSION['ref'] === 1) {
$this->classBonuses[$this->class]['items'][] = 4811;
@@ -203,7 +202,7 @@ class Register
$itemId = ItemsModel::addItem($item, $uid);
Db::sql(
'update items_users
set `1price` = (select price_1 from items_main where items_main.item_id = ? and sid = 1)
set `1price` = (select price1 from items_main where id = ?)
where id = ?',
[$item, $itemId]
);
@@ -213,7 +212,7 @@ class Register
}
private function addEffects(int $uid, int ...$eids)
private function addEffects(int $uid, int ...$eids): void
{
$in = implode(',', $eids);
$q =