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

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
+24 -5
View File
@@ -1879,8 +1879,27 @@ FROM `items_users` AS `iu` LEFT JOIN `items_main` AS `im` ON (`im`.`id` = `iu`.`
private function __construct()
{
$this->info = Db::getRow(
'select
if (!empty($_SESSION['uid'])) {
$this->info = Db::getRow(
'select
*,
users.id as id,
users.level as level,
users.align as align,
users.sex as sex,
users.clan as clan,
stats.timeGo as timeGo,
users.name as name,
stats.lider as lider
from users
left join stats on users.id = stats.id
left join room on users.room = room.id
where users.id = ?',
[$_SESSION['uid']]
);
} else {
$this->info = Db::getRow(
'select
*,
users.id as id,
users.level as level,
@@ -1894,9 +1913,9 @@ FROM `items_users` AS `iu` LEFT JOIN `items_main` AS `im` ON (`im`.`id` = `iu`.`
left join stats on users.id = stats.id
left join room on users.room = room.id
where login = ?',
[$_COOKIE['login']]
);
[$_COOKIE['login']]
);
}
Database::init(); // для всяких mysql_*
$this->infoTasks();
+13 -1
View File
@@ -5,6 +5,7 @@ namespace User;
use Core\Config;
use Core\Db;
use Core\Mail;
use PassGen;
use UserIp;
class Confirmation
@@ -78,6 +79,17 @@ class Confirmation
);
}
public static function userRegistrationCodeByEmail(string $email, string $login)
{
$code = PassGen::intCode(4);
Db::sql('insert into secure_code (email, code, time) values (?,?,unix_timestamp())', [$email, $code]);
Mail::send(
$email,
'Секретный Код: ' . $code,
'Код подтверждения регистрации персонажа ' . $login
);
}
public static function byCode(int $uid, int $code): string
{
$status = '';
@@ -117,4 +129,4 @@ class Confirmation
}
return $status;
}
}
}
+18 -18
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']));
}