LeechCraft 0.6.70-19424-g027e980fd1
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 QNetworkReply;
22class QTimer;
23
24template<typename>
25class QFuture;
26
27class IWebWidget;
28
29namespace LC::Util
30{
31class QueueManager;
32enum class QueuePriority;
33
34class CustomCookieJar;
35
36namespace SvcAuth
37{
38 class UTIL_SVCAUTH_API VkAuthManager : public QObject
39 {
40 Q_OBJECT
41
42 ICoreProxy_ptr Proxy_;
43
44 const QString AccountHR_;
45
46 std::unique_ptr<IWebWidget> Browser_;
47
48 QNetworkAccessManager * const AuthNAM_;
49 Util::CustomCookieJar * const Cookies_;
50
51 QueueManager * const Queue_;
52
53 QString Token_;
54 QDateTime ReceivedAt_;
55 qint32 ValidFor_ = 0;
56
57 bool IsRequesting_ = false;
58
59 const QString ID_;
60 QUrl URL_;
61
62 bool IsRequestScheduled_ = false;
63 QTimer * const ScheduleTimer_;
64
65 bool SilentMode_ = false;
66
67 bool HasTracked_ = false;
68 public:
69 using RequestQueue_t = QList<std::function<void (QString)>> ;
71
72 using PrioRequestQueue_t = QList<std::pair<std::function<void (QString)>, QueuePriority>>;
74
76 private:
77 QList<RequestQueue_ptr> ManagedQueues_;
78 QList<PrioRequestQueue_ptr> PrioManagedQueues_;
79 public:
80 VkAuthManager (const QString& accountName, const QString& clientId,
81 const QStringList& scope, const QByteArray& cookies,
82 const ICoreProxy_ptr&, QueueManager* = nullptr, QObject* = nullptr);
83 ~VkAuthManager () override;
84
85 bool IsAuthenticated () const;
86 bool HadAuthentication () const;
87
88 void UpdateScope (const QStringList&);
89
90 void GetAuthKey ();
91
92 struct SilentMode {};
93 using AuthKeyError_t = std::variant<SilentMode>;
95
97
100
101 void SetSilentMode (bool);
102
103 void ClearAuthData ();
104 void Reauth ();
105 private:
106 void InvokeQueues (const QString&);
107
108 void RequestURL (const QUrl&);
109 void RequestAuthKey ();
110 bool CheckReply (QUrl);
111 bool CheckError (const QUrl&);
112
113 void ScheduleTrack (const QString&);
114 void HandleGotForm (QNetworkReply*);
115 private slots:
116 void handleUrlChanged (const QUrl&);
117 signals:
118 void gotAuthKey (const QString&);
119 void cookiesChanged (const QByteArray&);
122 };
123}
124}
Common interface for a web widget.
Definition iwebbrowser.h:24
A simple scheduling manager for a queue of functors.
Util::DefaultScopeGuard ScheduleGuard_t
ScheduleGuard_t ManageQueue(RequestQueue_ptr)
PrioRequestQueue_t * PrioRequestQueue_ptr
QList< std::pair< std::function< void(QString)>, QueuePriority > > PrioRequestQueue_t
QList< std::function< void(QString)> > RequestQueue_t
QFuture< AuthKeyResult_t > GetAuthKeyFuture()
Either< AuthKeyError_t, QString > AuthKeyResult_t
void UpdateScope(const QStringList &)
std::variant< SilentMode > AuthKeyError_t
void cookiesChanged(const QByteArray &)
void gotAuthKey(const QString &)
VkAuthManager(const QString &accountName, const QString &clientId, const QStringList &scope, const QByteArray &cookies, const ICoreProxy_ptr &, QueueManager *=nullptr, QObject *=nullptr)
std::shared_ptr< ICoreProxy > ICoreProxy_ptr
Definition icoreproxy.h:177
QueuePriority
The priority of the action in the queue.
detail::ScopeGuard< detail::DefaultScopeGuardDeleter > DefaultScopeGuard
Definition util.h:132
#define UTIL_SVCAUTH_API