Added better is logging function
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user