diff --git a/src/webserver/auth/register.php b/src/webserver/auth/register.php new file mode 100644 index 0000000..61305b9 --- /dev/null +++ b/src/webserver/auth/register.php @@ -0,0 +1,86 @@ + + +
" . $e . "
"; + } + regForm(); + } else { + $add_stmt = $conn->prepare('INSERT INTO Players (nickname, is_active) VALUES (:nickname, 1)'); + if ($add_stmt) { + $add_stmt->bindValue(':nickname', $_POST['nickname']); + $add_result = $add_stmt->execute(); + $player_id = false; + if ($add_result) { + $player_id = $conn->lastInsertRowID(); + if ($player_id) { + $credentials_stmt = $conn->prepare('INSERT INTO PlayerAuth (player_id, email, hashed_pw, is_active, is_email_verified) VALUES (:player_id, :email, :hashed_pw, 1, 0)'); + if ($credentials_stmt) { + $credentials_stmt->bindParam(':player_id', $player_id); + $credentials_stmt->bindParam(':email', $_POST['email']); + $credentials_stmt->bindParam(':hashed_pw', password_hash($_POST['password'], PASSWORD_DEFAULT, ['cost' => 12])); + $credentials_result = $credentials_stmt->execute(); + if ($credentials_result) { + echo "Your account has been created. You can now log in and start playing!
"; + } + } + } + } + } + } + } + + require_once(realpath(dirname(__FILE__) . '/../footer.php')); + + function regForm() { +?> + + + + + + + +