Files
amnezia-client/client/ui/controllers/api/subscriptionUiController.h
T
yp bcee58b08b feat: add captcha (#2508)
* test capcha

* add test AMNEZIA_GATEWAY_PLAINTEXT_MOCK

* ref

* remove first QNetworkReply::NoError

* fixed macros

* fixed http code

* add test server

* fix cmake

* add CAPTCHA refreshed

* fixed captcha

* update QML Captha

* fixed crash app & up vercion & fix qml captha

* ver 4.9.0.1

* remove m_gatewayCaptchaStickyBase & outEffectiveRequestBase

* reset code PR

* remove mock & temp var AMNEZIA_LOCAL_GATEWAY

* ref code & remove AMNEZIA_LOCAL_GATEWAY

* remove check httpStatusCode & error

* add 408 status code

* fix update captca

* remove fallback на transport

* chore: add loader after captcha solved

* chore: remove logs from api utils

* chore: minor fixes

---------

Co-authored-by: vkamn <vk@amnezia.org>
2026-05-28 13:51:26 +08:00

131 lines
5.1 KiB
C++

#ifndef SUBSCRIPTIONUICONTROLLER_H
#define SUBSCRIPTIONUICONTROLLER_H
#include <QObject>
#include "core/controllers/serversController.h"
#include "core/controllers/settingsController.h"
#include "core/controllers/connectionController.h"
#include "core/controllers/api/servicesCatalogController.h"
#include "core/controllers/api/subscriptionController.h"
#include "ui/models/api/apiSubscriptionPlansModel.h"
#include "ui/models/api/apiBenefitsModel.h"
#include "ui/models/api/apiServicesModel.h"
#include "ui/models/api/apiAccountInfoModel.h"
#include "ui/models/api/apiCountryModel.h"
#include "ui/models/api/apiDevicesModel.h"
class SubscriptionUiController : public QObject
{
Q_OBJECT
public:
SubscriptionUiController(ServersController* serversController,
ApiServicesModel* apiServicesModel,
ServicesCatalogController* servicesCatalogController,
SubscriptionController* subscriptionController,
ApiSubscriptionPlansModel* apiSubscriptionPlansModel,
ApiBenefitsModel* apiBenefitsModel,
ApiAccountInfoModel* apiAccountInfoModel,
ApiCountryModel* apiCountryModel,
ApiDevicesModel* apiDevicesModel,
SettingsController* settingsController,
ConnectionController* connectionController,
QObject *parent = nullptr);
Q_PROPERTY(QList<QString> qrCodes READ getQrCodes NOTIFY vpnKeyExportReady)
Q_PROPERTY(int qrCodesCount READ getQrCodesCount NOTIFY vpnKeyExportReady)
Q_PROPERTY(QString vpnKey READ getVpnKey NOTIFY vpnKeyExportReady)
public slots:
bool exportNativeConfig(const QString &serverId, const QString &serverCountryCode, const QString &fileName);
bool revokeNativeConfig(const QString &serverId, const QString &serverCountryCode);
bool exportVpnKey(const QString &serverId, const QString &fileName);
void prepareVpnKeyExport(const QString &serverId);
void copyVpnKeyToClipboard();
bool fillAvailableServices();
bool importPremiumFromAppStore(const QString &storeProductId);
bool importFreeFromGateway();
bool restoreServiceFromAppStore();
bool importTrialFromGateway(const QString &email);
bool updateServiceFromGateway(const QString &serverId, const QString &newCountryCode, const QString &newCountryName,
bool reloadServiceConfig = false);
bool deactivateDevice(const QString &serverId);
bool deactivateExternalDevice(const QString &serverId, const QString &uuid, const QString &serverCountryCode);
void validateConfig();
void setCurrentProtocol(const QString &serverId, const QString &protocolName);
bool isVlessProtocol(const QString &serverId);
bool isCaptchaAwaitingUser() const;
void onCaptchaSolved(const QString &captchaId, const QString &solution);
void onRefreshCaptchaRequested();
void removeApiConfig(const QString &serverId);
void removeServer(const QString &serverId);
bool getAccountInfo(const QString &serverId, bool reload);
void getRenewalLink(const QString &serverId);
void updateApiCountryModel();
void updateApiDevicesModel();
signals:
void configValidated(bool isValid);
void errorOccurred(ErrorCode errorCode);
void trialEmailError(const QString &message);
void subscriptionExpiredOnServer();
void renewalLinkReceived(const QString &url);
void installServerFromApiFinished(const QString &message, int preferredDefaultServerIndex = -1);
void changeApiCountryFinished(const QString &message);
void reloadServerFromApiFinished(const QString &message);
void updateServerFromApiFinished();
void subscriptionRefreshNeeded();
void apiConfigRemoved(const QString &message);
void apiServerRemoved(const QString &message);
void vpnKeyExportReady();
void captchaRequired(const QString &captchaId, const QString &captchaImageBase64, const QString &hint);
void captchaFlowDismissRequested();
void unsupportedConnectDrawerRequested();
private:
struct CaptchaState {
QString userCountryCode;
QString serviceType;
QString serviceProtocol;
QString openvpnPrivKey;
QString wireguardClientPrivKey;
QString wireguardClientPubKey;
QString xrayUuid;
bool isPending = false;
} m_captchaState;
private:
QList<QString> getQrCodes();
int getQrCodesCount();
QString getVpnKey();
QList<QString> m_qrCodes;
QString m_vpnKey;
ServersController* m_serversController;
ApiServicesModel* m_apiServicesModel;
ServicesCatalogController* m_servicesCatalogController;
SubscriptionController* m_subscriptionController;
ApiSubscriptionPlansModel* m_apiSubscriptionPlansModel;
ApiBenefitsModel* m_apiBenefitsModel;
ApiAccountInfoModel* m_apiAccountInfoModel;
ApiCountryModel* m_apiCountryModel;
ApiDevicesModel* m_apiDevicesModel;
SettingsController* m_settingsController;
ConnectionController* m_connectionController;
};
#endif // SUBSCRIPTIONUICONTROLLER_H