-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathregistration.php
80 lines (75 loc) · 2.53 KB
/
registration.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 "helpers.php";
require_once "validate_functions.php";
if (isset($_SESSION["user"])) {
http_response_code(403);
$content = include_template("error.php", [
"categories" => $categories,
"code_error" => "403",
"text_error" => "Страница для незарегистрированных пользователей"
]);
} elseif ($_SERVER["REQUEST_METHOD"] === "POST") {
$errors = [];
$email = post_value("email");
$password = post_value("password");
$name = post_value("name");
$message = post_value("message");
$errors = validate(
[
"email" => $email,
"password" => $password,
"name" => $name,
"message" => $message,
],
[
"email" => [
not_empty("Введите электронный адресс"),
checking_correct_email(),
db_exists("users", "email", "Пользователь с этим email уже зарегистрирован", $con),
str_length_gt(254),
],
"password" => [
not_empty("Введите пароль"),
],
"name" => [
not_empty("Укажите Ваше ФИО"),
str_length_gt(254),
],
"message" => [
not_empty("Напишите как с вами связаться"),
],
]
);
if (empty($errors)) {
$password = password_hash($password, PASSWORD_DEFAULT);
$query_insert_database_user = "INSERT INTO `users`(
`registration_dt`,
`email`,
`name`,
`password`,
`users_info`
)
VALUES(NOW(), ?, ?, ?, ?)";
$stmt = db_get_prepare_stmt($con, $query_insert_database_user, [$email, $name, $password, $message]);
$result = mysqli_stmt_execute($stmt);
if ($result) {
header("location: login.php");
exit();
}
echo "Ошибка вставки " . mysqli_error($con);
} else {
$content = include_template("sign-up.php", [
"errors" => $errors,
]);
}
} else {
$content = include_template("sign-up.php", []);
}
$layout_content = include_template("layout.php", [
"content" => $content,
"title_page" => "Страница регистрации",
"user_name" => get_value_from_user_session("name"),
"categories" => $categories,
]);
print($layout_content);