-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsign-up.php
More file actions
76 lines (63 loc) · 1.71 KB
/
sign-up.php
File metadata and controls
76 lines (63 loc) · 1.71 KB
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
<?php
declare(strict_types=1);
$conn = require_once 'init.php';
require_once 'models/category.php';
require_once 'models/lot.php';
require_once 'models/user.php';
require_once 'validators.php';
$is_auth = is_user_authorized($conn);
if ($is_auth === true) {
exit_with_message('Доступ запрещён', 403);
}
$user_name = get_user_name();
$page_title = 'Регистрация';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$errors = validate(
array_merge_recursive($_POST, $_FILES),
[
'email' => ['required', 'valid_email', unique_email($conn)],
'password' => ['required'],
'name' => ['required', character_limit(128)],
'message' => ['required', character_limit(256)],
],
);
if (empty($errors)) {
add_user(
$conn,
[
$_POST['email'],
$_POST['name'],
password_hash($_POST['password'], PASSWORD_BCRYPT),
$_POST['message'],
]
);
header('Location: /login.php');
die();
}
}
$categories_list = get_all_categories($conn);
$categories_header = include_template(
'categories-header.php',
[
'categories_list' => $categories_list,
],
);
$page_content = include_template(
'sign-up.php',
[
'categories_header' => $categories_header,
'errors' => $errors ?? [],
'form_data' => $_POST,
],
);
$html_result = include_template(
'layout.php',
[
'categories_list' => $categories_list,
'page_title' => $page_title,
'is_auth' => $is_auth,
'user_name' => $user_name,
'page_content' => $page_content,
],
);
print($html_result);