battles/register.php

51 lines
2.2 KiB
PHP
Raw Normal View History

<?php
use Battles\Template, Battles\Register;
require_once "config.php";
if ($_COOKIE[GAMEDOMAIN] ?? null) {
2018-01-28 16:40:49 +00:00
$error = "Не больше одной регистрации в час!";
} else {
$login = $_POST['login'] ?? null;
$password = isset($_POST['psw']) ? password_hash($_POST['psw'], PASSWORD_DEFAULT) : null;
$birthday = $_POST['birthday'] ?? null;
2018-01-28 16:40:49 +00:00
$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);
if ($login && $password && $email && $birthday && $law && $law2) {
$uid = Register::addUser($login, $password, $email, $birthday);
setcookie(GAMEDOMAIN, $uid, time() + 3600);
setcookie("battle", time());
$_SESSION['uid'] = $uid;
$_SESSION['sid'] = session_id();
header('Location: fight.php');
exit;
2018-01-28 16:40:49 +00:00
}
}
Template::header('Регистрация персонажа');
2018-01-28 16:40:49 +00:00
?>
<a href="/"> на главную</a>
<?php if (isset($error)): ?>
<h3><?= $error ?></h3>
2018-01-28 16:40:49 +00:00
<?php else: ?>
<h1>Регистрация</h1>
<form method="post">
<label>
<input required name="login" placeholder='Имя персонажа'> Имя персонажа.
</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>
<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">Я согласен на любые
условия, давайте играть!</label><br>
<input type=submit value=Зарегистрироваться>
</form>
<?php endif; ?>