| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
#pragma once |
| 6 |
|
| 7 |
#include <QObject> |
| 8 |
#include <QQmlEngine> |
| 9 |
|
| 10 |
#include <mtxclient/http/client.hpp> |
| 11 |
|
| 12 |
#include "FallbackAuth.h" |
| 13 |
#include "ReCaptcha.h" |
| 14 |
|
| 15 |
class UIA final : public QObject |
| 16 |
{ |
| 17 |
Q_OBJECT |
| 18 |
|
| 19 |
QML_ELEMENT |
| 20 |
QML_SINGLETON |
| 21 |
|
| 22 |
Q_PROPERTY(QString title READ title NOTIFY titleChanged) |
| 23 |
|
| 24 |
public: |
| 25 |
static UIA *instance(); |
| 26 |
static UIA *create(QQmlEngine *qmlEngine, QJSEngine *) |
| 27 |
{ |
| 28 |
|
| 29 |
Q_ASSERT(instance()); |
| 30 |
|
| 31 |
|
| 32 |
Q_ASSERT(qmlEngine->thread() == instance()->thread()); |
| 33 |
|
| 34 |
|
| 35 |
static QJSEngine *s_engine = nullptr; |
| 36 |
if (s_engine) |
| 37 |
Q_ASSERT(qmlEngine == s_engine); |
| 38 |
else |
| 39 |
s_engine = qmlEngine; |
| 40 |
|
| 41 |
QJSEngine::setObjectOwnership(instance(), QJSEngine::CppOwnership); |
| 42 |
return instance(); |
| 43 |
} |
| 44 |
|
| 45 |
UIA(QObject *parent) |
| 46 |
: QObject(parent) |
| 47 |
{ |
| 48 |
} |
| 49 |
|
| 50 |
mtx::http::UIAHandler genericHandler(QString context); |
| 51 |
|
| 52 |
QString title() const { return title_; } |
| 53 |
|
| 54 |
public slots: |
| 55 |
void continuePassword(const QString &password); |
| 56 |
void continueEmail(const QString &email); |
| 57 |
void continuePhoneNumber(const QString &countryCode, const QString &phoneNumber); |
| 58 |
void submit3pidToken(const QString &token); |
| 59 |
void continue3pidReceived(); |
| 60 |
|
| 61 |
signals: |
| 62 |
void password(); |
| 63 |
void email(); |
| 64 |
void phoneNumber(); |
| 65 |
void reCaptcha(ReCaptcha *recaptcha); |
| 66 |
void fallbackAuth(FallbackAuth *fallback); |
| 67 |
|
| 68 |
void confirm3pidToken(); |
| 69 |
void prompt3pidToken(); |
| 70 |
void tokenAccepted(); |
| 71 |
|
| 72 |
void titleChanged(); |
| 73 |
void error(QString msg); |
| 74 |
|
| 75 |
private: |
| 76 |
std::optional<mtx::http::UIAHandler> currentHandler; |
| 77 |
mtx::user_interactive::Unauthorized currentStatus; |
| 78 |
QString title_; |
| 79 |
|
| 80 |
|
| 81 |
std::string client_secret; |
| 82 |
std::string sid; |
| 83 |
std::string submit_url; |
| 84 |
bool email_ = true; |
| 85 |
}; |