geopro/src/net/AuthService.hpp

44 lines
1.6 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#pragma once
#include <QString>
#include <string>
namespace geopro::net {
class ApiClient;
class CaptchaLoad;
class LoginLoad;
// 登录编排:复刻已实测通过的 getImageCode -> verifyCodeCheck -> RSA -> login2 流程。
// 依赖外部注入的 ApiClient单实例、共享会话RSA 公钥 PEM 由调用方读取后传入。
// 异步fetchCaptchaAsync/loginAsync 立即返回自管理句柄net 层 CaptchaLoad/LoginLoad
// 不阻塞 UI句柄 done/failed 后自 deleteLater。AuthService 自身只创建句柄,无需是 QObject。
class AuthService {
public:
AuthService(ApiClient& api, std::string rsaPublicKeyPem);
// 验证码:服务端返回 data.id + data.imagebase64 PNG 图用户照图输入data.code 已不返回。
struct Captcha {
QString codeId;
QString code; // 旧字段(后端已不返回明文,保留兼容)
QString image; // data URL base64 PNG后端 getImageCode 实际返回的验证码图)
};
// 异步拉验证码GET getImageCode返回句柄连 CaptchaLoad::done(Captcha)/failed(QString)。
CaptchaLoad* fetchCaptchaAsync();
// 异步登录verifyCodeCheck -> RSA 加密密码 -> login2依赖链
// 返回句柄,连 LoginLoad::done(token)/failed(QString)。
LoginLoad* loginAsync(const QString& username, const QString& password, const QString& code,
const QString& codeId);
private:
ApiClient& api_;
std::string rsaPublicKeyPem_;
};
} // namespace geopro::net
#include <QMetaType>
Q_DECLARE_METATYPE(geopro::net::AuthService::Captcha)