push
parent
1a456c5d73
commit
793ee5ecbe
|
@ -8,6 +8,7 @@ option(ENABLE_TSAN "Enable the thread data race sanitizer" OFF)
|
||||||
set(CMAKE_CXX_STANDARD 20)
|
set(CMAKE_CXX_STANDARD 20)
|
||||||
set(CROW_FEATURES compression)
|
set(CROW_FEATURES compression)
|
||||||
|
|
||||||
|
cmake_policy(SET CMP0057 NEW)
|
||||||
find_package(Crow)
|
find_package(Crow)
|
||||||
find_package(CURL)
|
find_package(CURL)
|
||||||
find_package(OpenSSL)
|
find_package(OpenSSL)
|
||||||
|
|
|
@ -1,21 +0,0 @@
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<link rel="stylesheet" href="/static/css/home.css">
|
|
||||||
<link rel="stylesheet" href="/static/css/bar.css">
|
|
||||||
<title>{{$SITE_TITLE}}</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div class="center">
|
|
||||||
<div class="body">
|
|
||||||
<div class="titlebar">
|
|
||||||
<button class="bar"><a href="/home.html">home</a></button>
|
|
||||||
<button class="bar"><a href="/projects.html">projects</a></button>
|
|
||||||
</div>
|
|
||||||
<div class="center">
|
|
||||||
HAXsdsad
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
|
@ -1,16 +1,21 @@
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
|
<link rel="stylesheet" href="/static/css/home.css">
|
||||||
|
<link rel="stylesheet" href="/static/css/bar.css">
|
||||||
<title>{{$SITE_TITLE}}</title>
|
<title>{{$SITE_TITLE}}</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<p>Hello {{person}}!</p>
|
<div class="center">
|
||||||
<form action="/req/posta.html" method="posts">
|
<div class="body">
|
||||||
<label for="fname">First name:</label>
|
<div class="titlebar">
|
||||||
<input type="text" id="fname" name="fname"><br><br>
|
<button class="bar"><a href="/home.html">home</a></button>
|
||||||
<label for="lname">Last name:</label>
|
<button class="bar"><a href="/projects.html">projects</a></button>
|
||||||
<input type="text" id="lname" name="lname"><br><br>
|
</div>
|
||||||
<input type="submit" value="Submit">
|
<div class="center">
|
||||||
</form>
|
HAXsdsad
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -5,9 +5,11 @@
|
||||||
#ifndef CROWSITE_AUTH_H
|
#ifndef CROWSITE_AUTH_H
|
||||||
#define CROWSITE_AUTH_H
|
#define CROWSITE_AUTH_H
|
||||||
|
|
||||||
|
#include "crowsite/utility.h"
|
||||||
|
|
||||||
namespace cs {
|
namespace cs {
|
||||||
|
|
||||||
|
void handleLoginPost(cs::parser::Post postData);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <crowsite/config.h>
|
#include <crowsite/config.h>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
#include <blt/std/hashmap.h>
|
||||||
|
|
||||||
namespace cs {
|
namespace cs {
|
||||||
|
|
||||||
|
@ -18,6 +19,7 @@ namespace cs {
|
||||||
public:
|
public:
|
||||||
explicit Post(const std::string& input);
|
explicit Post(const std::string& input);
|
||||||
|
|
||||||
|
bool hasKey(const std::string& key);
|
||||||
const std::string& operator[](const std::string& key);
|
const std::string& operator[](const std::string& key);
|
||||||
|
|
||||||
std::string dump();
|
std::string dump();
|
||||||
|
|
|
@ -30,8 +30,8 @@ namespace cs::jellyfin
|
||||||
|
|
||||||
for (const auto& user : json)
|
for (const auto& user : json)
|
||||||
{
|
{
|
||||||
auto username = user["Name"].s();
|
auto username = std::string(user["Name"].s());
|
||||||
auto userid = user["Id"].s();
|
auto userid = std::string(user["Id"].s());
|
||||||
//BLT_TRACE("Processing %s = %s", username.operator std::string().c_str(), userid.operator std::string().c_str());
|
//BLT_TRACE("Processing %s = %s", username.operator std::string().c_str(), userid.operator std::string().c_str());
|
||||||
GLOBALS.user_ids[username] = userid;
|
GLOBALS.user_ids[username] = userid;
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,11 @@ namespace cs {
|
||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Post::hasKey(const std::string& key)
|
||||||
|
{
|
||||||
|
return m_Values.find(key) != m_Values.end();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace fs {
|
namespace fs {
|
||||||
|
|
38
src/main.cpp
38
src/main.cpp
|
@ -10,6 +10,7 @@
|
||||||
#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>
|
||||||
|
#include <crowsite/site/auth.h>
|
||||||
|
|
||||||
class BLT_CrowLogger : public crow::ILogHandler
|
class BLT_CrowLogger : public crow::ILogHandler
|
||||||
{
|
{
|
||||||
|
@ -17,7 +18,8 @@ class BLT_CrowLogger : public crow::ILogHandler
|
||||||
void log(std::string message, crow::LogLevel crow_level) final
|
void log(std::string message, crow::LogLevel crow_level) final
|
||||||
{
|
{
|
||||||
blt::logging::log_level blt_level;
|
blt::logging::log_level blt_level;
|
||||||
switch (crow_level){
|
switch (crow_level)
|
||||||
|
{
|
||||||
case crow::LogLevel::DEBUG:
|
case crow::LogLevel::DEBUG:
|
||||||
blt_level = blt::logging::log_level::DEBUG;
|
blt_level = blt::logging::log_level::DEBUG;
|
||||||
break;
|
break;
|
||||||
|
@ -47,6 +49,7 @@ int main(int argc, const char** argv)
|
||||||
cs::requests::init();
|
cs::requests::init();
|
||||||
|
|
||||||
blt::arg_parse parser;
|
blt::arg_parse parser;
|
||||||
|
parser.addArgument(blt::arg_builder("--tests").setAction(blt::arg_action_t::STORE_TRUE).build());
|
||||||
parser.addArgument(blt::arg_builder("token").build());
|
parser.addArgument(blt::arg_builder("token").build());
|
||||||
parser.addArgument(blt::arg_builder("user").build());
|
parser.addArgument(blt::arg_builder("user").build());
|
||||||
parser.addArgument(blt::arg_builder("pass").build());
|
parser.addArgument(blt::arg_builder("pass").build());
|
||||||
|
@ -64,7 +67,7 @@ int main(int argc, const char** argv)
|
||||||
BLT_INFO("Init Crow with compression and logging enabled!");
|
BLT_INFO("Init Crow with compression and logging enabled!");
|
||||||
crow::SimpleApp app;
|
crow::SimpleApp app;
|
||||||
app.use_compression(crow::compression::GZIP);
|
app.use_compression(crow::compression::GZIP);
|
||||||
app.loglevel(crow::LogLevel::INFO);
|
app.loglevel(crow::LogLevel::WARNING);
|
||||||
|
|
||||||
BLT_INFO("Creating static context");
|
BLT_INFO("Creating static context");
|
||||||
|
|
||||||
|
@ -103,13 +106,19 @@ int main(int argc, const char** argv)
|
||||||
// for (const auto& v : req.url_params.keys())
|
// for (const auto& v : req.url_params.keys())
|
||||||
// BLT_TRACE("URL: %s = %s", v.c_str(), req.url_params.get(v));
|
// BLT_TRACE("URL: %s = %s", v.c_str(), req.url_params.get(v));
|
||||||
if (name.ends_with(".html"))
|
if (name.ends_with(".html"))
|
||||||
return {engine.fetch(name)};
|
{
|
||||||
|
crow::mustache::context ctx;
|
||||||
|
// we don't want to pass all get parameters to the context to prevent leaking
|
||||||
|
auto referer = req.url_params.get("referer");
|
||||||
|
if (referer)
|
||||||
|
ctx["referer"] = referer;
|
||||||
|
auto page = crow::mustache::compile(engine.fetch(name));
|
||||||
|
return page.render(ctx);
|
||||||
|
}
|
||||||
|
|
||||||
crow::mustache::context ctx({{"person", name}});
|
crow::mustache::context ctx({{"person", name}});
|
||||||
auto user_page = crow::mustache::compile(engine.fetch("index.html"));
|
auto user_page = crow::mustache::compile(engine.fetch("index.html"));
|
||||||
|
|
||||||
//BLT_TRACE(page);
|
|
||||||
|
|
||||||
return user_page.render(ctx);
|
return user_page.render(ctx);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -118,13 +127,15 @@ int main(int argc, const char** argv)
|
||||||
[](const crow::request& req) {
|
[](const crow::request& req) {
|
||||||
cs::parser::Post pp(req.body);
|
cs::parser::Post pp(req.body);
|
||||||
|
|
||||||
return "Portabella Mushrooms! " + pp.dump();
|
crow::response res(303);
|
||||||
|
res.set_header("Location", pp.hasKey("referer") ? pp["referer"] : "/");
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
CROW_ROUTE(app, "/")(
|
CROW_ROUTE(app, "/")(
|
||||||
[&engine]() {
|
[&engine]() {
|
||||||
return engine.fetch("home.html");
|
return engine.fetch("index.html");
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -134,6 +145,19 @@ int main(int argc, const char** argv)
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
app.tick(
|
||||||
|
std::chrono::seconds(1), [&app, &args]() -> void {
|
||||||
|
if (!args.contains("tests"))
|
||||||
|
return;
|
||||||
|
static uint64_t timer = 0;
|
||||||
|
const uint64_t wait = 10;
|
||||||
|
timer++;
|
||||||
|
if (timer > wait)
|
||||||
|
{
|
||||||
|
app.stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
app.port(8080).multithreaded().run();
|
app.port(8080).multithreaded().run();
|
||||||
|
|
||||||
cs::requests::cleanup();
|
cs::requests::cleanup();
|
||||||
|
|
Loading…
Reference in New Issue