aboutsummaryrefslogtreecommitdiff
path: root/lib/csapi/registration.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/csapi/registration.cpp')
-rw-r--r--lib/csapi/registration.cpp341
1 files changed, 88 insertions, 253 deletions
diff --git a/lib/csapi/registration.cpp b/lib/csapi/registration.cpp
index 320ec796..04c0fe12 100644
--- a/lib/csapi/registration.cpp
+++ b/lib/csapi/registration.cpp
@@ -4,292 +4,127 @@
#include "registration.h"
-#include "converters.h"
+using namespace Quotient;
-#include <QtCore/QStringBuilder>
-
-using namespace QMatrixClient;
-
-static const auto basePath = QStringLiteral("/_matrix/client/r0");
-
-class RegisterJob::Private
-{
- public:
- QString userId;
- QString accessToken;
- QString homeServer;
- QString deviceId;
-};
-
-BaseJob::Query queryToRegister(const QString& kind)
+auto queryToRegister(const QString& kind)
{
- BaseJob::Query _q;
+ QUrlQuery _q;
addParam<IfNotEmpty>(_q, QStringLiteral("kind"), kind);
return _q;
}
-static const auto RegisterJobName = QStringLiteral("RegisterJob");
-
-RegisterJob::RegisterJob(const QString& kind, const Omittable<AuthenticationData>& auth, bool bindEmail, const QString& username, const QString& password, const QString& deviceId, const QString& initialDeviceDisplayName, bool inhibitLogin)
- : BaseJob(HttpVerb::Post, RegisterJobName,
- basePath % "/register",
- queryToRegister(kind),
- {}, false)
- , d(new Private)
-{
- QJsonObject _data;
- addParam<IfNotEmpty>(_data, QStringLiteral("auth"), auth);
- addParam<IfNotEmpty>(_data, QStringLiteral("bind_email"), bindEmail);
- addParam<IfNotEmpty>(_data, QStringLiteral("username"), username);
- addParam<IfNotEmpty>(_data, QStringLiteral("password"), password);
- addParam<IfNotEmpty>(_data, QStringLiteral("device_id"), deviceId);
- addParam<IfNotEmpty>(_data, QStringLiteral("initial_device_display_name"), initialDeviceDisplayName);
- addParam<IfNotEmpty>(_data, QStringLiteral("inhibit_login"), inhibitLogin);
- setRequestData(_data);
-}
-
-RegisterJob::~RegisterJob() = default;
-
-const QString& RegisterJob::userId() const
-{
- return d->userId;
-}
-
-const QString& RegisterJob::accessToken() const
+RegisterJob::RegisterJob(const QString& kind,
+ const Omittable<AuthenticationData>& auth,
+ const QString& username, const QString& password,
+ const QString& deviceId,
+ const QString& initialDeviceDisplayName,
+ Omittable<bool> inhibitLogin,
+ Omittable<bool> refreshToken)
+ : BaseJob(HttpVerb::Post, QStringLiteral("RegisterJob"),
+ makePath("/_matrix/client/v3", "/register"),
+ queryToRegister(kind), {}, false)
{
- return d->accessToken;
+ QJsonObject _dataJson;
+ addParam<IfNotEmpty>(_dataJson, QStringLiteral("auth"), auth);
+ addParam<IfNotEmpty>(_dataJson, QStringLiteral("username"), username);
+ addParam<IfNotEmpty>(_dataJson, QStringLiteral("password"), password);
+ addParam<IfNotEmpty>(_dataJson, QStringLiteral("device_id"), deviceId);
+ addParam<IfNotEmpty>(_dataJson,
+ QStringLiteral("initial_device_display_name"),
+ initialDeviceDisplayName);
+ addParam<IfNotEmpty>(_dataJson, QStringLiteral("inhibit_login"),
+ inhibitLogin);
+ addParam<IfNotEmpty>(_dataJson, QStringLiteral("refresh_token"),
+ refreshToken);
+ setRequestData({ _dataJson });
+ addExpectedKey("user_id");
}
-const QString& RegisterJob::homeServer() const
+RequestTokenToRegisterEmailJob::RequestTokenToRegisterEmailJob(
+ const EmailValidationData& body)
+ : BaseJob(HttpVerb::Post, QStringLiteral("RequestTokenToRegisterEmailJob"),
+ makePath("/_matrix/client/v3", "/register/email/requestToken"),
+ false)
{
- return d->homeServer;
+ setRequestData({ toJson(body) });
}
-const QString& RegisterJob::deviceId() const
+RequestTokenToRegisterMSISDNJob::RequestTokenToRegisterMSISDNJob(
+ const MsisdnValidationData& body)
+ : BaseJob(HttpVerb::Post, QStringLiteral("RequestTokenToRegisterMSISDNJob"),
+ makePath("/_matrix/client/v3", "/register/msisdn/requestToken"),
+ false)
{
- return d->deviceId;
+ setRequestData({ toJson(body) });
}
-BaseJob::Status RegisterJob::parseJson(const QJsonDocument& data)
+ChangePasswordJob::ChangePasswordJob(const QString& newPassword,
+ bool logoutDevices,
+ const Omittable<AuthenticationData>& auth)
+ : BaseJob(HttpVerb::Post, QStringLiteral("ChangePasswordJob"),
+ makePath("/_matrix/client/v3", "/account/password"))
{
- auto json = data.object();
- if (!json.contains("user_id"_ls))
- return { JsonParseError,
- "The key 'user_id' not found in the response" };
- d->userId = fromJson<QString>(json.value("user_id"_ls));
- d->accessToken = fromJson<QString>(json.value("access_token"_ls));
- d->homeServer = fromJson<QString>(json.value("home_server"_ls));
- d->deviceId = fromJson<QString>(json.value("device_id"_ls));
- return Success;
+ QJsonObject _dataJson;
+ addParam<>(_dataJson, QStringLiteral("new_password"), newPassword);
+ addParam<IfNotEmpty>(_dataJson, QStringLiteral("logout_devices"),
+ logoutDevices);
+ addParam<IfNotEmpty>(_dataJson, QStringLiteral("auth"), auth);
+ setRequestData({ _dataJson });
}
-class RequestTokenToRegisterEmailJob::Private
-{
- public:
- Sid data;
-};
-
-static const auto RequestTokenToRegisterEmailJobName = QStringLiteral("RequestTokenToRegisterEmailJob");
-
-RequestTokenToRegisterEmailJob::RequestTokenToRegisterEmailJob(const QString& clientSecret, const QString& email, int sendAttempt, const QString& idServer, const QString& nextLink)
- : BaseJob(HttpVerb::Post, RequestTokenToRegisterEmailJobName,
- basePath % "/register/email/requestToken", false)
- , d(new Private)
+RequestTokenToResetPasswordEmailJob::RequestTokenToResetPasswordEmailJob(
+ const EmailValidationData& body)
+ : BaseJob(HttpVerb::Post,
+ QStringLiteral("RequestTokenToResetPasswordEmailJob"),
+ makePath("/_matrix/client/v3",
+ "/account/password/email/requestToken"),
+ false)
{
- QJsonObject _data;
- addParam<>(_data, QStringLiteral("client_secret"), clientSecret);
- addParam<>(_data, QStringLiteral("email"), email);
- addParam<>(_data, QStringLiteral("send_attempt"), sendAttempt);
- addParam<IfNotEmpty>(_data, QStringLiteral("next_link"), nextLink);
- addParam<>(_data, QStringLiteral("id_server"), idServer);
- setRequestData(_data);
+ setRequestData({ toJson(body) });
}
-RequestTokenToRegisterEmailJob::~RequestTokenToRegisterEmailJob() = default;
-
-const Sid& RequestTokenToRegisterEmailJob::data() const
+RequestTokenToResetPasswordMSISDNJob::RequestTokenToResetPasswordMSISDNJob(
+ const MsisdnValidationData& body)
+ : BaseJob(HttpVerb::Post,
+ QStringLiteral("RequestTokenToResetPasswordMSISDNJob"),
+ makePath("/_matrix/client/v3",
+ "/account/password/msisdn/requestToken"),
+ false)
{
- return d->data;
+ setRequestData({ toJson(body) });
}
-BaseJob::Status RequestTokenToRegisterEmailJob::parseJson(const QJsonDocument& data)
+DeactivateAccountJob::DeactivateAccountJob(
+ const Omittable<AuthenticationData>& auth, const QString& idServer)
+ : BaseJob(HttpVerb::Post, QStringLiteral("DeactivateAccountJob"),
+ makePath("/_matrix/client/v3", "/account/deactivate"))
{
- d->data = fromJson<Sid>(data);
- return Success;
+ QJsonObject _dataJson;
+ addParam<IfNotEmpty>(_dataJson, QStringLiteral("auth"), auth);
+ addParam<IfNotEmpty>(_dataJson, QStringLiteral("id_server"), idServer);
+ setRequestData({ _dataJson });
+ addExpectedKey("id_server_unbind_result");
}
-class RequestTokenToRegisterMSISDNJob::Private
-{
- public:
- Sid data;
-};
-
-static const auto RequestTokenToRegisterMSISDNJobName = QStringLiteral("RequestTokenToRegisterMSISDNJob");
-
-RequestTokenToRegisterMSISDNJob::RequestTokenToRegisterMSISDNJob(const QString& clientSecret, const QString& country, const QString& phoneNumber, int sendAttempt, const QString& idServer, const QString& nextLink)
- : BaseJob(HttpVerb::Post, RequestTokenToRegisterMSISDNJobName,
- basePath % "/register/msisdn/requestToken", false)
- , d(new Private)
+auto queryToCheckUsernameAvailability(const QString& username)
{
- QJsonObject _data;
- addParam<>(_data, QStringLiteral("client_secret"), clientSecret);
- addParam<>(_data, QStringLiteral("country"), country);
- addParam<>(_data, QStringLiteral("phone_number"), phoneNumber);
- addParam<>(_data, QStringLiteral("send_attempt"), sendAttempt);
- addParam<IfNotEmpty>(_data, QStringLiteral("next_link"), nextLink);
- addParam<>(_data, QStringLiteral("id_server"), idServer);
- setRequestData(_data);
-}
-
-RequestTokenToRegisterMSISDNJob::~RequestTokenToRegisterMSISDNJob() = default;
-
-const Sid& RequestTokenToRegisterMSISDNJob::data() const
-{
- return d->data;
-}
-
-BaseJob::Status RequestTokenToRegisterMSISDNJob::parseJson(const QJsonDocument& data)
-{
- d->data = fromJson<Sid>(data);
- return Success;
-}
-
-static const auto ChangePasswordJobName = QStringLiteral("ChangePasswordJob");
-
-ChangePasswordJob::ChangePasswordJob(const QString& newPassword, const Omittable<AuthenticationData>& auth)
- : BaseJob(HttpVerb::Post, ChangePasswordJobName,
- basePath % "/account/password")
-{
- QJsonObject _data;
- addParam<>(_data, QStringLiteral("new_password"), newPassword);
- addParam<IfNotEmpty>(_data, QStringLiteral("auth"), auth);
- setRequestData(_data);
-}
-
-class RequestTokenToResetPasswordEmailJob::Private
-{
- public:
- Sid data;
-};
-
-static const auto RequestTokenToResetPasswordEmailJobName = QStringLiteral("RequestTokenToResetPasswordEmailJob");
-
-RequestTokenToResetPasswordEmailJob::RequestTokenToResetPasswordEmailJob(const QString& clientSecret, const QString& email, int sendAttempt, const QString& idServer, const QString& nextLink)
- : BaseJob(HttpVerb::Post, RequestTokenToResetPasswordEmailJobName,
- basePath % "/account/password/email/requestToken", false)
- , d(new Private)
-{
- QJsonObject _data;
- addParam<>(_data, QStringLiteral("client_secret"), clientSecret);
- addParam<>(_data, QStringLiteral("email"), email);
- addParam<>(_data, QStringLiteral("send_attempt"), sendAttempt);
- addParam<IfNotEmpty>(_data, QStringLiteral("next_link"), nextLink);
- addParam<>(_data, QStringLiteral("id_server"), idServer);
- setRequestData(_data);
-}
-
-RequestTokenToResetPasswordEmailJob::~RequestTokenToResetPasswordEmailJob() = default;
-
-const Sid& RequestTokenToResetPasswordEmailJob::data() const
-{
- return d->data;
-}
-
-BaseJob::Status RequestTokenToResetPasswordEmailJob::parseJson(const QJsonDocument& data)
-{
- d->data = fromJson<Sid>(data);
- return Success;
-}
-
-class RequestTokenToResetPasswordMSISDNJob::Private
-{
- public:
- Sid data;
-};
-
-static const auto RequestTokenToResetPasswordMSISDNJobName = QStringLiteral("RequestTokenToResetPasswordMSISDNJob");
-
-RequestTokenToResetPasswordMSISDNJob::RequestTokenToResetPasswordMSISDNJob(const QString& clientSecret, const QString& country, const QString& phoneNumber, int sendAttempt, const QString& idServer, const QString& nextLink)
- : BaseJob(HttpVerb::Post, RequestTokenToResetPasswordMSISDNJobName,
- basePath % "/account/password/msisdn/requestToken", false)
- , d(new Private)
-{
- QJsonObject _data;
- addParam<>(_data, QStringLiteral("client_secret"), clientSecret);
- addParam<>(_data, QStringLiteral("country"), country);
- addParam<>(_data, QStringLiteral("phone_number"), phoneNumber);
- addParam<>(_data, QStringLiteral("send_attempt"), sendAttempt);
- addParam<IfNotEmpty>(_data, QStringLiteral("next_link"), nextLink);
- addParam<>(_data, QStringLiteral("id_server"), idServer);
- setRequestData(_data);
-}
-
-RequestTokenToResetPasswordMSISDNJob::~RequestTokenToResetPasswordMSISDNJob() = default;
-
-const Sid& RequestTokenToResetPasswordMSISDNJob::data() const
-{
- return d->data;
-}
-
-BaseJob::Status RequestTokenToResetPasswordMSISDNJob::parseJson(const QJsonDocument& data)
-{
- d->data = fromJson<Sid>(data);
- return Success;
-}
-
-static const auto DeactivateAccountJobName = QStringLiteral("DeactivateAccountJob");
-
-DeactivateAccountJob::DeactivateAccountJob(const Omittable<AuthenticationData>& auth)
- : BaseJob(HttpVerb::Post, DeactivateAccountJobName,
- basePath % "/account/deactivate")
-{
- QJsonObject _data;
- addParam<IfNotEmpty>(_data, QStringLiteral("auth"), auth);
- setRequestData(_data);
-}
-
-class CheckUsernameAvailabilityJob::Private
-{
- public:
- bool available;
-};
-
-BaseJob::Query queryToCheckUsernameAvailability(const QString& username)
-{
- BaseJob::Query _q;
+ QUrlQuery _q;
addParam<>(_q, QStringLiteral("username"), username);
return _q;
}
-QUrl CheckUsernameAvailabilityJob::makeRequestUrl(QUrl baseUrl, const QString& username)
+QUrl CheckUsernameAvailabilityJob::makeRequestUrl(QUrl baseUrl,
+ const QString& username)
{
return BaseJob::makeRequestUrl(std::move(baseUrl),
- basePath % "/register/available",
- queryToCheckUsernameAvailability(username));
-}
-
-static const auto CheckUsernameAvailabilityJobName = QStringLiteral("CheckUsernameAvailabilityJob");
-
-CheckUsernameAvailabilityJob::CheckUsernameAvailabilityJob(const QString& username)
- : BaseJob(HttpVerb::Get, CheckUsernameAvailabilityJobName,
- basePath % "/register/available",
- queryToCheckUsernameAvailability(username),
- {}, false)
- , d(new Private)
-{
-}
-
-CheckUsernameAvailabilityJob::~CheckUsernameAvailabilityJob() = default;
-
-bool CheckUsernameAvailabilityJob::available() const
-{
- return d->available;
-}
-
-BaseJob::Status CheckUsernameAvailabilityJob::parseJson(const QJsonDocument& data)
-{
- auto json = data.object();
- d->available = fromJson<bool>(json.value("available"_ls));
- return Success;
+ makePath("/_matrix/client/v3",
+ "/register/available"),
+ queryToCheckUsernameAvailability(username));
}
+CheckUsernameAvailabilityJob::CheckUsernameAvailabilityJob(
+ const QString& username)
+ : BaseJob(HttpVerb::Get, QStringLiteral("CheckUsernameAvailabilityJob"),
+ makePath("/_matrix/client/v3", "/register/available"),
+ queryToCheckUsernameAvailability(username), {}, false)
+{}