From 7788e29b36931858c51a0d3eb4cf6f7a6906870f Mon Sep 17 00:00:00 2001 From: bert hubert Date: Fri, 5 Jan 2024 14:33:32 +0100 Subject: [PATCH] make sure all api calls return json with .ok=1 if they are ok --- serv.cc | 48 ++++++++++++++++-------------------------------- 1 file changed, 16 insertions(+), 32 deletions(-) diff --git a/serv.cc b/serv.cc index a57526f..29542f0 100644 --- a/serv.cc +++ b/serv.cc @@ -2,7 +2,6 @@ #include #include #include - #include #include @@ -343,10 +342,7 @@ int trifectaMain(int argc, const char**argv) reason = "An unknown error occurred"; } cout< ?", {sessionid, time(0)}); if(c.size()==1) { @@ -587,8 +581,7 @@ int trifectaMain(int argc, const char**argv) wrapPost({Capability::IsUser}, "/delete-post/(.+)", [&lsqw, &u](const auto& req, auto& res, const string& user) { string postid = req.matches[1]; - nlohmann::json j; - j["ok"]=0; + nlohmann::json j{{"ok", 0}}; if(canTouchPost(lsqw, u, user, postid)) { lsqw.query("delete from posts where id=?", {postid}); j["ok"]=1; @@ -624,14 +617,12 @@ int trifectaMain(int argc, const char**argv) checkImageOwnership(lsqw, u, user, imgid); lsqw.query("update images set caption=? where id=?", {caption, imgid}); lsqw.addValue({{"action", "set-image-caption"}, {"ip", getIP(req)}, {"user", user}, {"imageId", imgid}, {"tstamp", time(0)}}, "log"); - return nlohmann::json(); + return nlohmann::json{{"ok", 1}}; }); wrapPost({Capability::IsUser, Capability::EmailAuthenticated}, "/wipe-my-password/?", [&lsqw, &u](const auto& req, auto& res, const string& user) { u.changePassword(user, ""); - nlohmann::json j; - j["ok"]=1; - return j; + return nlohmann::json{{"ok", 1}}; }); wrapPost({Capability::IsUser}, "/change-my-password/?", [&lsqw, &u](const auto& req, auto& res, const string& user) { @@ -644,19 +635,13 @@ int trifectaMain(int argc, const char**argv) } cout<<"Attemping to set password for user "<("local-address");