added login suppport
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
#include "ShadowrunApi.hpp"
|
||||
#include "ShadowrunCharacterForm.hpp"
|
||||
#include "ShadowrunDb.hpp"
|
||||
#include "login.hpp"
|
||||
#include <format>
|
||||
#include <vector>
|
||||
|
||||
@@ -35,8 +36,8 @@ static crow::response rsp(const std::string& msg){
|
||||
|
||||
void initApi(crow::SimpleApp& app)
|
||||
{
|
||||
CROW_ROUTE(app, "/api/shadowrun/submit-character").methods("POST"_method)(
|
||||
[](const crow::request& req) {
|
||||
CROW_ROUTE(app, "/api/shadowrun/submit-character").methods("POST"_method)
|
||||
(login::login_required([](const crow::request& req) {
|
||||
auto params = parse_query_string(req.body);
|
||||
|
||||
auto name_data = params["Character-Info_Name"];
|
||||
@@ -75,20 +76,20 @@ void initApi(crow::SimpleApp& app)
|
||||
return rsp("Failed to store character data");
|
||||
};
|
||||
return rsp(format("Character {} submitted successfully", name_data));
|
||||
});
|
||||
}));
|
||||
|
||||
CROW_ROUTE(app, "/api/shadowrun/character-form")
|
||||
([](const crow::request& req) {
|
||||
(login::login_required([](const crow::request& req) {
|
||||
auto query = crow::query_string(req.url_params);
|
||||
std::string name = query.get("name") ? query.get("name") : "";
|
||||
|
||||
auto data = getCharacterData(getKeyOfCharacter(name));
|
||||
|
||||
return crow::response{ShadowrunCharacterForm(data).htmx()};
|
||||
});
|
||||
}));
|
||||
|
||||
CROW_ROUTE(app, "/api/shadowrun/character-list")
|
||||
([] {
|
||||
(login::login_required([](const crow::request& req) {
|
||||
std::ostringstream html;
|
||||
|
||||
// Simulated character database
|
||||
@@ -106,7 +107,7 @@ void initApi(crow::SimpleApp& app)
|
||||
<< "</form>";
|
||||
|
||||
return crow::response{html.str()};
|
||||
});
|
||||
}));
|
||||
|
||||
if(!shadowrun::initDb()){
|
||||
CROW_LOG_ERROR << "Failed to Init shadowrun database";
|
||||
|
||||
Reference in New Issue
Block a user