aboutsummaryrefslogtreecommitdiff
path: root/lib/csapi
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2018-06-08 16:59:55 +0900
committerKitsune Ral <Kitsune-Ral@users.sf.net>2018-06-08 16:59:55 +0900
commit318e094e19bc8ecfe89031e4c62a8cd14d307157 (patch)
treec8d03662e9c6e68683141769e39f8816a6dea2c3 /lib/csapi
parent907865f71aed9c51565bb3ed229e791757874a61 (diff)
downloadlibquotient-318e094e19bc8ecfe89031e4c62a8cd14d307157.tar.gz
libquotient-318e094e19bc8ecfe89031e4c62a8cd14d307157.zip
csapi: Added registration and account management jobs
Regrettably had to cut corners and use QJsonObject for auth_data.yaml because GTAD 0.6 doesn't properly deal with a combination of properties and additionalProperties in the API description.
Diffstat (limited to 'lib/csapi')
-rw-r--r--lib/csapi/gtad.yaml1
-rw-r--r--lib/csapi/registration.cpp166
-rw-r--r--lib/csapi/registration.h94
3 files changed, 261 insertions, 0 deletions
diff --git a/lib/csapi/gtad.yaml b/lib/csapi/gtad.yaml
index b98d27c9..76418f3c 100644
--- a/lib/csapi/gtad.yaml
+++ b/lib/csapi/gtad.yaml
@@ -67,6 +67,7 @@ analyzer:
{ type: RoomEventPtr, imports: '"events/event.h"' }
- /event.yaml$/:
{ type: EventPtr, imports: '"events/event.h"' }
+ - /auth_data.yaml$/: *QJsonObject # GTAD 0.6 cannot cope with this one
- /m\.room\.member$/: pass # This $ref is only used in an array, see below
- //: *UseOmittable # Also apply "avoidCopy" to all other ref'ed types
- schema: # Properties of inline structure definitions
diff --git a/lib/csapi/registration.cpp b/lib/csapi/registration.cpp
new file mode 100644
index 00000000..1e239d2a
--- /dev/null
+++ b/lib/csapi/registration.cpp
@@ -0,0 +1,166 @@
+/******************************************************************************
+ * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN
+ */
+
+#include "registration.h"
+
+#include "converters.h"
+
+#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)
+{
+ BaseJob::Query _q;
+ if (!kind.isEmpty())
+ _q.addQueryItem("kind", kind);
+ return _q;
+}
+
+RegisterJob::RegisterJob(const QString& kind, const QJsonObject& auth, bool bindEmail, const QString& username, const QString& password, const QString& deviceId, const QString& initialDeviceDisplayName)
+ : BaseJob(HttpVerb::Post, "RegisterJob",
+ basePath % "/register",
+ queryToRegister(kind),
+ {}, false)
+ , d(new Private)
+{
+ QJsonObject _data;
+ addToJson<IfNotEmpty>(_data, "auth", auth);
+ addToJson<IfNotEmpty>(_data, "bind_email", bindEmail);
+ addToJson<IfNotEmpty>(_data, "username", username);
+ addToJson<IfNotEmpty>(_data, "password", password);
+ addToJson<IfNotEmpty>(_data, "device_id", deviceId);
+ addToJson<IfNotEmpty>(_data, "initial_device_display_name", initialDeviceDisplayName);
+ setRequestData(_data);
+}
+
+RegisterJob::~RegisterJob() = default;
+
+const QString& RegisterJob::userId() const
+{
+ return d->userId;
+}
+
+const QString& RegisterJob::accessToken() const
+{
+ return d->accessToken;
+}
+
+const QString& RegisterJob::homeServer() const
+{
+ return d->homeServer;
+}
+
+const QString& RegisterJob::deviceId() const
+{
+ return d->deviceId;
+}
+
+BaseJob::Status RegisterJob::parseJson(const QJsonDocument& data)
+{
+ auto json = data.object();
+ d->userId = fromJson<QString>(json.value("user_id"));
+ d->accessToken = fromJson<QString>(json.value("access_token"));
+ d->homeServer = fromJson<QString>(json.value("home_server"));
+ d->deviceId = fromJson<QString>(json.value("device_id"));
+ return Success;
+}
+
+RequestTokenToRegisterJob::RequestTokenToRegisterJob(const QString& clientSecret, const QString& email, int sendAttempt, const QString& idServer)
+ : BaseJob(HttpVerb::Post, "RequestTokenToRegisterJob",
+ basePath % "/register/email/requestToken", false)
+{
+ QJsonObject _data;
+ addToJson<IfNotEmpty>(_data, "id_server", idServer);
+ addToJson<>(_data, "client_secret", clientSecret);
+ addToJson<>(_data, "email", email);
+ addToJson<>(_data, "send_attempt", sendAttempt);
+ setRequestData(_data);
+}
+
+ChangePasswordJob::ChangePasswordJob(const QString& newPassword, const QJsonObject& auth)
+ : BaseJob(HttpVerb::Post, "ChangePasswordJob",
+ basePath % "/account/password")
+{
+ QJsonObject _data;
+ addToJson<>(_data, "new_password", newPassword);
+ addToJson<IfNotEmpty>(_data, "auth", auth);
+ setRequestData(_data);
+}
+
+QUrl RequestTokenToResetPasswordJob::makeRequestUrl(QUrl baseUrl)
+{
+ return BaseJob::makeRequestUrl(std::move(baseUrl),
+ basePath % "/account/password/email/requestToken");
+}
+
+RequestTokenToResetPasswordJob::RequestTokenToResetPasswordJob()
+ : BaseJob(HttpVerb::Post, "RequestTokenToResetPasswordJob",
+ basePath % "/account/password/email/requestToken", false)
+{
+}
+
+DeactivateAccountJob::DeactivateAccountJob(const QJsonObject& auth)
+ : BaseJob(HttpVerb::Post, "DeactivateAccountJob",
+ basePath % "/account/deactivate")
+{
+ QJsonObject _data;
+ addToJson<IfNotEmpty>(_data, "auth", auth);
+ setRequestData(_data);
+}
+
+class CheckUsernameAvailabilityJob::Private
+{
+ public:
+ bool available;
+};
+
+BaseJob::Query queryToCheckUsernameAvailability(const QString& username)
+{
+ BaseJob::Query _q;
+ _q.addQueryItem("username", username);
+ return _q;
+}
+
+QUrl CheckUsernameAvailabilityJob::makeRequestUrl(QUrl baseUrl, const QString& username)
+{
+ return BaseJob::makeRequestUrl(std::move(baseUrl),
+ basePath % "/register/available",
+ queryToCheckUsernameAvailability(username));
+}
+
+CheckUsernameAvailabilityJob::CheckUsernameAvailabilityJob(const QString& username)
+ : BaseJob(HttpVerb::Get, "CheckUsernameAvailabilityJob",
+ 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"));
+ return Success;
+}
+
diff --git a/lib/csapi/registration.h b/lib/csapi/registration.h
new file mode 100644
index 00000000..a4974177
--- /dev/null
+++ b/lib/csapi/registration.h
@@ -0,0 +1,94 @@
+/******************************************************************************
+ * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN
+ */
+
+#pragma once
+
+#include "jobs/basejob.h"
+
+#include "converters.h"
+#include <QtCore/QJsonObject>
+
+namespace QMatrixClient
+{
+ // Operations
+
+ class RegisterJob : public BaseJob
+ {
+ public:
+ explicit RegisterJob(const QString& kind = QStringLiteral("user"), const QJsonObject& auth = {}, bool bindEmail = false, const QString& username = {}, const QString& password = {}, const QString& deviceId = {}, const QString& initialDeviceDisplayName = {});
+ ~RegisterJob() override;
+
+ // Result properties
+
+ const QString& userId() const;
+ const QString& accessToken() const;
+ const QString& homeServer() const;
+ const QString& deviceId() const;
+
+ protected:
+ Status parseJson(const QJsonDocument& data) override;
+
+ private:
+ class Private;
+ QScopedPointer<Private> d;
+ };
+
+ class RequestTokenToRegisterJob : public BaseJob
+ {
+ public:
+ explicit RequestTokenToRegisterJob(const QString& clientSecret, const QString& email, int sendAttempt, const QString& idServer = {});
+ };
+
+ class ChangePasswordJob : public BaseJob
+ {
+ public:
+ explicit ChangePasswordJob(const QString& newPassword, const QJsonObject& auth = {});
+ };
+
+ class RequestTokenToResetPasswordJob : public BaseJob
+ {
+ public:
+ explicit RequestTokenToResetPasswordJob();
+
+ /** Construct a URL out of baseUrl and usual parameters passed to
+ * RequestTokenToResetPasswordJob. This function can be used when
+ * a URL for RequestTokenToResetPasswordJob is necessary but the job
+ * itself isn't.
+ */
+ static QUrl makeRequestUrl(QUrl baseUrl);
+
+ };
+
+ class DeactivateAccountJob : public BaseJob
+ {
+ public:
+ explicit DeactivateAccountJob(const QJsonObject& auth = {});
+ };
+
+ class CheckUsernameAvailabilityJob : public BaseJob
+ {
+ public:
+ explicit CheckUsernameAvailabilityJob(const QString& username);
+
+ /** Construct a URL out of baseUrl and usual parameters passed to
+ * CheckUsernameAvailabilityJob. This function can be used when
+ * a URL for CheckUsernameAvailabilityJob is necessary but the job
+ * itself isn't.
+ */
+ static QUrl makeRequestUrl(QUrl baseUrl, const QString& username);
+
+ ~CheckUsernameAvailabilityJob() override;
+
+ // Result properties
+
+ bool available() const;
+
+ protected:
+ Status parseJson(const QJsonDocument& data) override;
+
+ private:
+ class Private;
+ QScopedPointer<Private> d;
+ };
+} // namespace QMatrixClient