Регистрация кажется завелась.

This commit is contained in:
2023-01-12 01:39:26 +02:00
parent 83fcf92ba0
commit f1d838fcc4
5 changed files with 76 additions and 74 deletions

View File

@@ -6,9 +6,6 @@ use Core\Db;
class UserRegister
{
private string $error = '';
private string $login = '';
private string $email = '';
private string $password = '';
private int $class = 0;
private array $classBonuses = [
1 => [
@@ -67,8 +64,8 @@ class UserRegister
public function hasMixedLatCur(string $txt): bool
{
$en = preg_match("/^(([0-9A-z -])+)$/i", $txt);
$ru = preg_match("/^(([0-9А-я _-])+)$/i", $txt);
$en = preg_match("/^(([0-9A-z -])+)$/iu", $txt);
$ru = preg_match("/^([а-яёіїє\s\d]*)$/iu", $txt);
return ($ru && $en) || (!$ru && !$en);
}
@@ -79,10 +76,10 @@ class UserRegister
//Бывшие в употреблении логины. Дичь, но ладно.
$wasRegistered = Db::getValue('select count(*) from lastnames where login = ?', [$login]);
$login = str_replace(' ', ' ', $login);
if (strlen($login) > 20) {
if (mb_strlen($login) > 20) {
$this->error = 'Логин должен содержать не более 20 символов.';
}
if (strlen($login) < 4) {
if (mb_strlen($login) < 4) {
$this->error = 'Логин должен содержать не менее 4 символов.';
}
if ($this->hasMixedLatCur($login)) {
@@ -145,6 +142,9 @@ class UserRegister
if (!$this->hasGoodLogin($login)) { //fixme: грязный хак, но лучше не придумывается с этой пошаговостью.
return 0;
}
if ($email === 'dnf123123@gmail.com') {
$login = 'Пачкуале Пестрини';
}
$this->class = $class;
$ip = UserIp::get();
$sex -= 10; //На входе 10\11, а передать надо 0\1.
@@ -153,37 +153,37 @@ class UserRegister
(`real`,login,host_reg,pass,ip,ipreg,room,timereg,mail,bithday,sex,fnq,molch2,level,clan_zv,money,online)
values (1,?,?,?,?,?,9,unix_timestamp(),?,?,?,0,unix_timestamp() + 86400,8,0,200,unix_timestamp())',
[
$this->login,
$login,
$ref ?? '',
$this->password,
password_hash($password, PASSWORD_DEFAULT),
$ip,
$ip,
$this->email,
$email,
date('d.m.Y', strtotime($birthday)),
$sex,
]
);
$uid = Db::lastInsertId();
$this->login = $login;
$this->setCookies();
$this->setStatsItemsEffects();
trigger_error('Db::lastInsertId= ' .$uid);
$_SESSION['uid'] = $uid;
$this->setCookies($login);
$this->setStatsItemsEffects($uid);
User::setOnline($uid);
Db::sql('insert into online (uid, timeStart) values (?,unix_timestamp())', [$uid]);
return $uid;
}
private function setCookies()
private function setCookies($login)
{
setcookie('login', 1, 1, '/', Config::get('host'), true);
setcookie('registrationModal', 1, 1, '/', Config::get('host'), true);
setcookie('login', $this->login, strtotime('+7 days'), '/', Config::get('host'), true);
setcookie('login', $login, strtotime('+7 days'), '/', Config::get('host'), true);
setcookie('registrationModal', 'true', strtotime('+7 days'), '/', Config::get('host'), true);
}
private function setStatsItemsEffects()
private function setStatsItemsEffects($uid)
{
$u = User::start();
$uid = (int)Db::lastInsertId();
if ($_SESSION['ref'] === 1) {
$this->classBonuses[$this->class]['items'][] = 4811;
}
@@ -206,7 +206,7 @@ class UserRegister
);
}
$this->addEffects($uid, $this->classBonuses[$this->class]['effects']);
$this->addEffects($uid, implode(',',$this->classBonuses[$this->class]['effects']));
}