diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-07-02 17:58:34 +0900 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-07-04 20:13:43 +0900 |
commit | 3dd6b5e6cc50aafce74b21b5a0bf4b26a9fcf6ee (patch) | |
tree | a647fa5328e04b20a84e46d29d420555d9c56cde /lib/csapi/registration.cpp | |
parent | ed467d27b07781fdd2f7ddef043568954ce50b69 (diff) | |
download | libquotient-3dd6b5e6cc50aafce74b21b5a0bf4b26a9fcf6ee.tar.gz libquotient-3dd6b5e6cc50aafce74b21b5a0bf4b26a9fcf6ee.zip |
Use QStringLiteral() and operator"" _ls() in network jobs
Diffstat (limited to 'lib/csapi/registration.cpp')
-rw-r--r-- | lib/csapi/registration.cpp | 64 |
1 files changed, 38 insertions, 26 deletions
diff --git a/lib/csapi/registration.cpp b/lib/csapi/registration.cpp index 4345635a..4991829c 100644 --- a/lib/csapi/registration.cpp +++ b/lib/csapi/registration.cpp @@ -24,24 +24,26 @@ class RegisterJob::Private BaseJob::Query queryToRegister(const QString& kind) { BaseJob::Query _q; - addParam<IfNotEmpty>(_q, "kind", kind); + addParam<IfNotEmpty>(_q, QStringLiteral("kind"), kind); return _q; } +static const auto RegisterJobName = QStringLiteral("RegisterJob"); + 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", + : BaseJob(HttpVerb::Post, RegisterJobName, basePath % "/register", queryToRegister(kind), {}, false) , d(new Private) { QJsonObject _data; - addParam<IfNotEmpty>(_data, "auth", auth); - addParam<IfNotEmpty>(_data, "bind_email", bindEmail); - addParam<IfNotEmpty>(_data, "username", username); - addParam<IfNotEmpty>(_data, "password", password); - addParam<IfNotEmpty>(_data, "device_id", deviceId); - addParam<IfNotEmpty>(_data, "initial_device_display_name", initialDeviceDisplayName); + 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); setRequestData(_data); } @@ -70,32 +72,36 @@ const QString& RegisterJob::deviceId() const 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")); + 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; } +static const auto RequestTokenToRegisterJobName = QStringLiteral("RequestTokenToRegisterJob"); + RequestTokenToRegisterJob::RequestTokenToRegisterJob(const QString& clientSecret, const QString& email, int sendAttempt, const QString& idServer) - : BaseJob(HttpVerb::Post, "RequestTokenToRegisterJob", + : BaseJob(HttpVerb::Post, RequestTokenToRegisterJobName, basePath % "/register/email/requestToken", false) { QJsonObject _data; - addParam<IfNotEmpty>(_data, "id_server", idServer); - addParam<>(_data, "client_secret", clientSecret); - addParam<>(_data, "email", email); - addParam<>(_data, "send_attempt", sendAttempt); + addParam<IfNotEmpty>(_data, QStringLiteral("id_server"), idServer); + addParam<>(_data, QStringLiteral("client_secret"), clientSecret); + addParam<>(_data, QStringLiteral("email"), email); + addParam<>(_data, QStringLiteral("send_attempt"), sendAttempt); setRequestData(_data); } +static const auto ChangePasswordJobName = QStringLiteral("ChangePasswordJob"); + ChangePasswordJob::ChangePasswordJob(const QString& newPassword, const QJsonObject& auth) - : BaseJob(HttpVerb::Post, "ChangePasswordJob", + : BaseJob(HttpVerb::Post, ChangePasswordJobName, basePath % "/account/password") { QJsonObject _data; - addParam<>(_data, "new_password", newPassword); - addParam<IfNotEmpty>(_data, "auth", auth); + addParam<>(_data, QStringLiteral("new_password"), newPassword); + addParam<IfNotEmpty>(_data, QStringLiteral("auth"), auth); setRequestData(_data); } @@ -105,18 +111,22 @@ QUrl RequestTokenToResetPasswordJob::makeRequestUrl(QUrl baseUrl) basePath % "/account/password/email/requestToken"); } +static const auto RequestTokenToResetPasswordJobName = QStringLiteral("RequestTokenToResetPasswordJob"); + RequestTokenToResetPasswordJob::RequestTokenToResetPasswordJob() - : BaseJob(HttpVerb::Post, "RequestTokenToResetPasswordJob", + : BaseJob(HttpVerb::Post, RequestTokenToResetPasswordJobName, basePath % "/account/password/email/requestToken", false) { } +static const auto DeactivateAccountJobName = QStringLiteral("DeactivateAccountJob"); + DeactivateAccountJob::DeactivateAccountJob(const QJsonObject& auth) - : BaseJob(HttpVerb::Post, "DeactivateAccountJob", + : BaseJob(HttpVerb::Post, DeactivateAccountJobName, basePath % "/account/deactivate") { QJsonObject _data; - addParam<IfNotEmpty>(_data, "auth", auth); + addParam<IfNotEmpty>(_data, QStringLiteral("auth"), auth); setRequestData(_data); } @@ -129,7 +139,7 @@ class CheckUsernameAvailabilityJob::Private BaseJob::Query queryToCheckUsernameAvailability(const QString& username) { BaseJob::Query _q; - addParam<>(_q, "username", username); + addParam<>(_q, QStringLiteral("username"), username); return _q; } @@ -140,8 +150,10 @@ QUrl CheckUsernameAvailabilityJob::makeRequestUrl(QUrl baseUrl, const QString& u queryToCheckUsernameAvailability(username)); } +static const auto CheckUsernameAvailabilityJobName = QStringLiteral("CheckUsernameAvailabilityJob"); + CheckUsernameAvailabilityJob::CheckUsernameAvailabilityJob(const QString& username) - : BaseJob(HttpVerb::Get, "CheckUsernameAvailabilityJob", + : BaseJob(HttpVerb::Get, CheckUsernameAvailabilityJobName, basePath % "/register/available", queryToCheckUsernameAvailability(username), {}, false) @@ -159,7 +171,7 @@ bool CheckUsernameAvailabilityJob::available() const BaseJob::Status CheckUsernameAvailabilityJob::parseJson(const QJsonDocument& data) { auto json = data.object(); - d->available = fromJson<bool>(json.value("available")); + d->available = fromJson<bool>(json.value("available"_ls)); return Success; } |