mirror of
https://codeberg.org/metamuffin/abrechenbarkeit.git
synced 2024-12-29 16:14:36 +00:00
config and transaction sounds
This commit is contained in:
parent
c3dadcc5a3
commit
82e7646230
1 changed files with 33 additions and 12 deletions
|
@ -29,6 +29,22 @@ local function parse_query(q)
|
||||||
return data
|
return data
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function load_config()
|
||||||
|
local log = io.open("config", "r")
|
||||||
|
if log == nil then return {} end
|
||||||
|
local config = {}
|
||||||
|
for l in log:lines("l") do
|
||||||
|
if l ~= "" and l[0] ~= "#" then
|
||||||
|
local key, value = string.match(l, "^([^=]+)=([^=]*)")
|
||||||
|
if key ~= nil and value ~= nil then
|
||||||
|
config[key] = value
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return config
|
||||||
|
end
|
||||||
|
|
||||||
|
local config = load_config()
|
||||||
local path = os.getenv("PATH_INFO")
|
local path = os.getenv("PATH_INFO")
|
||||||
local method = os.getenv("REQUEST_METHOD")
|
local method = os.getenv("REQUEST_METHOD")
|
||||||
local query = parse_query(os.getenv("QUERY_STRING"))
|
local query = parse_query(os.getenv("QUERY_STRING"))
|
||||||
|
@ -47,7 +63,6 @@ local stylesheet = [[
|
||||||
form h3 { margin: 5px; }
|
form h3 { margin: 5px; }
|
||||||
]]
|
]]
|
||||||
|
|
||||||
-- local script = io.open("main.js"):read("a")
|
|
||||||
local script = [[
|
local script = [[
|
||||||
document.addEventListener("keypress", ev => {
|
document.addEventListener("keypress", ev => {
|
||||||
if (!(document.activeElement instanceof HTMLInputElement)) {
|
if (!(document.activeElement instanceof HTMLInputElement)) {
|
||||||
|
@ -70,6 +85,7 @@ local function respond(status, title, body)
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<style>%s</style>
|
<style>%s</style>
|
||||||
<script>%s</script>
|
<script>%s</script>
|
||||||
|
%s
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<nav>
|
<nav>
|
||||||
|
@ -77,7 +93,7 @@ local function respond(status, title, body)
|
||||||
<span><a href="/?log">View Log</a></span>
|
<span><a href="/?log">View Log</a></span>
|
||||||
<span><a href="https://codeberg.org/metamuffin/strichliste">Source</a></span>
|
<span><a href="https://codeberg.org/metamuffin/strichliste">Source</a></span>
|
||||||
</nav>
|
</nav>
|
||||||
]], escape(title), stylesheet, script))
|
]], escape(title), stylesheet, script, config.head_extra or ""))
|
||||||
body()
|
body()
|
||||||
print("</body></html>")
|
print("</body></html>")
|
||||||
end
|
end
|
||||||
|
@ -187,9 +203,13 @@ local function r_user_post(username)
|
||||||
log:write(string.format("%d,%s,%d,%s\n", time, username, amount, comment))
|
log:write(string.format("%d,%s,%d,%s\n", time, username, amount, comment))
|
||||||
log:flush()
|
log:flush()
|
||||||
log:close()
|
log:close()
|
||||||
return string.format(
|
return string.format([[
|
||||||
"<div class=\"notif\"><p>Transaction successful: <strong class=\"amount-%s\">%.02f€</strong> (%s)</p></div>",
|
<div class=\"notif\"><p>Transaction successful: <strong class=\"amount-%s\">%.02f€</strong> (%s)</p></div>
|
||||||
amount >= 0 and "pos" or "neg", amount / 100, escape(comment)
|
<audio src="%s" autoplay></audio>
|
||||||
|
]],
|
||||||
|
amount >= 0 and "pos" or "neg", amount / 100,
|
||||||
|
escape(comment),
|
||||||
|
config.transaction_sound or ""
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -204,18 +224,19 @@ local function r_user(username)
|
||||||
local last_txn = last_txns()[username]
|
local last_txn = last_txns()[username]
|
||||||
local new_user = balance == nil
|
local new_user = balance == nil
|
||||||
balance = balance or 0
|
balance = balance or 0
|
||||||
|
if notif then print(notif) end
|
||||||
if new_user then
|
if new_user then
|
||||||
print([[
|
print([[
|
||||||
<div class="notif"><p><i>This user account does not exist yet. It will only be created after the first transaction.</i></p></div>
|
<div class="notif"><p><i>This user account does not exist yet. It will only be created after the first transaction.</i></p></div>
|
||||||
]])
|
]])
|
||||||
|
else
|
||||||
|
print(string.format([[
|
||||||
|
<p>Current balance: <span class="amount-%s">%.02f€</p>
|
||||||
|
]], balance >= 0 and "pos" or "neg", balance / 100))
|
||||||
|
print(string.format([[
|
||||||
|
<p>Last transaction added %s ago. <a href="/%s?log">View user log</a>
|
||||||
|
]], format_duration(os.time() - last_txn), username))
|
||||||
end
|
end
|
||||||
if notif then print(notif) end
|
|
||||||
print(string.format([[
|
|
||||||
<p>Current balance: <span class="amount-%s">%.02f€</p>
|
|
||||||
]], balance >= 0 and "pos" or "neg", balance / 100))
|
|
||||||
print(string.format([[
|
|
||||||
<p>Last transaction added %s ago. <a href="/%s?log">View user log</a>
|
|
||||||
]], format_duration(os.time() - last_txn), username))
|
|
||||||
print([[
|
print([[
|
||||||
<form class="transaction box" action="" method="POST">
|
<form class="transaction box" action="" method="POST">
|
||||||
<h3>Create Transaction</h3>
|
<h3>Create Transaction</h3>
|
||||||
|
|
Loading…
Reference in a new issue