LeechCraft  0.6.70-15082-g543737046d
Modular cross-platform feature rich live environment.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules
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 
21 class QTimer;
22 
23 template<typename>
24 class QFuture;
25 
26 class IWebWidget;
27 
28 namespace LC::Util
29 {
30 class QueueManager;
31 enum class QueuePriority;
32 
33 class CustomCookieJar;
34 
35 namespace 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 
95  [[nodiscard]] QFuture<AuthKeyResult_t> GetAuthKeyFuture ();
96 
97  [[nodiscard]] ScheduleGuard_t ManageQueue (RequestQueue_ptr);
98  [[nodiscard]] ScheduleGuard_t ManageQueue (PrioRequestQueue_ptr);
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&);
119  void authCanceled ();
120  void justAuthenticated ();
121  };
122 }
123 }
LC::Util::SvcAuth::VkAuthManager
Definition: vkauthmanager.h:37
LC::Util::SvcAuth::VkAuthManager::AuthKeyError_t
std::variant< SilentMode > AuthKeyError_t
Definition: vkauthmanager.h:92
LC::Util::DefaultScopeGuard
detail::ScopeGuard< detail::DefaultScopeGuardDeleter > DefaultScopeGuard
Definition: util.h:125
QList
Definition: ianrulesstorage.h:14
icoreproxy.h
LC::Util::QueuePriority
QueuePriority
The priority of the action in the queue.
Definition: queuemanager.h:27
LC::Util
Definition: icoreproxy.h:33
LC::Util::Either
Definition: either.h:33
UTIL_SVCAUTH_API
#define UTIL_SVCAUTH_API
Definition: svcauthconfig.h:16
util.h
LC::Util::QueueManager
A simple scheduling manager for a queue of functors.
Definition: queuemanager.h:43
ICoreProxy_ptr
std::shared_ptr< ICoreProxy > ICoreProxy_ptr
Definition: icoreproxy.h:181
IWebWidget
Common interface for a web widget.
Definition: iwebbrowser.h:23
LC::Util::detail::ScopeGuard
Definition: util.h:61
svcauthconfig.h
QFuture
Definition: idownload.h:17
LC::Util::SvcAuth::VkAuthManager::SilentMode
Definition: vkauthmanager.h:91
eitherfwd.h