updated include to be more scoped

This commit is contained in:
2026-02-23 14:08:18 +01:00
parent a48ff4780b
commit b03d9bf998
9 changed files with 17 additions and 18 deletions

View File

@@ -3,7 +3,6 @@
#include "json.hpp" #include "json.hpp"
#include <string> #include <string>
namespace AppSettings { namespace AppSettings {
static constexpr char settingsFile[] = "assets/settings.json"; static constexpr char settingsFile[] = "assets/settings.json";

View File

@@ -1,15 +1,13 @@
#include "login.hpp" #include "login.hpp"
#include "crow/http_response.h"
#include "databasepool.h" #include "databasepool.h"
#include "SessionHandler.hpp" #include "SessionHandler.hpp"
#include <optional>
namespace login namespace login
{ {
SessionHandler sessionHandler; SessionHandler sessionHandler;
std::string getSessionId(const crow::request& req) { static std::string getSessionId(const crow::request& req) {
auto cookie_header = req.get_header_value("Cookie"); auto cookie_header = req.get_header_value("Cookie");
std::string prefix = "session_id="; std::string prefix = "session_id=";
auto pos = cookie_header.find(prefix); auto pos = cookie_header.find(prefix);
@@ -24,6 +22,15 @@ static crow::response redirectToLogin(){
return res; return res;
} }
static std::optional<std::string> loginUser(const std::string& username, const std::string& password)
{
auto user = getVerifiedUser(username, password);
if (user) {
return sessionHandler.createSession(user->id);
}
return {};
}
std::optional<crow::response> isLoggedIn(const crow::request& req) { std::optional<crow::response> isLoggedIn(const crow::request& req) {
std::string sessionId = getSessionId(req); std::string sessionId = getSessionId(req);
if (sessionId.empty()) if (sessionId.empty())
@@ -36,15 +43,6 @@ std::optional<crow::response> isLoggedIn(const crow::request& req) {
return {}; return {};
} }
std::optional<std::string> loginUser(const std::string& username, const std::string& password)
{
auto user = getVerifiedUser(username, password);
if (user) {
return sessionHandler.createSession(user->id);
}
return {};
}
void initLogin(crow::App<crow::CORSHandler>& app){ void initLogin(crow::App<crow::CORSHandler>& app){
createUser("lukas", "Trollar4928"); createUser("lukas", "Trollar4928");

View File

@@ -3,7 +3,8 @@
#pragma once #pragma once
#include <crow.h> #include <crow/http_response.h>
#include <crow/app.h>
#include "crow/middlewares/cors.h" #include "crow/middlewares/cors.h"
namespace login { namespace login {

View File

@@ -5,6 +5,7 @@
#include <vector> #include <vector>
#include "json.hpp" #include "json.hpp"
#include "utils.hpp" #include "utils.hpp"
namespace login namespace login
{ {

View File

@@ -3,6 +3,7 @@
#include "ShadowrunApi.hpp" #include "ShadowrunApi.hpp"
#include "ShadowrunDb.hpp" #include "ShadowrunDb.hpp"
#include "login.hpp" #include "login.hpp"
#include "magic_enum.hpp"
#include <vector> #include <vector>
using namespace std; using namespace std;

View File

@@ -1,7 +1,7 @@
#ifndef __SHADOWRUNAPI_H__ #ifndef __SHADOWRUNAPI_H__
#define __SHADOWRUNAPI_H__ #define __SHADOWRUNAPI_H__
#include "crow.h" #include "crow/app.h"
#include "crow/middlewares/cors.h" #include "crow/middlewares/cors.h"
namespace shadowrun { namespace shadowrun {

View File

@@ -1,6 +1,7 @@
#include "ShadowrunDb.hpp" #include "ShadowrunDb.hpp"
#include <optional> #include <optional>
#include "databasepool.h" #include "databasepool.h"
#include "magic_enum.hpp"
#include "utils.hpp" #include "utils.hpp"
#include "crow/logging.h" #include "crow/logging.h"

View File

@@ -7,8 +7,6 @@
#include <optional> #include <optional>
#include "json.hpp" #include "json.hpp"
#include "utils.hpp" #include "utils.hpp"
#include "sqlite_orm.h"
#include "magic_enum.hpp"
namespace shadowrun { namespace shadowrun {
enum class Type { enum class Type {

View File

@@ -7,7 +7,7 @@
#include <filesystem> #include <filesystem>
#include <expected> #include <expected>
#include "json.hpp" #include "json.hpp"
#include "crow.h" #include "crow/http_response.h"
namespace utils { namespace utils {
// Svelte genereated files // Svelte genereated files