dev #38

Merged
lopar merged 22 commits from dev into master 2021-02-03 08:56:49 +00:00
1 changed files with 26 additions and 18 deletions
Showing only changes of commit 3d8803d67d - Show all commits

View File

@ -1,16 +1,15 @@
<?php <?php
use Battles\Template; use Battles\Template, Battles\Database\DBPDO;
session_start(); session_start();
require_once "config.php"; require_once "config.php";
if ($_COOKIE[GAMEDOMAIN] ?? null) { if ($_COOKIE[GAMEDOMAIN] ?? null) {
$error = "Не больше одной регистрации в час!"; $error = "Не больше одной регистрации в час!";
} else { } else {
$login = $_POST['login'] ?? null; $login = $_POST['login'] ?? null;
if ($_POST['psw'] ?? null) { $password = isset($_POST['psw']) ? password_hash($_POST['psw'], PASSWORD_DEFAULT) : null;
$password = password_hash($_POST['psw'], PASSWORD_DEFAULT);
}
$birthday = $_POST['birthday'] ?? null; $birthday = $_POST['birthday'] ?? null;
$email = filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL); $email = filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL);
$law = filter_input(INPUT_POST, 'law', FILTER_VALIDATE_BOOLEAN); $law = filter_input(INPUT_POST, 'law', FILTER_VALIDATE_BOOLEAN);
@ -21,20 +20,23 @@ if ($_COOKIE[GAMEDOMAIN] ?? null) {
$newUser = new class { $newUser = new class {
public static function addUser(string $login, string $password, string $email, string $birthday): bool public static function addUser(string $login, string $password, string $email, string $birthday): bool
{ {
if (db::c()->query('SELECT 1 FROM `users` WHERE `login` = "?s" OR `email` = "?s"', $login, $email)->getNumRows()) { $db = new DBPDO();
if ($db->ofetch('SELECT 1 FROM users WHERE login = ? OR email = ?', [$login, $email])) {
return false; return false;
} }
db::c()->query('INSERT INTO users (login,pass,email,borndate,ip,session_id,shadow) $db->execute('INSERT INTO users (login,pass,email,borndate,ip,session_id,shadow)
VALUES ("?s", "?s", "?s", "?s", "?s", "?s", "?s")', $login, $password, $email, $birthday, $_SERVER['REMOTE_ADDR'], session_id(), '0.gif'); VALUES (?,?,?,?,?,?,?)', [$login, $password, $email, $birthday, $_SERVER['REMOTE_ADDR'], session_id(), '0.gif']);
db::c()->query('INSERT INTO `online` (user_id, date, room, real_time) VALUES (?i, ?i, ?i, ?i)', db::c()->getLastInsertId(), time(), 1, time()); $userId = $db->lastInsertId();
db::c()->query('INSERT INTO `bank` (user_id) VALUES (?i)', db::c()->getLastInsertId()); $db->execute('INSERT INTO online (user_id, date, room, real_time) VALUES (?,?,1,?)', [$userId, time(), time()]);
setcookie(GAMEDOMAIN, db::c()->getLastInsertId(), time() + 3600); $db->execute('INSERT INTO bank (user_id) VALUES ?', $userId);
setcookie(GAMEDOMAIN, $userId, time() + 3600);
setcookie("battle", time()); setcookie("battle", time());
$_SESSION['uid'] = db::c()->getLastInsertId(); $_SESSION['uid'] = $userId;
$_SESSION['sid'] = session_id(); $_SESSION['sid'] = session_id();
return true; return true;
} }
}; };
$newUser::addUser($login, $password, $email, $birthday); $newUser::addUser($login, $password, $email, $birthday);
header('Location: fight.php'); header('Location: fight.php');
exit; exit;
@ -43,19 +45,25 @@ if ($_COOKIE[GAMEDOMAIN] ?? null) {
Template::header('Регистрация персонажа'); Template::header('Регистрация персонажа');
?> ?>
<a href="/"> на главную</a> <a href="/"> на главную</a>
<?php if ($error ?? null): ?> <?php if (isset($error)): ?>
<h1><?= $error ?></h1> <h3><?= $error ?></h3>
<?php else: ?> <?php else: ?>
<h1>Регистрация</h1> <h1>Регистрация</h1>
<form method="post"> <form method="post">
<input required name="login" placeholder='Имя персонажа'><br> <label>
<input required name="email" type=email placeholder='Электронная почта'><br> <input required name="login" placeholder='Имя персонажа'> Имя персонажа.
<input required name="psw" type=text placeholder='Пароль'><br> </label><br>
<label>
<input required name="email" type=email placeholder='Электронная почта'> Электронная почта.
</label><br>
<label>
<input required name="psw" type=text placeholder='Пароль'> Пароль.
</label><br>
<label for="bday">Дата рождения:</label><br> <label for="bday">Дата рождения:</label><br>
<input required id="bday" name="birthday" type='date' min=1970-01-01 max=2010-01-01><br> <input required id="bday" name="birthday" type='date' min=1970-01-01 max=2010-01-01><br>
<input required id="law" name="law" type=checkbox> <label for="law">Это мой единственный персонаж!</label><br> <input required id="law" name="law" type=checkbox> <label for="law">Это мой единственный персонаж!</label><br>
<input required id="law2" name="law2" type=checkbox> <label for="law2">Я согласен на <a href='#'>любые <input required id="law2" name="law2" type=checkbox> <label for="law2">Я согласен на любые
условия</a>, давайте играть!</label><br> условия, давайте играть!</label><br>
<input type=submit value=Зарегистрироваться> <input type=submit value=Зарегистрироваться>
</form> </form>
<?php endif; ?> <?php endif; ?>