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(...) stmnt_bio = assert(db.conn:prepare(queries.select_bio)) 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." } http_response(req,400,ret) end --Get the logged in author's bio to display stmnt_bio:bind_names{ authorid = authorid } local err = util.do_sql(stmnt_edit) 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() local bio = unpack(data) stmnt_bio:reset() ret = pages.edit_bio{ text = bio, user = author, domain = config.domain, } http_response(req,200,ret) end return edit_get