feat(auth): add session-based auth service with tests
这个提交包含在:
@@ -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
|
||||
在新工单中引用
屏蔽一个用户