dev-cookie-to-id #37

Merged
lopar merged 11 commits from dev-cookie-to-id into dev 2023-01-12 03:41:15 +00:00
5 changed files with 76 additions and 74 deletions
Showing only changes of commit f1d838fcc4 - Show all commits

View File

@ -1879,8 +1879,27 @@ FROM `items_users` AS `iu` LEFT JOIN `items_main` AS `im` ON (`im`.`id` = `iu`.`
private function __construct() private function __construct()
{ {
$this->info = Db::getRow( if (!empty($_SESSION['uid'])) {
'select $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.id as id,
users.level as level, 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 stats on users.id = stats.id
left join room on users.room = room.id left join room on users.room = room.id
where login = ?', where login = ?',
[$_COOKIE['login']] [$_COOKIE['login']]
); );
}
Database::init(); // для всяких mysql_* Database::init(); // для всяких mysql_*
$this->infoTasks(); $this->infoTasks();

View File

@ -5,6 +5,7 @@ namespace User;
use Core\Config; use Core\Config;
use Core\Db; use Core\Db;
use Core\Mail; use Core\Mail;
use PassGen;
use UserIp; use UserIp;
class Confirmation 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 public static function byCode(int $uid, int $code): string
{ {
$status = ''; $status = '';
@ -117,4 +129,4 @@ class Confirmation
} }
return $status; return $status;
} }
} }

View File

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

View File

@ -119,22 +119,6 @@ $u = Db::getRow(
); );
$auth = Db::getValue('select id from logs_auth where uid = ? and ip = ?', [$u['id'], IP]); $auth = Db::getValue('select id from logs_auth where uid = ? and ip = ?', [$u['id'], IP]);
if (
Config::get('securetime') > 0 &&
IP != $u['ip'] &&
IP != $u['ipreg'] &&
!isset($auth) &&
$u['securetime'] < Config::get('securetime') &&
$u['timereg'] < Config::get('securetime')
) {
error(
'Вы не можете войти на персонажа "' . $_POST['login'] . '".<br>
Скорее всего вы давно не меняли пароль.
Для смены перейдите по ссылке: <a href="/repass.php?login=' . $u['login'] . '">СМЕНА ПАРОЛЯ</a><br><br>
Вам необходимо сменить пароль для безопасности персонажа,
на почту по которой зарегистрирован персонаж придет новый случайно сгенерированный пароль.'
);
}
if (!isset($u['id'])) { if (!isset($u['id'])) {
error('Логин "' . $_POST['login'] . '" не найден в базе.'); error('Логин "' . $_POST['login'] . '" не найден в базе.');
@ -145,8 +129,8 @@ if (!isset($u['id'])) {
} elseif (!checkPassword($_POST['pass'], $u['pass'], $u['login'])) { } elseif (!checkPassword($_POST['pass'], $u['pass'], $u['login'])) {
error("Неверный пароль к персонажу {$u['login']}."); error("Неверный пароль к персонажу {$u['login']}.");
Db::sql( Db::sql(
'insert into logs_auth (uid, ip, browser, type, time, depass) values (?,?,?,3,unix_timestamp(),?)', 'insert into logs_auth (uid, ip, browser, type, time) values (?,?,?,3,unix_timestamp())',
[$u['id'], IP, $_SERVER['HTTP_USER_AGENT'], $_POST['pass']] [$u['id'], IP, $_SERVER['HTTP_USER_AGENT']]
); );
} else { } else {
@ -164,7 +148,6 @@ if (!isset($u['id'])) {
$koko = 'Неверный второй пароль<br>'; $koko = 'Неверный второй пароль<br>';
} }
setcookie('login', '', time() - 60 * 60 * 24, '', Config::get('host')); setcookie('login', '', time() - 60 * 60 * 24, '', Config::get('host'));
setcookie('pass', '', time() - 60 * 60 * 24, '', Config::get('host'));
} }
if ($koko) { if ($koko) {
@ -318,33 +301,15 @@ if (!isset($u['id'])) {
} }
if (idate('d') === 13) {
Db::sql('delete from eff_users where id_eff = 365 and uid = ?', [$u['id']]);
Db::sql(
'insert into eff_users (id_eff, uid, name, data, overType, timeUse, no_Ace) values (365,?,?,?,47,unix_timestamp(),1)',
[
$u['id'],
'День Рождения Клуба',
'add_speedhp=500|add_speedmp=500|add_speed_dungeon=50|add_repair_discount=1|',
]
);
$chat->send(
'', $u['room'], $u['city'], '', $u['login'],
'В честь дня рождения проекта вы получаете эффект &quot;День Рождения Клуба&quot;!(Эффект обновляется каждый раз когда вы заходите на персонажа)',
time(), 6, 0, 0, 0, 1
);
}
if (isset($_COOKIE['ip']) && $_COOKIE['ip'] != IP) { if (isset($_COOKIE['ip']) && $_COOKIE['ip'] != IP) {
Db::sql( Db::sql(
'insert into logs_auth (uid, ip, browser, type, time, depass) VALUES (?,?,?,1,unix_timestamp(),?)', 'insert into logs_auth (uid, ip, browser, type, time) VALUES (?,?,?,1,unix_timestamp())',
[$u['id'], $_COOKIE['ip'], $_SERVER['HTTP_USER_AGENT'], md5($_POST['pass'])] [$u['id'], $_COOKIE['ip'], $_SERVER['HTTP_USER_AGENT']]
); );
} }
setcookie('login', $_POST['login'], time() + 60 * 60 * 24 * 7, '', Config::get('host')); setcookie('login', $_POST['login'], time() + 60 * 60 * 24 * 7, '', Config::get('host'));
setcookie('pass', $u['pass'], time() + 60 * 60 * 24 * 7, '', Config::get('host'));
setcookie('ip', IP, time() + 60 * 60 * 24 * 150, ''); setcookie('ip', IP, time() + 60 * 60 * 24 * 150, '');
if ($u['online'] < time() - 520) { if ($u['online'] < time() - 520) {
@ -396,18 +361,16 @@ if (!isset($u['id'])) {
} }
mysql_query( Db::sql('insert into logs_auth (uid, ip, browser, time) values (?,?,?,unix_timestamp())', [
"INSERT INTO `logs_auth` (`uid`,`ip`,`browser`,`type`,`time`,`depass`) VALUES ('" . $u['id'] . "','" . IP . "','" . $u['id'], IP, $_SERVER['HTTP_USER_AGENT']
$_SERVER['HTTP_USER_AGENT'] . "','0','" . time() . "','" . mysql_real_escape_string(md5($_POST['pass'])) . "')" ]);
);
mysql_query( mysql_query(
"UPDATE `users` SET " . $apu . "`ip`='" . $ipnew . "',`dateEnter`='" . $_SERVER['HTTP_USER_AGENT'] . "UPDATE `users` SET " . $apu . "`ip`='" . $ipnew . "',`dateEnter`='" . $_SERVER['HTTP_USER_AGENT'] .
"',`online`='" . time() . "' WHERE `login` = '" . mysql_real_escape_string($_POST['login']) . "',`online`='" . time() . "' WHERE `id` = " . $u['id']
"' AND `pass` = '" . mysql_real_escape_string(md5($_POST['pass'])) . "' LIMIT 1"
); );
$_SESSION['uid'] = $u['id'];
header('location: /bk'); header('location: /bk');
} }

View File

@ -100,7 +100,15 @@ if ($_SESSION['step'] === 8) { // Всех их соберём, вместе с
); );
if ($uid > 0) { if ($uid > 0) {
unset(
$_SESSION['login'],
$_SESSION['password'],
$_SESSION['email'],
$_SESSION['ref'],
$_SESSION['birthday'],
$_SESSION['sex'],
$_SESSION['class']
);
//мульты //мульты
$ppl = Db::getRows('select * from logs_auth where ip = ? or ip = ?', [UserIp::get(), $_COOKIE['ip']]); $ppl = Db::getRows('select * from logs_auth where ip = ? or ip = ?', [UserIp::get(), $_COOKIE['ip']]);
@ -122,10 +130,10 @@ if ($_SESSION['step'] === 8) { // Всех их соберём, вместе с
//Обновяем таблицы //Обновяем таблицы
Db::sql('update users set ip = ? where id = ?', [UserIp::get(), $uid]); Db::sql('update users set ip = ? where id = ?', [UserIp::get(), $uid]);
Db::sql('insert into users_learning_status (uid) values (?)', [$uid]); Db::sql('insert into users_learning_status (uid) values (?)', [$uid]);
session_unset();
header('Refresh: 1; url=/bk'); header('Refresh: 1; url=/bk');
die('Спасибо за регистрацию в игровом мире Бойцовского Клуба, желаем вам побед и долгой игры. die(
'Спасибо за регистрацию в игровом мире Бойцовского Клуба, желаем вам побед и долгой игры.
В случае вопросов по игре, Вам будет доступен общий чат!' В случае вопросов по игре, Вам будет доступен общий чат!'
); );
} }
@ -138,7 +146,7 @@ $errorMessage = $newUser->getError() ? "<h4>{$newUser->getError()}</h4>" : '';
<!DOCTYPE html> <!DOCTYPE html>
<head> <head>
<title><?= Config::get('name') ?>: Регистрация - создай персонажа в игре.</title> <title><?= Config::get('name') ?>: Регистрация - создай персонажа в игре.</title>
<meta name="description" content="<?= Config::get('desc') ?>"/> <meta name="description" content="<?= Config::get('desc') ?>"/>
</head> </head>