<?php
define('_CONSTANT_', 1);
require_once '../../core/start.php';
checkIn();
head();
/* Image */
echo '<div class="headerImg"><img src="' . HOME . '/img/shadow.png" alt="[header-img]" height="70px"></div>';
if (isset($_POST['try'])) 
{
    $data = $_POST; 
    $data['login'] = $Filter->clearString($data['login']);
    $data['password'] = $Filter->clearString($data['password']);
    $data['password'] = crypt($data['password'], '$1$game$');
    
    if (empty($data['login']) || empty($data['password'])) 
    {
        errorNoExit('Ошибка авторизации.');
    } 
    else 
    {
        $sql = DB::$dbs->queryFetch("SELECT `id` FROM ".USERS." WHERE `login` = ? && `password` = ?", [$data['login'], $data['password']]);
        
        if ($sql) 
        {
            $_SESSION['id'] = $sql['id']; 
            setcookie("login", $data['login'], time()+9999999);
            setcookie("password", $data['password'], time()+9999999);
            header("Location:".HOME."/game/");
        } 
        else 
        {
            errorNoExit('Ошибка авторизации.');
        }
    }
} 
?> 
<form action="" method="POST">
    <br/>
    <input type="text" name="login" maxlength="15" placeholder="Введите логин"><br/><br/>
    <input type="password" name="password" maxlength="20" placeholder="Введите пароль"><br/><br/>
    <input type="submit" name="try" value="Войти">
</form>
<?php 
require_once '../../core/foot.php';