diff options
author | Andres Salomon <dilinger@queued.net> | 2021-01-18 04:00:14 -0500 |
---|---|---|
committer | Andres Salomon <dilinger@queued.net> | 2021-01-18 04:00:14 -0500 |
commit | 09eb39236666e81d5da014acea011dcd74d0999b (patch) | |
tree | 52876d96be71be1a39d5d935c1295a51995e8949 /lib/csapi/login.cpp | |
parent | f1788ee27f33e9339334e0d79bde9a27d9ce2e44 (diff) | |
parent | a4e78956f105875625b572d8b98459ffa86fafe5 (diff) | |
download | libquotient-09eb39236666e81d5da014acea011dcd74d0999b.tar.gz libquotient-09eb39236666e81d5da014acea011dcd74d0999b.zip |
Update upstream source from tag 'upstream/0.6.4'
Update to upstream version '0.6.4'
with Debian dir aa8705fd74743e79c043bc9e3e425d5064404cfe
Diffstat (limited to 'lib/csapi/login.cpp')
-rw-r--r-- | lib/csapi/login.cpp | 124 |
1 files changed, 17 insertions, 107 deletions
diff --git a/lib/csapi/login.cpp b/lib/csapi/login.cpp index 5e369b9a..a5bac9ea 100644 --- a/lib/csapi/login.cpp +++ b/lib/csapi/login.cpp @@ -4,78 +4,29 @@ #include "login.h" -#include "converters.h" - #include <QtCore/QStringBuilder> -using namespace QMatrixClient; - -static const auto basePath = QStringLiteral("/_matrix/client/r0"); - -namespace QMatrixClient -{ - // Converters - - template <> struct JsonObjectConverter<GetLoginFlowsJob::LoginFlow> - { - static void fillFrom(const QJsonObject& jo, GetLoginFlowsJob::LoginFlow& result) - { - fromJson(jo.value("type"_ls), result.type); - } - }; -} // namespace QMatrixClient - -class GetLoginFlowsJob::Private -{ - public: - QVector<LoginFlow> flows; -}; +using namespace Quotient; QUrl GetLoginFlowsJob::makeRequestUrl(QUrl baseUrl) { return BaseJob::makeRequestUrl(std::move(baseUrl), - basePath % "/login"); + QStringLiteral("/_matrix/client/r0") + % "/login"); } -static const auto GetLoginFlowsJobName = QStringLiteral("GetLoginFlowsJob"); - GetLoginFlowsJob::GetLoginFlowsJob() - : BaseJob(HttpVerb::Get, GetLoginFlowsJobName, - basePath % "/login", false) - , d(new Private) -{ -} - -GetLoginFlowsJob::~GetLoginFlowsJob() = default; - -const QVector<GetLoginFlowsJob::LoginFlow>& GetLoginFlowsJob::flows() const -{ - return d->flows; -} - -BaseJob::Status GetLoginFlowsJob::parseJson(const QJsonDocument& data) -{ - auto json = data.object(); - fromJson(json.value("flows"_ls), d->flows); - return Success; -} - -class LoginJob::Private -{ - public: - QString userId; - QString accessToken; - QString homeServer; - QString deviceId; - Omittable<DiscoveryInformation> wellKnown; -}; - -static const auto LoginJobName = QStringLiteral("LoginJob"); - -LoginJob::LoginJob(const QString& type, const Omittable<UserIdentifier>& identifier, const QString& password, const QString& token, const QString& deviceId, const QString& initialDeviceDisplayName, const QString& user, const QString& medium, const QString& address) - : BaseJob(HttpVerb::Post, LoginJobName, - basePath % "/login", false) - , d(new Private) + : BaseJob(HttpVerb::Get, QStringLiteral("GetLoginFlowsJob"), + QStringLiteral("/_matrix/client/r0") % "/login", false) +{} + +LoginJob::LoginJob(const QString& type, + const Omittable<UserIdentifier>& identifier, + const QString& password, const QString& token, + const QString& deviceId, + const QString& initialDeviceDisplayName) + : BaseJob(HttpVerb::Post, QStringLiteral("LoginJob"), + QStringLiteral("/_matrix/client/r0") % "/login", false) { QJsonObject _data; addParam<>(_data, QStringLiteral("type"), type); @@ -83,48 +34,7 @@ LoginJob::LoginJob(const QString& type, const Omittable<UserIdentifier>& identif addParam<IfNotEmpty>(_data, QStringLiteral("password"), password); addParam<IfNotEmpty>(_data, QStringLiteral("token"), token); addParam<IfNotEmpty>(_data, QStringLiteral("device_id"), deviceId); - addParam<IfNotEmpty>(_data, QStringLiteral("initial_device_display_name"), initialDeviceDisplayName); - addParam<IfNotEmpty>(_data, QStringLiteral("user"), user); - addParam<IfNotEmpty>(_data, QStringLiteral("medium"), medium); - addParam<IfNotEmpty>(_data, QStringLiteral("address"), address); - setRequestData(_data); + addParam<IfNotEmpty>(_data, QStringLiteral("initial_device_display_name"), + initialDeviceDisplayName); + setRequestData(std::move(_data)); } - -LoginJob::~LoginJob() = default; - -const QString& LoginJob::userId() const -{ - return d->userId; -} - -const QString& LoginJob::accessToken() const -{ - return d->accessToken; -} - -const QString& LoginJob::homeServer() const -{ - return d->homeServer; -} - -const QString& LoginJob::deviceId() const -{ - return d->deviceId; -} - -const Omittable<DiscoveryInformation>& LoginJob::wellKnown() const -{ - return d->wellKnown; -} - -BaseJob::Status LoginJob::parseJson(const QJsonDocument& data) -{ - auto json = data.object(); - fromJson(json.value("user_id"_ls), d->userId); - fromJson(json.value("access_token"_ls), d->accessToken); - fromJson(json.value("home_server"_ls), d->homeServer); - fromJson(json.value("device_id"_ls), d->deviceId); - fromJson(json.value("well_known"_ls), d->wellKnown); - return Success; -} - |