summaryrefslogtreecommitdiff
path: root/register.php
diff options
context:
space:
mode:
authorcflip <36554078+cflip@users.noreply.github.com>2021-05-08 17:30:08 -0600
committerGitHub <noreply@github.com>2021-05-08 17:30:08 -0600
commit87b1dfd1f77b08915ee5e905da45e316ba2c0e7d (patch)
treef6c0f8d09454b6e887df0f66ca37c1ce9efb30d0 /register.php
parent0b045d57b2164b5ce003955d79627ae506a153eb (diff)
parenta09d9f377f5c055e42e5f21b5cdea64c2e2ca896 (diff)
Merge pull request #14 from cflip/refactor
Huge refactor
Diffstat (limited to 'register.php')
-rw-r--r--register.php63
1 files changed, 15 insertions, 48 deletions
diff --git a/register.php b/register.php
index cd72a37..02fbe58 100644
--- a/register.php
+++ b/register.php
@@ -1,48 +1,26 @@
+<?php session_start() ?>
<!DOCTYPE html>
-<html>
+<html lang="en">
<head>
- <title>Register an account - cflip.net forum</title>
- <link rel="stylesheet" href="styles/style.css">
+ <title>Register an account - cflip.net forum</title>
+ <link rel="stylesheet" href="styles/style.css">
</head>
<body>
-<?php include_once 'templates/header.php'?>
+<?php include './includes/templates/header.php' ?>
<h2>Register an account</h2>
<form action="register.php" method="post">
- <label for="user_name">Username: </label><br>
- <input type="text" name="user_name"><br>
- <label for="user_pass">Password: </label><br>
- <input type="password" name="user_pass"><br>
- <label for="user_pass_check">Re-enter password: </label><br>
- <input type="password" name="user_pass_check"><br>
- <input type="submit" name="submit">
+ <label for="user_name">Username: </label><br>
+ <input type="text" name="user_name"><br>
+ <label for="user_pass">Password: </label><br>
+ <input type="password" name="user_pass"><br>
+ <label for="user_pass_check">Re-enter password: </label><br>
+ <input type="password" name="user_pass_check"><br>
+ <input type="submit" name="submit">
</form>
<br>
<?php
-include_once 'includes/db_inc.php';
-
-function username_exists($dbc, $user_name) {
- $sql = "SELECT * FROM users WHERE user_name = ?;";
- $stmt = mysqli_stmt_init($dbc);
-
- if (!mysqli_stmt_prepare($stmt, $sql)) {
- die("Error: " . mysqli_error($dbc));
- }
-
- mysqli_stmt_bind_param($stmt, "s", $user_name);
- mysqli_stmt_execute($stmt);
-
- $result = mysqli_stmt_get_result($stmt);
-
- if ($row = mysqli_fetch_assoc($result)) {
- return $row;
- } else {
- $result = false;
- return $result;
- }
-
- mysqli_stmt_close($stmt);
-}
+include_once './includes/functions_user.php';
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$errors = array();
@@ -62,7 +40,7 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$errors[] = "Your username must be 30 characters or less.";
}
- if (username_exists($dbc, $user_name) !== false) {
+ if (username_exists($user_name) !== false) {
$errors[] = "The username '" . $user_name . "' has already been taken by another user.";
}
}
@@ -89,19 +67,8 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
}
echo '</ul>';
} else {
- $sql = "INSERT INTO users(user_name, user_pass, user_date) VALUES(?, ?, NOW());";
- $stmt = mysqli_stmt_init($dbc);
-
- if (!mysqli_stmt_prepare($stmt, $sql)) {
- die('Could not create account due to internal error: ' . mysqli_error($dbc));
- }
-
$pass_hash = password_hash($user_pass, PASSWORD_DEFAULT);
-
- mysqli_stmt_bind_param($stmt, "ss", $user_name, $pass_hash);
- mysqli_stmt_execute($stmt);
- mysqli_stmt_close($stmt);
-
+ register_user($user_name, $pass_hash);
echo 'Account successfully registered! You can now <a href="signin.php">sign in</a>';
}
}