64 || strlen($u) === 0) { $err = $lang["account"]["errors"]["username_length"]; } else if (!preg_match("/^[a-z0-9_-]{1,64}$/", $u)) { $err = $lang["account"]["errors"]["username_characters"]; } 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") { $allow_signup = true; if ($signups === "invite") { $invite_code = $_POST["invite"]; if (strlen($invite_code) !== 64 || !preg_match("/^[a-f0-9]{64}$/", $invite_code)) { $allow_signup = false; $err = $lang["account"]["errors"]["invalid_invite"]; } else { $q = "SELECT count(*) FROM invites WHERE id='$invite_code' LIMIT 1;"; $invite_valid = pg_fetch_array(pg_query($db, $q))["count"] === "1"; echo json_encode(pg_fetch_array(pg_query($db, $q))); if (!$invite_valid) { $allow_signup = false; $err = $lang["account"]["errors"]["invalid_invite"]; } else { $q = "DELETE FROM invites WHERE id='$invite_code';"; pg_query($db, $q); } } } if ($allow_signup) { $user_id = generate_id(); $pw_hash = password_hash($p, PASSWORD_DEFAULT); $user_parameters = array( "id" => $user_id, "username" => $u, "password_hash" => $pw_hash, "enable_colors" => true, "yellow_threshold" => 2, "gray_threshold" => 60 ); 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 * 365 // 1 year from now ); header("Location: index.php"); exit(); } } else { $err = str_replace("%u", htmlspecialchars($u), $lang["account"]["errors"]["user_exists"]); } } } $title = $lang["account"]["sign_up"]; include "boilerplate/head.php"; ?>