2022-09-03 01:24:39 +02:00
|
|
|
local zlib = require("zlib")
|
|
|
|
local sql = require("lsqlite3")
|
|
|
|
|
|
|
|
local db = require("db")
|
|
|
|
local queries = require("queries")
|
|
|
|
local util = require("util")
|
|
|
|
local pages = require("pages")
|
|
|
|
local tags = require("tags")
|
|
|
|
local session = require("session")
|
|
|
|
local config = require("config")
|
|
|
|
|
|
|
|
local stmnt_bio
|
|
|
|
local oldconfigure = configure
|
|
|
|
function configure(...)
|
2022-11-20 00:58:56 +01:00
|
|
|
stmnt_bio = assert(db.conn:prepare(queries.select_author_bio))
|
2022-09-03 01:24:39 +02:00
|
|
|
return oldconfigure(...)
|
|
|
|
end
|
|
|
|
|
|
|
|
local function bio_edit_get(req)
|
|
|
|
local host = http_request_get_host(req)
|
|
|
|
local path = http_request_get_path(req)
|
|
|
|
local author, authorid = session.get(req)
|
|
|
|
|
|
|
|
http_request_populate_qs(req)
|
|
|
|
local ret
|
|
|
|
|
|
|
|
if (not author) or (not authorid) then
|
|
|
|
ret = pages.error{
|
|
|
|
errcode = 401,
|
|
|
|
errcodemsg = "Not authorized",
|
|
|
|
explanation = "You must be logged in to edit your biography."
|
|
|
|
}
|
2022-11-21 01:32:49 +01:00
|
|
|
http_response(req,401,ret)
|
2022-09-03 01:24:39 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
--Get the logged in author's bio to display
|
|
|
|
stmnt_bio:bind_names{
|
|
|
|
authorid = authorid
|
|
|
|
}
|
2022-11-23 22:44:46 +01:00
|
|
|
local err = db.do_sql(stmnt_bio)
|
2022-09-03 01:24:39 +02:00
|
|
|
if err == sql.DONE then
|
|
|
|
--No rows, we're logged in but an author with our id doesn't
|
|
|
|
--exist? Something has gone wrong.
|
|
|
|
ret = pages.error{
|
|
|
|
errcode = 500,
|
|
|
|
errcodemsg = "Server error",
|
|
|
|
explanation = string.format([[
|
|
|
|
Tried to get the biography of author %q (%d) but no author with that id was
|
|
|
|
found, please report this error.
|
|
|
|
]], author, authorid),
|
|
|
|
should_traceback=true
|
|
|
|
}
|
|
|
|
stmnt_bio:reset()
|
|
|
|
http_response(req,500,ret)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
assert(err == sql.ROW)
|
|
|
|
local data = stmnt_bio:get_values()
|
2022-11-23 22:44:46 +01:00
|
|
|
local bio_text = data[1]
|
|
|
|
if data[1] ~= "" then
|
|
|
|
bio_text = zlib.decompress(data[1])
|
|
|
|
end
|
2022-09-03 01:24:39 +02:00
|
|
|
stmnt_bio:reset()
|
|
|
|
ret = pages.edit_bio{
|
2022-11-23 22:44:46 +01:00
|
|
|
text = bio_text,
|
2022-09-03 01:24:39 +02:00
|
|
|
user = author,
|
|
|
|
domain = config.domain,
|
|
|
|
}
|
|
|
|
http_response(req,200,ret)
|
|
|
|
end
|
|
|
|
|
2022-11-20 00:58:56 +01:00
|
|
|
return bio_edit_get
|