From 477a23097499ec5b2f56bd5836436d2c070f2e1e Mon Sep 17 00:00:00 2001 From: Brett Laptop Date: Mon, 21 Aug 2023 01:03:19 -0400 Subject: [PATCH] nightly push --- include/crowsite/crow_utility.h | 19 +++++++++++++++++++ libs/BLT | 2 +- src/crowsite/site/cache.cpp | 1 + src/main.cpp | 26 ++++++++------------------ 4 files changed, 29 insertions(+), 19 deletions(-) create mode 100644 include/crowsite/crow_utility.h diff --git a/include/crowsite/crow_utility.h b/include/crowsite/crow_utility.h new file mode 100644 index 0000000..5277154 --- /dev/null +++ b/include/crowsite/crow_utility.h @@ -0,0 +1,19 @@ +// +// Created by brett on 21/08/23. +// + +#ifndef CROWSITE_CROW_UTILITY_H +#define CROWSITE_CROW_UTILITY_H + +#include + +namespace cs { + inline crow::response redirect(const std::string& loc = "/", int code = 303) + { + crow::response res(code); + res.set_header("Location", loc); + return res; + } +} + +#endif //CROWSITE_CROW_UTILITY_H diff --git a/libs/BLT b/libs/BLT index bbbf0ba..34536e2 160000 --- a/libs/BLT +++ b/libs/BLT @@ -1 +1 @@ -Subproject commit bbbf0ba2e57ae202aa83cd2c8178f772a2e14a78 +Subproject commit 34536e2a633050ed241b951c292aca58c55435b9 diff --git a/src/crowsite/site/cache.cpp b/src/crowsite/site/cache.cpp index f9fc517..badff5c 100644 --- a/src/crowsite/site/cache.cpp +++ b/src/crowsite/site/cache.cpp @@ -7,6 +7,7 @@ #include "crowsite/utility.h" #include #include +#include namespace cs { diff --git a/src/main.cpp b/src/main.cpp index 9ae7561..84572c5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,12 +1,9 @@ -#include #include #include -#include -#include -#include #include #include #include +#include #include #include #include @@ -53,13 +50,6 @@ struct site_params const std::string& name; }; -inline crow::response redirect(const std::string& loc = "/", int code = 303) -{ - crow::response res(code); - res.set_header("Location", loc); - return res; -} - /** * Note this function destroys the user's session and any login related cookies! */ @@ -156,7 +146,7 @@ crow::response handle_root_page(const site_params& params) crow::response handle_auth_page(const site_params& params) { if (isUserAdmin(params.app, params.req)) - return redirect("/login.html"); + return cs::redirect("/login.html"); @@ -226,7 +216,7 @@ int main(int argc, const char** argv) CROW_ROUTE(app, "/login.html")( [&app, &engine](const crow::request& req) -> crow::response { if (isUserLoggedIn(app, req)) - return redirect("/"); + return cs::redirect("/"); return handle_root_page({app, engine, req, "login.html"}); } ); @@ -234,7 +224,7 @@ int main(int argc, const char** argv) CROW_ROUTE(app, "/logout.html")( [&app](const crow::request& req) -> crow::response { destroyUserSession(app, req); - return redirect("/"); + return cs::redirect("/"); } ); @@ -258,14 +248,14 @@ int main(int argc, const char** argv) break; } - // either redirect to clear the form if failed or pass user to index + // either cs::redirect to clear the form if failed or pass user to index if (cs::checkUserAuthorization(pp)) { cs::cookie_data data = cs::createUserAuthTokens(pp, user_agent); if (!cs::storeUserData(pp["username"], user_agent, data)) { BLT_ERROR("Failed to update user data"); - return redirect("login.html"); + return cs::redirect("login.html"); } session.set("clientID", data.clientID); @@ -276,9 +266,9 @@ int main(int argc, const char** argv) cookie_context.set_cookie("clientID", data.clientID).path("/").max_age(cookie_age); cookie_context.set_cookie("clientToken", data.clientToken).path("/").max_age(cookie_age); } - return redirect(pp.hasKey("referer") ? pp["referer"] : "/"); + return cs::redirect(pp.hasKey("referer") ? pp["referer"] : "/"); } else - return redirect("login.html"); + return cs::redirect("login.html"); } );