-
Notifications
You must be signed in to change notification settings - Fork 1
/
auth.php
80 lines (70 loc) · 1.98 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
require_once 'init.php';
require_once 'model.php';
require_once 'helpers.php';
require_once 'myfunction.php';
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$required = ['email', 'password'];
$errors = [];
$user_auth = filter_input_array(
INPUT_POST,
[
'email' => FILTER_DEFAULT,
'password' => FILTER_DEFAULT
],
true
);
foreach ($user_auth as $key => $value) {
if (in_array($key, $required) && empty($value)) {
$errors[$key] = "Поле $key надо заполнить";
}
}
$errors = array_filter($errors);
$user = get_user($con, $user_auth);
if (!count($errors) and !empty($user)) {
if (password_verify($user_auth['password'], $user['password'])) {
$_SESSION['user'] = $user;
$user_id = $_SESSION['user']['id'];
} else {
$errors['password'] = 'Неверный пароль';
}
} else {
$errors['email'] = 'Такой пользователь не найден';
}
if (count($errors)) {
$page_content = include_template(
'auth.php',
[
'user' => $user_auth,
'errors' => $errors
]
);
} else {
header("Location: index.php");
}
} else {
$page_content = include_template('auth.php', []);
if (!empty($_SESSION['user'])) {
header("Location: index.php");
}
}
$project_id = filter_input(INPUT_GET, 'project_id', FILTER_SANITIZE_NUMBER_INT);
$projects = get_projects($con, $user_id);
$navigation_content = include_template(
'navigation.php',
[
'user' => [],
'projects' => $projects,
'project_id' => $project_id,
'content' => $page_content
]
);
$layout_content = include_template(
'layout.php',
[
'user' => [],
'navigation' => $navigation_content,
'title' => 'Дела в порядке'
]
);
print($layout_content);