feat(auth): add session-based auth service with tests

这个提交包含在:
anygen-build-bot
2026-02-12 09:00:27 +00:00
父节点 76b512939d
当前提交 a6d087d5a9
修改 6 个文件,包含 255 行新增0 行删除

查看文件

@@ -0,0 +1,30 @@
#pragma once
#include "csp/db/sqlite_db.h"
#include <optional>
#include <string>
namespace csp::services {
struct AuthResult {
int user_id = 0;
std::string token;
int64_t expires_at = 0;
};
class AuthService {
public:
explicit AuthService(db::SqliteDb& db) : db_(db) {}
// Throws on error; for controller we will catch and convert to JSON.
AuthResult Register(const std::string& username, const std::string& password);
AuthResult Login(const std::string& username, const std::string& password);
std::optional<int> VerifyToken(const std::string& token);
private:
db::SqliteDb& db_;
};
} // namespace csp::services

查看文件

@@ -0,0 +1,10 @@
#pragma once
#include <string>
namespace csp::crypto {
std::string RandomHex(size_t bytes);
std::string Sha256Hex(const std::string& data);
} // namespace csp::crypto