aboutsummaryrefslogtreecommitdiff
path: root/user/register.php
diff options
context:
space:
mode:
Diffstat (limited to 'user/register.php')
-rw-r--r--user/register.php29
1 files changed, 29 insertions, 0 deletions
diff --git a/user/register.php b/user/register.php
new file mode 100644
index 0000000..fb9ed09
--- /dev/null
+++ b/user/register.php
@@ -0,0 +1,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");
+?>