Added better is logging function

This commit is contained in:
2026-02-09 18:28:01 +01:00
parent fbb54b461e
commit 4ad48d4ecc
4 changed files with 39 additions and 46 deletions

View File

@@ -1,8 +1,8 @@
#include "login.hpp"
#include "crow/http_response.h"
#include "databasepool.h"
#include "utils.hpp"
#include "SessionHandler.hpp"
#include <optional>
namespace login
{
@@ -18,12 +18,22 @@ std::string getSessionId(const crow::request& req) {
return cookie_header.substr(pos + prefix.size(), Session::SESSION_ID_SIZE);
}
bool isLoggedIn(const crow::request& req) {
static crow::response redirectToLogin(){
crow::response res(302); // 302 = temporary redirect
res.set_header("Location", "/");
return res;
}
std::optional<crow::response> isLoggedIn(const crow::request& req) {
std::string sessionId = getSessionId(req);
if (sessionId.empty())
return false;
return std::move(redirectToLogin());
auto userId = sessionHandler.isSessionValid(sessionId);
return userId.has_value();
if(!userId.has_value())
return std::move(redirectToLogin());
return {};
}
std::optional<std::string> loginUser(const std::string& username, const std::string& password)