From 2590d62f1f4ac9b6ce8a212995d825b5be429ca8 Mon Sep 17 00:00:00 2001 From: Ivor Barhansky Date: Tue, 10 Jan 2023 20:13:19 +0200 Subject: [PATCH] registration bug --- _incl_data/class/UserRegister.php | 32 +++++++++---------------------- register.php | 3 +++ 2 files changed, 12 insertions(+), 23 deletions(-) diff --git a/_incl_data/class/UserRegister.php b/_incl_data/class/UserRegister.php index b5505237..9dfc3fb4 100644 --- a/_incl_data/class/UserRegister.php +++ b/_incl_data/class/UserRegister.php @@ -97,11 +97,8 @@ class UserRegister if ($isRegistered || $wasRegistered || $isRestricted) { $this->error = 'Логин ' . $login . ' уже занят, выберите другой.'; } - if (!$this->error) { - $this->login = $login; - return true; - } - return false; + + return !$this->error; } public function hasGoodEmail(string $email): bool @@ -118,11 +115,7 @@ class UserRegister if (!in_array(explode('@', $email)[1], $allowedDomains)) { $this->error = 'Данный почтовый сервис использовать нельзя.'; } - if (!$this->error) { - $this->email = $email; - return true; - } - return false; + return !$this->error; } public function hasGoodEmailCode(string $email, int $code): bool @@ -144,25 +137,17 @@ class UserRegister if (strlen($password1) < 8) { $this->error = 'Пароль должен быть больше 8 символов'; } - if (!$this->error) { - $this->password = password_hash($password1, PASSWORD_DEFAULT); - return true; - } - return false; + return !$this->error; } - public function new($ref, $birthday, int $sex, int $class): string + public function new(string $login, string $password, string $email, $ref, $birthday, int $sex, int $class): string { - if (!$this->login || - !$this->password || - !$this->email || - !in_array($sex, [10, 11]) || - !in_array($class, range(1, 9))) { + if (!$this->hasGoodLogin()) { return 0; } $this->class = $class; $ip = UserIp::get(); - $sex = (int)$sex - 10; //На входе 10\11, а передать надо 0\1. + $sex -= 10; //На входе 10\11, а передать надо 0\1. Db::sql( 'insert into users (`real`,login,host_reg,pass,ip,ipreg,room,timereg,mail,bithday,sex,fnq,molch2,level,clan_zv,money,online) @@ -179,6 +164,7 @@ class UserRegister ] ); $uid = Db::lastInsertId(); + $this->login = $login; $this->setCookies(); $this->setStatsItemsEffects(); User::setOnline($uid); @@ -190,7 +176,7 @@ class UserRegister { setcookie('login', 1, 1, '/', Config::get('host'), true); setcookie('registrationModal', 1, 1, '/', Config::get('host'), true); - setrawcookie('login', $this->login, strtotime('+7 days'), '/', Config::get('host'), true); + setcookie('login', $this->login, strtotime('+7 days'), '/', Config::get('host'), true); setcookie('registrationModal', 'true', strtotime('+7 days'), '/', Config::get('host'), true); } diff --git a/register.php b/register.php index 040c0e91..a5bc9112 100644 --- a/register.php +++ b/register.php @@ -89,6 +89,9 @@ if ($_SESSION['step'] === 8) { // Всех их соберём, вместе с //Создаем персонажа $uid = $newUser->new( + $_SESSION['login'], + $_SESSION['password'], + $_SESSION['email'], $_SESSION['ref'], $_SESSION['birthday'], $_SESSION['sex'],