-
Notifications
You must be signed in to change notification settings - Fork 1
/
sign-up.php
39 lines (33 loc) · 1.01 KB
/
sign-up.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
<?php
require_once __DIR__ . '/init.php';
$categories = getCategories($link);
if ($_SERVER['REQUEST_METHOD'] === 'POST'){
$userFormData = getUserFormData($_POST);
$errors = validateSignUpForm($link, $userFormData);
if (count($errors) === 0)
{
$userFormData['password'] = password_hash($userFormData['password'], null, $options = []);
addUser($link, $userFormData);
header("Location:/login.php");
exit();
}
}
if ($_SERVER['REQUEST_METHOD'] === 'GET'){
if(isset($_SESSION['user_id'])){
header("Location:/403.php");
exit();
}
$userFormData = getUserFormData([]);
$errors = [];
}
$page_content = include_template('sign-up.php',[
'categories' => $categories,
'userFormData' => $userFormData,
'errors' => $errors
]);
$layout_content = include_template('layout.php',[
'categories' => $categories,
'content' => $page_content,
'title' => 'Регистрация нового аккаунта'
]);
print($layout_content);