api basic routes
This commit is contained in:
18
include/auth_middleware.hpp
Normal file
18
include/auth_middleware.hpp
Normal file
@@ -0,0 +1,18 @@
|
||||
#ifndef AUTH_MIDDLEWARE_HPP
|
||||
#define AUTH_MIDDLEWARE_HPP
|
||||
#include "crow.h"
|
||||
#include "types.hpp"
|
||||
#include <vector>
|
||||
#include <database.hpp>
|
||||
|
||||
struct UserAuthMiddleware {
|
||||
struct context {
|
||||
User user;
|
||||
};
|
||||
|
||||
void before_handle(crow::request& req, crow::response& res, context& ctx);
|
||||
|
||||
void after_handle(crow::request& req, crow::response& res, context& ctx) {};
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef DATABASE_HPP
|
||||
#define DATABASE_HPP
|
||||
#include "types.hpp"
|
||||
#include "timestamp.hpp"
|
||||
#include "utils.hpp"
|
||||
#include <chrono>
|
||||
#include <optional>
|
||||
|
||||
@@ -28,10 +28,11 @@ public:
|
||||
|
||||
void CreateAccessToken(User& user);
|
||||
void DeleteAccessToken(const User& user);
|
||||
User ValidateAccessToken(const std::string& token);
|
||||
|
||||
void StartFront(const User& user, const Member& member, const std::string& note = "", Timestamp start_time = std::chrono::system_clock::now());
|
||||
void EndFront(const User& user, const Member& member, Timestamp end_time = std::chrono::system_clock::now());
|
||||
std::vector<Front> GetFronts(const User& user, Timestamp start_time, std::optional<Timestamp> end_time = std::nullopt);
|
||||
void StartFront(const User& user, const Member& member, const std::string& note = "", timestamp::Timestamp start_time = timestamp::Now());
|
||||
void EndFront(const User& user, const Member& member, timestamp::Timestamp end_time = timestamp::Now());
|
||||
std::vector<Front> GetFronts(const User& user, timestamp::Timestamp start_time, std::optional<timestamp::Timestamp> end_time = std::nullopt);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,11 +0,0 @@
|
||||
#ifndef TIMESTAMP_HPP
|
||||
#define TIMESTAMP_HPP
|
||||
#include <chrono>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
|
||||
typedef std::chrono::system_clock::time_point Timestamp;
|
||||
|
||||
Timestamp ParseTimestamp(const std::string& ts);
|
||||
|
||||
#endif
|
||||
@@ -2,8 +2,7 @@
|
||||
#define TYPES_HPP
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <chrono>
|
||||
#include "hashing.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
struct AcessToken {
|
||||
int uid;
|
||||
@@ -62,9 +61,9 @@ struct Front {
|
||||
int uid;
|
||||
Member *member;
|
||||
std::string note;
|
||||
std::chrono::system_clock::time_point start_time;
|
||||
timestamp::Timestamp start_time;
|
||||
bool is_active;
|
||||
std::chrono::system_clock::time_point end_time;
|
||||
timestamp::Timestamp end_time;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,6 +1,9 @@
|
||||
#ifndef HASHING_HPP
|
||||
#define HASHING_HPP
|
||||
#ifndef UTILS_HPP
|
||||
#define UTILS_HPP
|
||||
#include <string>
|
||||
#include <chrono>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
|
||||
namespace hashing {
|
||||
std::string GenerateSetting(unsigned long cost = 0);
|
||||
@@ -9,4 +12,12 @@ namespace hashing {
|
||||
std::string generate_token(size_t bytes = 32);
|
||||
}
|
||||
|
||||
namespace timestamp {
|
||||
typedef std::chrono::system_clock::time_point Timestamp;
|
||||
|
||||
Timestamp ParseTimestamp(const std::string& ts);
|
||||
Timestamp Now();
|
||||
std::string FormatTimestamp(const Timestamp& ts);
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user