<?
if ($user) {
	Redirection('/user/');
}
if (isset($_POST['login'], $_POST['password']) AND $_POST['password'] != null AND $_POST['login'] != null) {
	$login = $_POST['login'];
	$password = shif($_POST['password']);
	$userd = $sql->fetch("SELECT * FROM `users` where `login` = ? ", [$login]);
	$checkuser = $sql->rowCount("SELECT * FROM `users` where `password` = ? AND `login` = ? ", [$password, $login]);
	if ($checkuser == 0) {
		$err[] = 'Неверный логин или пароль';
	}
	if (!isset($err)) {
		$_SESSION['user_id'] = $userd['id'];
		cookie('user_id', $userd['id'], $set['user_cookie']);
		cookie('user_pass', $userd['password'], $set['user_cookie']);
		Redirection((isset($_SESSION['url']) ? $_SESSION['url'] : '/user/'));
	}	
}
if (isset($err)) {
	err($err);
}
$PageConfig = [
	'title' => 'Авторизация',
];

PageConfig($PageConfig);

echo $t->fetch('user.login');