first commit
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
#ifndef TAUTH_H
|
||||
#define TAUTH_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
|
||||
class QTcpServer;
|
||||
class QTcpSocket;
|
||||
|
||||
class TAuth : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit TAuth(QObject *parent = nullptr);
|
||||
~TAuth();
|
||||
|
||||
// Запуск сервера с указанием режима работы
|
||||
void startServer(const QString &authUrl, bool openBrowser = true);
|
||||
void stopServer();
|
||||
|
||||
// Получить URL для отображения (если не открываем браузер)
|
||||
QString getAuthUrl() const { return m_authUrl; }
|
||||
|
||||
// Получить порт, на котором запущен сервер
|
||||
int getServerPort() const { return m_serverPort; }
|
||||
|
||||
signals:
|
||||
void tokenReceived(const QString &token);
|
||||
void errorOccurred(const QString &error);
|
||||
// Новый сигнал для передачи кода авторизации
|
||||
void codeReceived(const QString &code);
|
||||
// Сигнал о запуске сервера
|
||||
void serverStarted(int port);
|
||||
|
||||
private slots:
|
||||
void handleNewConnection();
|
||||
void readClientData();
|
||||
|
||||
private:
|
||||
QTcpServer *m_server;
|
||||
QTcpSocket *m_clientSocket;
|
||||
QString m_authUrl;
|
||||
int m_serverPort;
|
||||
bool m_autoOpenBrowser;
|
||||
|
||||
void handleRootRequest(QTcpSocket *socket);
|
||||
void handleRedirectRequest(const QString &request, QTcpSocket *socket);
|
||||
void sendResponse(QTcpSocket *socket, const QString &content);
|
||||
void sendErrorResponse(QTcpSocket *socket, const QString &error);
|
||||
|
||||
void extractAndEmitToken(const QString ¶ms);
|
||||
void extractAndEmitError(const QString ¶ms);
|
||||
void extractAndEmitCode(const QString ¶ms);
|
||||
QString extractErrorDescription(const QString ¶ms);
|
||||
|
||||
// Вспомогательные методы для извлечения параметров
|
||||
QString extractParam(const QString ¶ms, const QString ¶mName);
|
||||
QString extractExpiresIn(const QString ¶ms);
|
||||
};
|
||||
|
||||
#endif // TAUTH_H
|
||||
Reference in New Issue
Block a user