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

@@ -1,15 +1,13 @@
#include "login.hpp"
#include "crow/http_response.h"
#include "databasepool.h"
#include "SessionHandler.hpp"
#include <optional>
namespace login
{
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");
std::string prefix = "session_id=";
auto pos = cookie_header.find(prefix);
@@ -24,6 +22,15 @@ static crow::response redirectToLogin(){
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::string sessionId = getSessionId(req);
if (sessionId.empty())
@@ -36,15 +43,6 @@ std::optional<crow::response> isLoggedIn(const crow::request& req) {
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){
createUser("lukas", "Trollar4928");