aboutsummaryrefslogtreecommitdiff
path: root/user/register.php
blob: fb9ed09294734fea06ea189305c149dca42d0b62 (plain)
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
<?php
require '../config.php';
require_once(TEMPLATES_PATH . "/header.php");
require_once(TEMPLATES_PATH . "/panel.php");
require_once(LIBRARY_PATH . "/functions.php");

print_r($_POST);

$password = password_hash($_POST['password'], PASSWORD_ARGON2I);

$conn = new PDO($config['db']['dsn'], $config['db']['username'], $config['db']['password']);
$query = $conn->prepare("INSERT INTO users (username, password, email) VALUES (:username, :password, :email)");
$query->bindParam(':username', $_POST['username']);
$query->bindParam(':password', $password);
$query->bindParam(':email', $_POST['email']);

if($query->execute()) {
    echo '<h2>Registration successful</h2>';
    $result = $conn->query("SELECT id, username, password FROM users WHERE username = '$_POST[username]'")->fetch();
    $_SESSION['user_name'] = $result['username'];
    $_SESSION['user_id'] = $result['id'];
} else {
    echo '<h2>Registration failed</h2>';
}

header("Refresh: 2; URL={$config['urls']['base']}");

require_once(TEMPLATES_PATH . "/footer.php");
?>