Выброс ошибок.

This commit is contained in:
Igor Barkov (iwork) 2020-08-27 15:53:01 +03:00
parent af20137f99
commit 0271b1d4fc
1 changed files with 9 additions and 6 deletions

View File

@ -1,7 +1,10 @@
<?php
session_start();
include("config.php");
define('ERROR_NO_SUCH_USER', 'Такого пользователя не существует!');
define('ERROR_USER_IS_BLOCKED', 'Пользователь заблокирован!');
define('ERROR_WRONG_PASSWORD', 'Неверный пароль!');
define('ERROR_EMPTY_CREDENTIALS', 'Вы не ввели логин или пароль!');
foreach ($_POST as $key => $val) { //Проверка всех значений массива POST одним махом.
$_POST[$key] = iconv(mb_detect_encoding($_POST[$key], 'auto'), 'utf-8', $val);
}
@ -15,9 +18,9 @@ if ($username && $password) {
$user_query = db::c()->query('SELECT `id`, `login` ,`pass`, `room`, `block` FROM `users` WHERE `login` = "?s"', $username)->fetch_assoc();
if (!$user_query['id']) {
$error = 'Ой! Такого пользователя нет!';
$error = ERROR_NO_SUCH_USER;
} elseif ($user_query['block'] == 1) {
$error = 'Ой! Вы заблокированы!';
$error = ERROR_USER_IS_BLOCKED;
} elseif (password_verify($password, $user_query['pass'])) {
if (!$error) {
@ -43,10 +46,10 @@ if ($username && $password) {
header("Location: fight.php");
}
} else {
throw new Exception('Неверный пароль!');
$error = ERROR_WRONG_PASSWORD;
}
} else {
throw new Exception('Вы не ввели логин или пароль!');
$error = ERROR_EMPTY_CREDENTIALS;
}
?>
@ -60,7 +63,7 @@ if ($username && $password) {
<body>
<?php if (!empty($error)): ?>
<a href="/"> на главную</a>
<h1><?php echo $error; ?></h1>
<h1><?= $error ?></h1>
<?php endif; ?>
</body>
</html>