This commit is contained in:
doomtube 2025-08-10 07:55:39 -04:00
parent 4c23ab840a
commit e8864cc853
15 changed files with 4004 additions and 1593 deletions

View file

@ -1,19 +1,20 @@
#pragma once
#include <drogon/drogon.h>
#include <bcrypt/BCrypt.hpp>
#include <jwt-cpp/jwt.h>
#include <string>
#include <functional>
#include <memory>
#include <jwt-cpp/jwt.h>
#include <bcrypt/BCrypt.hpp>
struct UserInfo {
int64_t id;
int64_t id = 0;
std::string username;
bool isAdmin;
bool isStreamer;
bool isPgpOnly;
bool isAdmin = false;
bool isStreamer = false;
bool isPgpOnly = false;
std::string bio;
std::string avatarUrl;
std::string pgpOnlyEnabledAt;
std::string colorCode;
};
class AuthService {
@ -23,41 +24,38 @@ public:
return instance;
}
// User registration
void registerUser(const std::string& username, const std::string& password,
const std::string& publicKey, const std::string& fingerprint,
std::function<void(bool success, const std::string& error, int64_t userId)> callback);
std::function<void(bool, const std::string&, int64_t)> callback);
// User login with password
void loginUser(const std::string& username, const std::string& password,
std::function<void(bool success, const std::string& token, const UserInfo& user)> callback);
std::function<void(bool, const std::string&, const UserInfo&)> callback);
// User login with PGP (returns challenge)
void initiatePgpLogin(const std::string& username,
std::function<void(bool success, const std::string& challenge, const std::string& publicKey)> callback);
std::function<void(bool, const std::string&, const std::string&)> callback);
// Verify PGP signature
void verifyPgpLogin(const std::string& username, const std::string& signature, const std::string& challenge,
std::function<void(bool success, const std::string& token, const UserInfo& user)> callback);
void verifyPgpLogin(const std::string& username, const std::string& signature,
const std::string& challenge,
std::function<void(bool, const std::string&, const UserInfo&)> callback);
// Validate JWT token
std::string generateToken(const UserInfo& user);
bool validateToken(const std::string& token, UserInfo& userInfo);
// Update password
void updatePassword(int64_t userId, const std::string& oldPassword, const std::string& newPassword,
std::function<void(bool success, const std::string& error)> callback);
// New method to fetch complete user info including color
void fetchUserInfo(int64_t userId, std::function<void(bool, const UserInfo&)> callback);
// Check password requirements
bool validatePassword(const std::string& password, std::string& error);
void updatePassword(int64_t userId, const std::string& oldPassword,
const std::string& newPassword,
std::function<void(bool, const std::string&)> callback);
// Generate JWT token
std::string generateToken(const UserInfo& user);
void updateUserColor(int64_t userId, const std::string& newColor,
std::function<void(bool, const std::string&, const std::string&)> callback);
void generateUniqueColor(std::function<void(const std::string& color)> callback);
private:
AuthService() = default;
~AuthService() = default;
AuthService(const AuthService&) = delete;
AuthService& operator=(const AuthService&) = delete;
std::string jwtSecret_;
bool validatePassword(const std::string& password, std::string& error);
};