nightly push

main
Brett 2023-08-21 01:03:19 -04:00
parent 4baf70ad0c
commit 477a230974
4 changed files with 29 additions and 19 deletions

View File

@ -0,0 +1,19 @@
//
// Created by brett on 21/08/23.
//
#ifndef CROWSITE_CROW_UTILITY_H
#define CROWSITE_CROW_UTILITY_H
#include <crow/http_response.h>
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

@ -1 +1 @@
Subproject commit bbbf0ba2e57ae202aa83cd2c8178f772a2e14a78 Subproject commit 34536e2a633050ed241b951c292aca58c55435b9

View File

@ -7,6 +7,7 @@
#include "crowsite/utility.h" #include "crowsite/utility.h"
#include <algorithm> #include <algorithm>
#include <blt/std/time.h> #include <blt/std/time.h>
#include <blt/parse/mustache.h>
namespace cs namespace cs
{ {

View File

@ -1,12 +1,9 @@
#include <iostream>
#include <crowsite/crow_includes.h> #include <crowsite/crow_includes.h>
#include <blt/std/logging.h> #include <blt/std/logging.h>
#include <blt/std/string.h>
#include <blt/profiling/profiler.h>
#include <sstream>
#include <crowsite/utility.h> #include <crowsite/utility.h>
#include <crowsite/site/cache.h> #include <crowsite/site/cache.h>
#include <crowsite/beemovie.h> #include <crowsite/beemovie.h>
#include <crowsite/crow_utility.h>
#include <crowsite/requests/jellyfin.h> #include <crowsite/requests/jellyfin.h>
#include <crowsite/requests/curl.h> #include <crowsite/requests/curl.h>
#include <blt/parse/argparse.h> #include <blt/parse/argparse.h>
@ -53,13 +50,6 @@ struct site_params
const std::string& name; 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! * 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) crow::response handle_auth_page(const site_params& params)
{ {
if (isUserAdmin(params.app, params.req)) 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")( CROW_ROUTE(app, "/login.html")(
[&app, &engine](const crow::request& req) -> crow::response { [&app, &engine](const crow::request& req) -> crow::response {
if (isUserLoggedIn(app, req)) if (isUserLoggedIn(app, req))
return redirect("/"); return cs::redirect("/");
return handle_root_page({app, engine, req, "login.html"}); 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")( CROW_ROUTE(app, "/logout.html")(
[&app](const crow::request& req) -> crow::response { [&app](const crow::request& req) -> crow::response {
destroyUserSession(app, req); destroyUserSession(app, req);
return redirect("/"); return cs::redirect("/");
} }
); );
@ -258,14 +248,14 @@ int main(int argc, const char** argv)
break; 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)) if (cs::checkUserAuthorization(pp))
{ {
cs::cookie_data data = cs::createUserAuthTokens(pp, user_agent); cs::cookie_data data = cs::createUserAuthTokens(pp, user_agent);
if (!cs::storeUserData(pp["username"], user_agent, data)) if (!cs::storeUserData(pp["username"], user_agent, data))
{ {
BLT_ERROR("Failed to update user data"); BLT_ERROR("Failed to update user data");
return redirect("login.html"); return cs::redirect("login.html");
} }
session.set("clientID", data.clientID); 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("clientID", data.clientID).path("/").max_age(cookie_age);
cookie_context.set_cookie("clientToken", data.clientToken).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 } else
return redirect("login.html"); return cs::redirect("login.html");
} }
); );