-
Notifications
You must be signed in to change notification settings - Fork 1
/
auth.php
43 lines (38 loc) · 1.34 KB
/
auth.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
session_start();
include 'helpers.php';
include 'conndb.php';
$conn = new mysqli($servername, $username, $password, $database);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$conn->set_charset("utf8");
$required_fields = ['email', 'password'];
$errors = [];
if ($_POST) {
foreach ($required_fields as $field) {
if (empty($_POST[$field])) {
$errors[$field] = 'Поле не заполнено';
}
}
if (!empty($_REQUEST['email'] and !empty($_REQUEST['password']))) {
$email = $_REQUEST['email'];
$password = $_REQUEST['password'];
$checkUser = mysqli_query($conn, "SELECT * FROM `users` WHERE email= '$email'");
if (mysqli_num_rows($checkUser) > 0) {
$user = mysqli_fetch_assoc($checkUser);
if (password_verify($password, $user['password'])) {
$_SESSION['user'] = $user;
header("Location:/index.php");
} else {
$errors['password'] = "Неправильный пароль";
}
} else {
$errors['email'] = "Не правильный email";
}
}
}
$mainContent = include_template('auth.php', [
'errors' => $errors,
]);
echo include_template('layout.php', ['title' => 'Дела в порядке', 'content' => $mainContent]);