updated include to be more scoped
This commit is contained in:
@@ -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";
|
||||||
|
|||||||
@@ -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");
|
||||||
|
|||||||
@@ -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 {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include "json.hpp"
|
#include "json.hpp"
|
||||||
#include "utils.hpp"
|
#include "utils.hpp"
|
||||||
|
|
||||||
namespace login
|
namespace login
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -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 {
|
||||||
|
|||||||
@@ -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"
|
||||||
|
|
||||||
|
|||||||
@@ -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 {
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user