add user editing, work on endpoints and database

This commit is contained in:
Sky Johnson 2025-06-04 19:07:08 -05:00
parent 043b74e25a
commit 113b0d357d
9 changed files with 100 additions and 46 deletions

2
config
View File

@ -1,6 +1,6 @@
server {
port 3117
debug false
debug true
http_logging true
static_prefix "public"
}

Binary file not shown.

View File

@ -0,0 +1,19 @@
<h1>{{ user.username }}</h1>
<h2>Account-level Details</h2>
<form action="/admin/users/{{ user.id }}" method="post">
<div>
<input type="text" name="username" id="username" placeholder="{{ user.username }}">
<input type="email" name="email" id="email" placeholder="{{ user.email }}">
<div>
Verified?
<input type="radio" name="verified" id="verified_true">
<label for="verified_true">True</label>
<input type="radio" name="verified" id="verified_false">
<label for="verified_false">False</label>
</div>
{{ local vtoken = user.verify_token }}
{{ if vtoken == "" then vtoken = "Verification Token" end }}
<input type="text" name="verify_token" id="verify_token" placeholder="{{ vtoken }}">
</div>
</form>

View File

@ -0,0 +1,20 @@
<p>
Here's the list of all currently registered users.
</p>
<table>
<thead>
<tr>
<th>id</th>
<th>username</th>
</tr>
</thead>
<tbody>
{{ for i, u in ipairs(users) do }}
<tr>
<td>{{ u.id }}</td>
<td><a href="/admin/users/{{ u.id }}">{{ u.username }}</a></td>
</tr>
{{ end }}
</tbody>
</table>

View File

@ -1,10 +1,9 @@
local m = {}
function m.page(template, title, ext_data)
if not title then
local title = "Admin"
else
local title = "Admin: "..title
function m.page(template, page_title, ext_data)
local title = "Admin"
if page_title ~= "" and page_title ~= nil then
title = "Admin: "..page_title
end
local data = table.merge({

BIN
moonshark

Binary file not shown.

View File

@ -0,0 +1,9 @@
--[[
GET /admin/users/[id]
Shows the editing page for the given user
]]
local a = require("admin")
local user = sqlite("dk"):get_one("SELECT * FROM users WHERE id = :i", {i = ctx.params.id})
return a.page("edit_user.html", "editing "..user.username, {user = user})

View File

@ -0,0 +1,9 @@
--[[
GET /admin/users
Shows the list of all users currently registered. Jumping off point for editing user data.
]]
local a = require("admin")
local users = sqlite("dk"):query("SELECT id, username FROM users")
return a.page("users.html", "Users", {users = users})

View File

@ -18,32 +18,27 @@ db:create_table("babble",
db:create_table("item_blueprints",
"id INTEGER PRIMARY KEY AUTOINCREMENT",
"type INTEGER NOT NULL DEFAULT 0",
"tier INTEGER NOT NULL DEFAULT 0",
"rarity INTEGER NOT NULL DEFAULT 0",
"base_value INTEGER NOT NULL DEFAULT 0",
"attributes_id INTEGER NOT NULL DEFAULT 0",
"stackable INTEGER NOT NULL DEFAULT 0",
"max_stack INTEGER NOT NULL DEFAULT 1",
"type INTEGER DEFAULT 0",
"tier INTEGER DEFAULT 0",
"rarity INTEGER DEFAULT 0",
"base_value INTEGER DEFAULT 0",
"attributes_id INTEGER DEFAULT 0",
"stackable INTEGER DEFAULT 0",
"max_stack INTEGER DEFAULT 1",
"name TEXT UNIQUE NOT NULL",
"lore TEXT",
"special TEXT NOT NULL DEFAULT ''"
"special TEXT"
)
db:create_table("items",
"id INTEGER PRIMARY KEY AUTOINCREMENT",
"type INTEGER NOT NULL DEFAULT 0",
"tier INTEGER NOT NULL DEFAULT 0",
"rarity INTEGER NOT NULL DEFAULT 0",
"crafted INTEGER NOT NULL DEFAULT 0",
"crafter_id INTEGER NOT NULL DEFAULT 0",
"base_value INTEGER NOT NULL DEFAULT 0",
"attributes_id INTEGER NOT NULL DEFAULT 0",
"stackable INTEGER NOT NULL DEFAULT 0",
"max_stack INTEGER NOT NULL DEFAULT 1",
"name TEXT UNIQUE NOT NULL",
"lore TEXT",
"special TEXT NOT NULL DEFAULT ''"
"blueprint_id INTEGER NOT NULL",
"attributes_id INTEGER DEFAULT 0",
"crafter_id INTEGER DEFAULT 0",
"condition INTEGER DEFAULT 0",
"forge_level INTEGER DEFAULT 0",
"name_override TEXT",
"special TEXT"
)
db:create_table("user_attributes",
@ -206,27 +201,27 @@ db:create_table("users",
"username TEXT UNIQUE NOT NULL",
"password TEXT NOT NULL",
"email TEXT UNIQUE NOT NULL",
"verified INTEGER NOT NULL DEFAULT 0",
"verify_token TEXT NOT NULL DEFAULT ''",
"registered INTEGER NOT NULL DEFAULT (unixepoch())",
"last_login INTEGER NOT NULL DEFAULT (unixepoch())",
"auth_level INTEGER NOT NULL DEFAULT 0",
"lat INTEGER NOT NULL DEFAULT 0",
"lon INTEGER NOT NULL DEFAULT 0",
"class_id INTEGER NOT NULL DEFAULT 1",
"verified INTEGER DEFAULT 0",
"verify_token TEXT DEFAULT ''",
"registered INTEGER DEFAULT (unixepoch())",
"last_login INTEGER DEFAULT (unixepoch())",
"auth_level INTEGER DEFAULT 0",
"lat INTEGER DEFAULT 0",
"lon INTEGER DEFAULT 0",
"class_id INTEGER DEFAULT 1",
"attributes_id INTEGER NOT NULL",
"currently INTEGER NOT NULL DEFAULT 0",
"fight_id INTEGER NOT NULL DEFAULT 0",
"hp INTEGER NOT NULL default 15",
"max_hp INTEGER NOT NULL default 15",
"mp INTEGER NOT NULL default 0",
"max_mp INTEGER NOT NULL default 0",
"tp INTEGER NOT NULL default 10",
"max_tp INTEGER NOT NULL default 10",
"level INTEGER NOT NULL default 1",
"gold INTEGER NOT NULL default 100",
"exp INTEGER NOT NULL default 0",
"drop_code INTEGER NOT NULL default 0",
"currently INTEGER DEFAULT 0",
"fight_id INTEGER DEFAULT 0",
"hp INTEGER DEFAULT 15",
"max_hp INTEGER DEFAULT 15",
"mp INTEGER DEFAULT 0",
"max_mp INTEGER DEFAULT 0",
"tp INTEGER DEFAULT 10",
"max_tp INTEGER DEFAULT 10",
"level INTEGER DEFAULT 1",
"gold INTEGER DEFAULT 100",
"exp INTEGER DEFAULT 0",
"drop_code INTEGER DEFAULT 0",
"spells TEXT",
"maps TEXT"
)
@ -263,4 +258,7 @@ db:commit()
local time = math.roundto(microtime(true) - start, 4)
print(iparse("Database setup in {{{}}} seconds.", {time}))
env_set("game_open", true)
return true