commit d8f1874ebb38a8c113d3234a480fdbbbb03ca666 Author: trinkey Date: Fri Mar 21 23:43:07 2025 -0400 Initial commit - signing up + boilerplate/schema diff --git a/assets/favicon.png b/assets/favicon.png new file mode 100644 index 0000000..0fe6caa Binary files /dev/null and b/assets/favicon.png differ diff --git a/boilerplate/foot.php b/boilerplate/foot.php new file mode 100644 index 0000000..b605728 --- /dev/null +++ b/boilerplate/foot.php @@ -0,0 +1,2 @@ + + diff --git a/boilerplate/head.php b/boilerplate/head.php new file mode 100644 index 0000000..308679e --- /dev/null +++ b/boilerplate/head.php @@ -0,0 +1,34 @@ + + + + + <?php + if ($title) { + echo "$title | "; + } + echo $site_name; + ?> + + + + + + + + + + + + + $title

$site_name

"; + } else { + echo "

$site_name

"; + } + + if ($err) { + echo "
$err
"; + } + ?> + diff --git a/config.php b/config.php new file mode 100644 index 0000000..8fed913 --- /dev/null +++ b/config.php @@ -0,0 +1,36 @@ + array( + "name" => "General", + "show_subtitle" => false, + "items" => array( + "general" => array( + "name" => "", + "display_format" => "For %d - %c" + ) + ) + ) +); + +?> diff --git a/css/base.css b/css/base.css new file mode 100644 index 0000000..23b3aa2 --- /dev/null +++ b/css/base.css @@ -0,0 +1,79 @@ +:root { + --background: #190b14; + --text: #c5b8ca; + --subtext: #c5a8ca80; + --border: #d8a4c62a; + --input-background: #2e1425; + --button-background: #3c1a30; + --button-hover-background: #5e2a4e; + --accent: #d8a4c6; + --red: #d67677; + --yellow: #d3d381; + + color-scheme: dark; +} + +::selection { + background-color: var(--accent); + color: var(--background); +} + +body { + position: absolute; + top: 0; + left: 0; + background-color: var(--background); + color: var(--text); + min-height: calc(100vh - 16px); + width: calc(100vw - 16px); + overflow-x: hidden; + margin: 8px; + text-align: center; + font-family: sans-serif; + font-size: 18px; +} + +input { + background-color: var(--input-background); + color: var(--color); + border: 1px solid var(--border); + padding: 3px 5px; + border-radius: 7.5px; + margin: 2px; +} + +input:focus { + outline: 2px solid var(--subtext); +} + +input::placeholder { + color: var(--subtext); +} + +a { + color: var(--accent); + text-decoration: none; +} + +a:hover { + text-decoration: underline; +} + +i { + color: var(--subtext); +} + +.err { + color: var(--red); + border: 2px dashed var(--red); + padding: 20px; + border-radius: 20px; + max-width: 400px; + margin: 0 auto; + margin-bottom: 20px; +} + +#container { + text-align: left; + margin: 0 10vw; +} diff --git a/helper.php b/helper.php new file mode 100644 index 0000000..21d3f5d --- /dev/null +++ b/helper.php @@ -0,0 +1,37 @@ + $u + ) + ); + + if ($user_object && get_token($user_object[0]["username"], $user_object[0]["password_hash"]) === $token) { + return $user_object; + } + + return false; +} + +?> diff --git a/index.php b/index.php new file mode 100644 index 0000000..039f5fe --- /dev/null +++ b/index.php @@ -0,0 +1,16 @@ + + +Log In + +Sign Up"; + } + + include "boilerplate/foot.php"; +?> diff --git a/login.php b/login.php new file mode 100644 index 0000000..4182595 --- /dev/null +++ b/login.php @@ -0,0 +1,46 @@ + $u) + ); + + if (sizeof($response) === 0) { + $err = "User '" . htmlspecialchars($u) . "' not found"; + } else { + echo json_encode($response); + } + } else { + $err = "Bad request, missing username or password parameter"; + } + } else { + $u = ""; + $p = ""; + } + + $title = "Log In"; + include "boilerplate/head.php"; +?> + +
+
+
+
+
+ +Sign up instead?

"; + } + + include "boilerplate/foot.php"; +?> diff --git a/setup.php b/setup.php new file mode 100644 index 0000000..c1b72ef --- /dev/null +++ b/setup.php @@ -0,0 +1,43 @@ + diff --git a/signup.php b/signup.php new file mode 100644 index 0000000..50745db --- /dev/null +++ b/signup.php @@ -0,0 +1,100 @@ + 64 || strlen($u) === 0) { + $err = "Username must be 1-64 chars"; + } else if (!preg_match("/^[a-z0-9_-]{1,64}$/", $u)) { + $err = "Username can only include a-z, 0-9, _, and -"; + } else { + $query = "SELECT count(*) FROM users WHERE username='$u' LIMIT 1;"; + + $response = pg_query($db, $query); + $c = pg_fetch_array($response)["count"]; + + if ($c === "0") { + $user_id = generate_id(); + $pw_hash = password_hash($p, PASSWORD_DEFAULT); + $user_parameters = array( + "id" => $user_id, + "username" => $u, + "password_hash" => $pw_hash + ); + + pg_insert($db, "users", $user_parameters); + + foreach ($default_schema as $section_id => $section_data) { + $section_id = generate_id(); + $section_parameters = array( + "id" => $section_id, + "users" => $user_id, + "name" => $section_data["name"], + "show_subtitle" => $section_data["show_subtitle"] + ); + + pg_insert($db, "section", $section_parameters); + + foreach ($section_data["items"] as $row_id => $row_data) { + $row_id = generate_id(); + $row_parameters = array( + "id" => $row_id, + "section" => $section_id, + "name" => $row_data["name"], + "display_format" => $row_data["display_format"] + ); + + pg_insert($db, "row", $row_parameters); + } + } + + $token = get_token($u, $pw_hash); + setcookie( + "token", + $token, + time() + 60 * 60 * 24 * 30 * 265 // 1 year from now + ); + header("Location: index.php"); + exit(); + } else { + $err = "User '" . htmlspecialchars($u) . "' already exists"; + } + } + } + + $title = "Log In"; + include "boilerplate/head.php"; +?> + +
+
+
+
+
+
+ +Sign up instead?

"; + } + + include "boilerplate/foot.php"; +?>