-
Notifications
You must be signed in to change notification settings - Fork 0
/
login.php
40 lines (30 loc) · 943 Bytes
/
login.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
<?php
require_once('./init.php');
// если юзер уже залогинен, то просто возвращаем на главную
if (isset($_SESSION['user'])) {
header('Location: /');
exit();
}
$found_errors = [];
$trimmed_email = isset($_POST['email']) ? trim_if_string($_POST['email']) : "";
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$found_errors = validate_login();
if (!count($found_errors)) {
$user = get_user_by_email($link, $trimmed_email);
$_SESSION['user'] = $user;
header('Location: /');
exit();
}
}
$content = include_template('login.php', [
'categories' => $full_categories,
'found_errors' => $found_errors,
'have_errors' => count($found_errors) > 0,
'email' => $trimmed_email
]);
$layout = include_template('layout.php', [
'title' => 'Войти',
'content' => $content,
'categories' => $full_categories
]);
print($layout);