File indexing completed on 2024-12-22 04:45:27
0001 /* 0002 SPDX-FileCopyrightText: 2020-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "deleteownaccountjob.h" 0008 #include "restapimethod.h" 0009 #include "rocketchatqtrestapi_debug.h" 0010 0011 #include <QJsonDocument> 0012 #include <QJsonObject> 0013 #include <QNetworkReply> 0014 using namespace RocketChatRestApi; 0015 DeleteOwnAccountJob::DeleteOwnAccountJob(QObject *parent) 0016 : RestApiAbstractJob(parent) 0017 { 0018 } 0019 0020 DeleteOwnAccountJob::~DeleteOwnAccountJob() = default; 0021 0022 bool DeleteOwnAccountJob::start() 0023 { 0024 if (!canStart()) { 0025 deleteLater(); 0026 return false; 0027 } 0028 addStartRestApiInfo("DeleteOwnAccountJob::start"); 0029 submitPostRequest(json()); 0030 return true; 0031 } 0032 0033 void DeleteOwnAccountJob::onPostRequestResponse(const QString &replyErrorString, const QJsonDocument &replyJson) 0034 { 0035 const QJsonObject replyObject = replyJson.object(); 0036 if (replyObject[QLatin1String("success")].toBool()) { 0037 addLoggerInfo(QByteArrayLiteral("DeleteOwnAccountJob: success: ") + replyJson.toJson(QJsonDocument::Indented)); 0038 Q_EMIT deleteOwnAccountDone(); 0039 } else { 0040 emitFailedMessage(replyErrorString, replyObject); 0041 addLoggerWarning(QByteArrayLiteral("DeleteOwnAccountJob: Problem: ") + replyJson.toJson(QJsonDocument::Indented)); 0042 } 0043 } 0044 0045 QString DeleteOwnAccountJob::password() const 0046 { 0047 return mPassword; 0048 } 0049 0050 void DeleteOwnAccountJob::setPassword(const QString &password) 0051 { 0052 mPassword = password; 0053 } 0054 0055 bool DeleteOwnAccountJob::requireHttpAuthentication() const 0056 { 0057 return true; 0058 } 0059 0060 bool DeleteOwnAccountJob::canStart() const 0061 { 0062 if (!RestApiAbstractJob::canStart()) { 0063 return false; 0064 } 0065 if (mPassword.isEmpty()) { 0066 qCWarning(ROCKETCHATQTRESTAPI_LOG) << "DeleteOwnAccountJob: mPassword is empty"; 0067 return false; 0068 } 0069 return true; 0070 } 0071 0072 QNetworkRequest DeleteOwnAccountJob::request() const 0073 { 0074 const QUrl url = mRestApiMethod->generateUrl(RestApiUtil::RestApiUrlType::UsersDeleteOwnAccount); 0075 QNetworkRequest request(url); 0076 addAuthRawHeader(request); 0077 addRequestAttribute(request); 0078 return request; 0079 } 0080 0081 QJsonDocument DeleteOwnAccountJob::json() const 0082 { 0083 QJsonObject jsonObj; 0084 const QByteArray sha256pw = RestApiUtil::convertSha256Password(mPassword); 0085 jsonObj[QLatin1String("password")] = QString::fromLatin1(sha256pw); 0086 0087 const QJsonDocument postData = QJsonDocument(jsonObj); 0088 return postData; 0089 } 0090 0091 #include "moc_deleteownaccountjob.cpp"