battles/register.php

61 lines
3.1 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
use Battles\Template;
session_start();
require_once "config.php";
if ($_COOKIE[GAMEDOMAIN] ?? null) {
$error = "Не больше одной регистрации в час!";
} else {
$login = $_POST['login'] ?? null;
if ($_POST['psw'] ?? null) {
$password = password_hash($_POST['psw'], PASSWORD_DEFAULT);
}
$birthday = $_POST['birthday'] ?? null;
$email = filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL);
$law = filter_input(INPUT_POST, 'law', FILTER_VALIDATE_BOOLEAN);
$law2 = filter_input(INPUT_POST, 'law2', FILTER_VALIDATE_BOOLEAN);
$ip = filter_input(INPUT_SERVER, 'REMOTE_ADDR', FILTER_VALIDATE_IP);
if ($login && $password && $email && $birthday && $law && $law2) {
$newUser = new class {
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()) {
return false;
}
db::c()->query('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');
db::c()->query('INSERT INTO `online` (user_id, date, room, real_time) VALUES (?i, ?i, ?i, ?i)', db::c()->getLastInsertId(), time(), 1, time());
db::c()->query('INSERT INTO `bank` (user_id) VALUES (?i)', db::c()->getLastInsertId());
setcookie(GAMEDOMAIN, db::c()->getLastInsertId(), time() + 3600);
setcookie("battle", time());
$_SESSION['uid'] = db::c()->getLastInsertId();
$_SESSION['sid'] = session_id();
return true;
}
};
$newUser::addUser($login, $password, $email, $birthday);
header('Location: fight.php');
exit;
}
}
Template::header('Регистрация персонажа');
?>
<a href="/"> ← на главную</a>
<?php if ($error ?? null): ?>
<h1><?= $error ?></h1>
<?php else: ?>
<h1>Регистрация</h1>
<form method="post">
<input required name="login" placeholder='Имя персонажа'><br>
<input required name="email" type=email placeholder='Электронная почта'><br>
<input required name="psw" type=text placeholder='Пароль'><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="law" name="law" type=checkbox> <label for="law">Это мой единственный персонаж!</label><br>
<input required id="law2" name="law2" type=checkbox> <label for="law2">Я согласен на <a href='#'>любые
условия</a>, давайте играть!</label><br>
<input type=submit value=Зарегистрироваться>
</form>
<?php endif; ?>