game/repass.php

142 lines
6.1 KiB
PHP
Raw Normal View History

<?php
2022-12-19 20:16:24 +00:00
2022-12-30 19:03:37 +00:00
use Core\{Config, Database, Db};
use User\UserIp;
2022-12-19 20:16:24 +00:00
if (!defined('GAME_VERSION')) {
require_once '_incl_data/autoload.php';
}
2022-06-06 21:30:34 +00:00
$step = 1;
$error = '';
2022-12-30 19:03:37 +00:00
Config::init();
Database::init();
2022-06-06 21:30:34 +00:00
if (isset($_GET['login'])) {
$_POST['relogin'] = $_GET['login'];
2022-06-06 21:30:34 +00:00
}
if (isset($_POST['relogin'])) {
$_POST['relogin'] = htmlspecialchars($_POST['relogin'], null);
$u = User::start();
2022-12-19 20:16:24 +00:00
2022-12-30 19:03:37 +00:00
$usr = Db::getRow('select * from users where login =?', [$_POST['relogin']]);
if (!isset($usr['id'])) {
$error = 'Логин "' . htmlspecialchars($_POST['relogin'], null) . '" не найден в базе.';
2022-12-30 19:03:37 +00:00
} else {
if ($usr['admin'] != 0 || $usr['banned'] != 0) {
2023-01-10 16:29:32 +00:00
$error = 'Персонаж "' . $_POST['relogin'] . '" заблокирован!';
2022-12-30 19:03:37 +00:00
} else {
$step = 2;
if (isset($_POST['redate'])) {
2023-01-10 16:29:32 +00:00
//Третий шаг
2022-12-30 19:03:37 +00:00
$lst_psw = Db::getValue(
'select count(*) from repass where uid = ? and time > unix_timestamp() - 24 * 60 * 60 and type = 1',
[$usr['id']]
2022-12-19 20:16:24 +00:00
);
2022-12-30 19:03:37 +00:00
if ($lst_psw) {
2023-01-10 16:29:32 +00:00
$error = 'Высылать пароль можно не более одного раза в сутки.';
} elseif (
str_replace('0', '', date('d.m.Y', strtotime($_POST['redate']))) == str_replace('0', '', $usr['bithday'])
) {
2022-12-30 19:03:37 +00:00
$re = Db::getValue(
'select count(*) from logs_auth where uid = ? and type = 0 and depass != ?',
[$usr['id'], '']
2022-12-19 20:16:24 +00:00
);
if ($usr['securetime'] < Config::get('securetime')) {
unset($re);
}
2023-01-12 03:38:48 +00:00
if (!empty($re)) {
2022-12-30 19:03:37 +00:00
$newPassword = PassGen::new();
2023-01-10 16:29:32 +00:00
$title = 'Восстановление пароля от "' . $usr['login'] . '".';
$txt = 'Добрый день.<br>';
$txt .= 'С IP-адреса - <b>' . UserIp::get() . '</b>, был запрошен пароль для вашего персонажа.<br>Если это не Вы, просто удалите это письмо.<br><br>';
2023-01-10 16:29:32 +00:00
$txt .= 'Ваш логин: <b>' . $usr['login'] . '</b><br>';
$txt .= 'Ваш пароль: ' . $newPassword . '<br><br>';
$txt .= 'Отвечать на данное письмо не нужно.<br><br>';
$txt .= 'С уважением,<br>';
$txt .= 'Администрация Бойцовского Клуба';
$mail = Helper\Mail::send($usr['mail'], $txt, $title);
2022-12-30 19:03:37 +00:00
if ($mail === 1) {
Db::sql(
'update users set securetime = unix_timestamp(), allLock = unix_timestamp(), pass = ? where id = ?',
[password_hash($newPassword, PASSWORD_DEFAULT), $usr['id']]
2022-12-30 19:03:37 +00:00
);
Db::sql(
'insert into repass (uid, time, ip, type) values (?,unix_timestamp(),?,1)',
[$usr['id'], UserIp::get()]
);
$step = 3;
} else {
$error = $mail;
}
unset($mail);
2023-01-12 03:38:48 +00:00
$error = '<br><br><br>Пароль от персонажа &quot;' . $usr['login'] . '&quot; был успешно выслан на E-mail указанный при регистрации! <br><br><br>';
}
} else {
2023-01-10 16:29:32 +00:00
$error = 'Неверно указан день рождения.';
}
}
}
}
}
2022-06-06 21:30:34 +00:00
?>
<!DOCTYPE html>
<html lang="ru-RU">
<head>
2023-01-10 16:29:32 +00:00
<title><?= Config::get('name') ?>: Восстановление пароля от персонажа</title>
2022-12-30 19:03:37 +00:00
<meta name="keywords" content="<?= Config::get('keys') ?>">
<meta name="description" content="<?= Config::get('desc') ?>"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
2022-12-30 19:03:37 +00:00
<link type="text/css" rel="stylesheet" href="stylen.css"/>
<style>
input[type=text], input[type=date] {
padding: 3px;
}
div.content, div.after {
display: flex;
justify-content: center;
}
div.content {
align-items: center;
flex-direction: column;
height: 50%;
}
2022-12-30 19:03:37 +00:00
</style>
2022-06-06 21:30:34 +00:00
</head>
<body>
2022-12-30 19:03:37 +00:00
<form method="post" id="repass"></form>
<div class="content">
2023-01-10 16:29:32 +00:00
<h1>Восстановление пароля</h1>
2022-12-30 19:03:37 +00:00
<?= $error ? '<b style="color: red">' . $error . '</b>' : '' ?>
<?php if ($step === 1): ?>
2023-01-10 16:29:32 +00:00
<label for="relogin">Укажите логин персонажа:</label>
<input form="repass" placeholder="Логин" maxlength="30" name="relogin" type="text" class="inup" id="relogin">
2022-12-30 19:03:37 +00:00
<br>
2023-01-10 16:29:32 +00:00
<input form="repass" type="submit" class="btn" value="Перейти к следующему шагу">
2022-12-30 19:03:37 +00:00
<?php elseif ($step === 2): ?>
2023-01-10 16:29:32 +00:00
<label for="relogin">Логин персонажа:</label>
2022-12-30 19:03:37 +00:00
<input form="repass" maxlength="30" name="relogin" type="text" class="inup" value="<?= $_POST['relogin'] ?>" id="relogin">
<br>
2023-01-10 16:29:32 +00:00
<label for="redate">День рождения:</label>
2022-12-30 19:03:37 +00:00
<input form="repass" name="redate" type="date" class="inup" id="redate"><br>
2023-01-10 16:29:32 +00:00
<small class="testro">(день рождения вы указывали при регистрации персонажа в формате
2022-12-30 19:03:37 +00:00
dd.mm.yyyy)</small><br>
2023-01-10 16:29:32 +00:00
<input form="repass" type="submit" class="btn" value="Выслать пароль на E-mail">
2022-12-30 19:03:37 +00:00
<?php endif; ?>
</div>
<div class="after">
2023-01-10 16:29:32 +00:00
<a href="<?= Config::get('https') ?>">Вернутся на главную страницу</a>
2022-12-30 19:03:37 +00:00
</div>
<div class="after">
<span class="testro"><?= Config::get('footer') ?></span>
2022-12-30 19:03:37 +00:00
</div>
2022-06-06 21:30:34 +00:00
</body>
</html>