LeechCraft 0.6.70-14794-g33744ae6ce
Modular cross-platform feature rich live environment.
Loading...
Searching...
No Matches
vkauthmanager.h
Go to the documentation of this file.
1/**********************************************************************
2 * LeechCraft - modular cross-platform feature rich internet client.
3 * Copyright (C) 2006-2014 Georg Rudoy
4 *
5 * Distributed under the Boost Software License, Version 1.0.
6 * (See accompanying file LICENSE or copy at https://www.boost.org/LICENSE_1_0.txt)
7 **********************************************************************/
8
9#pragma once
10
11#include <functional>
12#include <variant>
13#include <QObject>
14#include <QDateTime>
15#include <QUrl>
17#include <util/sll/util.h>
18#include <util/sll/eitherfwd.h>
19#include "svcauthconfig.h"
20
21class QTimer;
22
23template<typename>
24class QFuture;
25
26namespace LC::Util
27{
28class QueueManager;
29enum class QueuePriority;
30
31class CustomCookieJar;
32
33namespace SvcAuth
34{
35 class UTIL_SVCAUTH_API VkAuthManager : public QObject
36 {
37 Q_OBJECT
38
39 ICoreProxy_ptr Proxy_;
40
41 const QString AccountHR_;
42
43 QNetworkAccessManager * const AuthNAM_;
44 Util::CustomCookieJar * const Cookies_;
45
46 QueueManager * const Queue_;
47
48 QString Token_;
49 QDateTime ReceivedAt_;
50 qint32 ValidFor_ = 0;
51
52 bool IsRequesting_ = false;
53
54 const QString ID_;
55 QUrl URL_;
56
57 bool IsRequestScheduled_ = false;
58 QTimer * const ScheduleTimer_;
59
60 bool SilentMode_ = false;
61
62 bool HasTracked_ = false;
63 public:
64 using RequestQueue_t = QList<std::function<void (QString)>> ;
66
67 using PrioRequestQueue_t = QList<QPair<std::function<void (QString)>, QueuePriority>>;
69
71 private:
72 QList<RequestQueue_ptr> ManagedQueues_;
73 QList<PrioRequestQueue_ptr> PrioManagedQueues_;
74 public:
75 VkAuthManager (const QString& accountName, const QString& clientId,
76 const QStringList& scope, const QByteArray& cookies,
77 const ICoreProxy_ptr&, QueueManager* = nullptr, QObject* = nullptr);
78
79 bool IsAuthenticated () const;
80 bool HadAuthentication () const;
81
82 void UpdateScope (const QStringList&);
83
84 void GetAuthKey ();
85
86 struct SilentMode {};
87 using AuthKeyError_t = std::variant<SilentMode>;
89
90 [[nodiscard]] QFuture<AuthKeyResult_t> GetAuthKeyFuture ();
91
92 [[nodiscard]] ScheduleGuard_t ManageQueue (RequestQueue_ptr);
93 [[nodiscard]] ScheduleGuard_t ManageQueue (PrioRequestQueue_ptr);
94
95 void SetSilentMode (bool);
96
97 void ClearAuthData ();
98 void Reauth ();
99 private:
100 void InvokeQueues (const QString&);
101
102 void RequestURL (const QUrl&);
103 void RequestAuthKey ();
104 bool CheckReply (QUrl);
105 bool CheckError (const QUrl&);
106
107 void ScheduleTrack (const QString&);
108 void HandleGotForm (QNetworkReply*);
109 private slots:
110 void handleUrlChanged (const QUrl&);
111 signals:
112 void gotAuthKey (const QString&);
113 void cookiesChanged (const QByteArray&);
116 };
117}
118}
A simple scheduling manager for a queue of functors.
Definition: queuemanager.h:44
std::variant< SilentMode > AuthKeyError_t
Definition: vkauthmanager.h:87
void cookiesChanged(const QByteArray &)
void gotAuthKey(const QString &)
std::shared_ptr< ICoreProxy > ICoreProxy_ptr
Definition: icoreproxy.h:181
QueuePriority
The priority of the action in the queue.
Definition: queuemanager.h:28
#define UTIL_SVCAUTH_API
Definition: svcauthconfig.h:16