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