diff options
| author | isanae <14251494+isanae@users.noreply.github.com> | 2019-07-11 02:31:59 -0400 |
|---|---|---|
| committer | isanae <14251494+isanae@users.noreply.github.com> | 2019-07-11 02:31:59 -0400 |
| commit | ad29525e982f83343dbd70e17b914e0a30adb662 (patch) | |
| tree | 09ee6531679787412b3e16bcdbbe6156a20f9a8c /src/nxmaccessmanager.h | |
| parent | 5e5681709ab878f3aa6cf1344af44e8ae9544987 (diff) | |
moved NexusSSOLogin to nxmaccessmanager
added logs for manual key validation, will need to rewrite a few things
Diffstat (limited to 'src/nxmaccessmanager.h')
| -rw-r--r-- | src/nxmaccessmanager.h | 64 |
1 files changed, 61 insertions, 3 deletions
diff --git a/src/nxmaccessmanager.h b/src/nxmaccessmanager.h index cbec0530..08a799f9 100644 --- a/src/nxmaccessmanager.h +++ b/src/nxmaccessmanager.h @@ -27,6 +27,7 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>. #include <QProgressDialog> #include <QElapsedTimer> #include <QDialogButtonBox> +#include <QWebSocket> #include <set> namespace MOBase { class IPluginGame; } @@ -60,6 +61,52 @@ private: }; +class NexusSSOLogin +{ +public: + enum States + { + ConnectingToSSO, + WaitingForToken, + WaitingForBrowser, + Finished, + Timeout, + ClosedByRemote, + Cancelled, + Error + }; + + std::function<void (QString)> keyChanged; + std::function<void (States, QString)> stateChanged; + + NexusSSOLogin(); + + void start(); + void cancel(); + + bool isActive() const; + +private: + QWebSocket m_socket; + QString m_guid; + bool m_keyReceived; + QString m_token; + bool m_active; + QTimer m_timeout; + + void setState(States s, const QString& error={}); + + void close(); + void abort(); + + void onConnected(); + void onMessage(const QString& s); + void onDisconnected(); + void onError(QAbstractSocket::SocketError e); + void onTimeout(); +}; + + /** * @brief access manager extended to handle nxm links **/ @@ -67,6 +114,15 @@ class NXMAccessManager : public QNetworkAccessManager { Q_OBJECT public: + enum ApiCheckFlagsEnum + { + NoFlags = 0, + Force, + HideProgress + }; + + Q_DECLARE_FLAGS(ApiCheckFlags, ApiCheckFlagsEnum) + static const std::chrono::seconds ValidationTimeout; explicit NXMAccessManager(QObject *parent, const QString &moVersion); @@ -80,7 +136,7 @@ public: bool validateAttempted() const; bool validateWaiting() const; - void apiCheck(const QString &apiKey, bool force=false); + void apiCheck(const QString &apiKey, ApiCheckFlags flags=NoFlags); void showCookies() const; @@ -91,8 +147,6 @@ public: QString apiKey() const; void clearApiKey(); - void startValidationCheck(); - void refuseValidation(); signals: @@ -145,6 +199,10 @@ private: VALIDATE_REFUSED, VALIDATE_VALID } m_ValidateState = VALIDATE_NOT_CHECKED; + + void startValidationCheck(bool showProgress); }; +Q_DECLARE_OPERATORS_FOR_FLAGS(NXMAccessManager::ApiCheckFlags); + #endif // NXMACCESSMANAGER_H |
