<?php
require "db.php";
require "psw.php";
$userip = $_SERVER['REMOTE_ADDR'];
$baseip = R::findOne('users', 'ip = ?', array($userip));
if (isset($baseip)) {
exit("Пользователь с таким ip уже зарегистрирован. Его ник ".$baseip['login'].". Обратитесь в поддержку vk.com/lototoclub.");
}
if (isset($_SESSION['captcha'])) {
$captcha = $_SESSION['captcha'];
}
else {
session_start();
function generateRandomString($length = 7) {
return substr(str_shuffle(str_repeat($x='0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', ceil($length/strlen($x)) )),1,$length);
}
$captcha = generateRandomString();
$_SESSION['captcha'] = $captcha;
}
$data = $_POST;
if (isset($data['do_signup'])) {
$errors = array();
if (trim($data['login']) == '') {
$errors[] = 'Введите логин!';
}
if (trim($data['captcha_check']) != $captcha) {
function generateRandomString($length = 7) {
return substr(str_shuffle(str_repeat($x='0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', ceil($length/strlen($x)) )),1,$length);
}
$captcha = generateRandomString();
$_SESSION['captcha'] = $captcha;
exit ('Введите верную капчу!');
}
else if (trim($data['captcha_check']) == '') {
function generateRandomString($length = 7) {
return substr(str_shuffle(str_repeat($x='0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', ceil($length/strlen($x)) )),1,$length);
}
$captcha = generateRandomString();
$_SESSION['captcha'] = $captcha;
exit ('Введите капчу!');
}
else {
if (strlen(trim($data['login'])) > 25) {
$errors[] = 'Ваш логин более 25 символов!';
}
if (trim($data['email']) == '') {
$errors[] = 'Введите Email!';
}
if (trim($data['password']) == '') {
$errors[] = 'Введите пароль!';
}
if (strlen(trim($data['password'])) > 30) {
$errors[] = 'Ваш пароль более 30 символов!';
}
if (strlen(trim($data['password_2'])) > 30) {
$errors[] = 'Ваш пароль более 30 символов!';
}
if (trim($data['password_2']) == '') {
$errors[] = 'Введите пароль повторно!';
}
if (R::count('users', "login = ?", array($data['login'])) > 0) {
$errors[] = 'Пользователь с таким логином уже зарегистрирован.';
}
if (R::count('users', "email = ?", array($data['email'])) > 0) {
$errors[] = 'Пользователь с таким Email уже зарегистрирован.';
}
if (trim($data['password']) != trim($data['password_2'])) {
$errors[] = 'Пароли не совпадают!';
}
if (empty($errors)) {
// Добавление в базу данных
$user = R::dispense('users');
$user->balance = 4;
$user->login = $data['login'];
$user->email = $data['email'];
$user->ip = $_SERVER['REMOTE_ADDR'];
$user->password = password_hash($data['password'], PASSWORD_DEFAULT);
R::store($user);
$_SESSION['logged_user'] = $user;
header("Location: index.php");
}
else {
$specificerror = array_shift($errors);
}
}
}
?>
<?php if (! isset($_SESSION['logged_user'])) : ?>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Lototo - быстрые ставки</title>
<link href="css/bootstrap.css" rel="stylesheet">
<link href="css/login.css" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Comfortaa" rel="stylesheet">
</head>
<body>
<center>
<div class="shape">
<p>
<?php if (! empty($errors)) { echo "<div class='error'>".$specificerror."</div>"; } ?>
<h1>Регистрация</h1><br><br>
<form action="signup.php" method="POST">
<p>
<input type="text" name="login" value="<?php echo @$data['login'] ?>" placeholder="Логин" maxlength="25">
</p>
<p>
<input type="email" name="email" value="<?php echo @$data['email'] ?>" placeholder="E-Mail">
</p>
<p>
<input type="password" name="password" value="<?php echo @$data['password'] ?>" placeholder="Пароль" maxlength="30">
</p>
<p>
<input type="password" name="password_2" value="<?php echo @$data['password_2'] ?>" placeholder="Повтор пароля" maxlength="30">
</p>
<br>
<p>
<input type="text" name="captcha_check" value="" placeholder="Код с картинки" maxlength="7">
</p>
<br>
<p>
<img src="http://via.placeholder.com/300x200/ffffff/?text=<?php echo $captcha; ?>" alt="Капча" width="200px" height="100px">
</p>
<p>
<button type="submit" name="do_signup" class="login">Создать аккаунт</button>
</p>
<p>
<a href="index.php">Вход в аккаунт</a>
</p>
</form>
</p>
</div>
</center>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
</body>
</html>
<?php else : ?>
<?php header("Location: index.php"); ?>
<?php endif; ?>