Implement deactivating accounts
This commit is contained in:
@@ -307,6 +307,14 @@ NeochatChangePasswordJob::NeochatChangePasswordJob(const QString &newPassword, b
|
||||
setRequestData(_data);
|
||||
}
|
||||
|
||||
NeoChatDeactivateAccountJob::NeoChatDeactivateAccountJob(const Quotient::Omittable<QJsonObject> &auth)
|
||||
: BaseJob(HttpVerb::Post, QStringLiteral("DisableDeviceJob"), "_matrix/client/v3/account/deactivate")
|
||||
{
|
||||
QJsonObject data;
|
||||
addParam<IfNotEmpty>(data, QStringLiteral("auth"), auth);
|
||||
setRequestData(data);
|
||||
}
|
||||
|
||||
int Controller::accountCount() const
|
||||
{
|
||||
return m_accountRegistry.count();
|
||||
|
||||
@@ -249,3 +249,9 @@ class NeochatDeleteDeviceJob : public Quotient::BaseJob
|
||||
public:
|
||||
explicit NeochatDeleteDeviceJob(const QString &deviceId, const Quotient::Omittable<QJsonObject> &auth = Quotient::none);
|
||||
};
|
||||
|
||||
class NeoChatDeactivateAccountJob : public Quotient::BaseJob
|
||||
{
|
||||
public:
|
||||
explicit NeoChatDeactivateAccountJob(const Quotient::Omittable<QJsonObject> &auth = Quotient::none);
|
||||
};
|
||||
|
||||
@@ -132,3 +132,24 @@ QString NeoChatConnection::label() const
|
||||
{
|
||||
return accountDataJson("org.kde.neochat.account_label"_ls)["account_label"_ls].toString();
|
||||
}
|
||||
|
||||
void NeoChatConnection::deactivateAccount(const QString &password)
|
||||
{
|
||||
auto job = callApi<NeoChatDeactivateAccountJob>();
|
||||
connect(job, &BaseJob::result, this, [this, job, password] {
|
||||
if (job->error() == 103) {
|
||||
QJsonObject replyData = job->jsonData();
|
||||
QJsonObject authData;
|
||||
authData["session"_ls] = replyData["session"_ls];
|
||||
authData["password"_ls] = password;
|
||||
authData["type"_ls] = "m.login.password"_ls;
|
||||
authData["user"_ls] = user()->id();
|
||||
QJsonObject identifier = {{"type"_ls, "m.id.user"_ls}, {"user"_ls, user()->id()}};
|
||||
authData["identifier"_ls] = identifier;
|
||||
auto innerJob = callApi<NeoChatDeactivateAccountJob>(authData);
|
||||
connect(innerJob, &BaseJob::success, this, [this]() {
|
||||
logout(false);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -46,6 +46,8 @@ public:
|
||||
[[nodiscard]] QString label() const;
|
||||
void setLabel(const QString &label);
|
||||
|
||||
Q_INVOKABLE void deactivateAccount(const QString &password);
|
||||
|
||||
Q_SIGNALS:
|
||||
void labelChanged();
|
||||
};
|
||||
|
||||
46
src/qml/Dialog/ConfirmDeactivateAccountDialog.qml
Normal file
46
src/qml/Dialog/ConfirmDeactivateAccountDialog.qml
Normal file
@@ -0,0 +1,46 @@
|
||||
// SPDX-FileCopyrightText: 2023 Tobias Fella <tobias.fella@kde.org>
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
import QtQuick 2.15
|
||||
import QtQuick.Controls 2.15 as QQC2
|
||||
|
||||
import QtQuick.Layouts 1.15
|
||||
|
||||
import org.kde.kirigami 2.20 as Kirigami
|
||||
import org.kde.kirigamiaddons.formcard 1.0 as FormCard
|
||||
|
||||
import org.kde.neochat 1.0
|
||||
|
||||
FormCard.FormCardPage {
|
||||
id: root
|
||||
|
||||
property var connection
|
||||
|
||||
title: i18nc("@title", "Deactivate Account")
|
||||
|
||||
FormCard.FormHeader {
|
||||
title: i18nc("@title", "Deactivate Account")
|
||||
}
|
||||
FormCard.FormCard {
|
||||
FormCard.FormTextDelegate {
|
||||
text: i18nc("@title", "Warning")
|
||||
description: i18n("Your account will be permanently disabled.\nThis cannot be undone.\nYour Matrix ID will not be available for new accounts.\nYour messages will stay available.")
|
||||
}
|
||||
|
||||
FormCard.FormTextFieldDelegate {
|
||||
id: passwordField
|
||||
label: i18n("Password")
|
||||
echoMode: TextInput.Password
|
||||
}
|
||||
|
||||
FormCard.FormButtonDelegate {
|
||||
text: i18n("Deactivate account")
|
||||
icon.name: "emblem-warning"
|
||||
enabled: passwordField.text.length > 0
|
||||
onClicked: {
|
||||
root.connection.deactivateAccount(passwordField.text)
|
||||
root.closeDialog()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -249,6 +249,21 @@ Kirigami.ScrollablePage {
|
||||
}*/
|
||||
}
|
||||
}
|
||||
MobileForm.FormHeader {
|
||||
Layout.fillWidth: true
|
||||
title: i18nc("@title", "Account Management")
|
||||
}
|
||||
MobileForm.FormCard {
|
||||
Layout.fillWidth: true
|
||||
contentItem: ColumnLayout {
|
||||
spacing: 0
|
||||
MobileForm.FormButtonDelegate {
|
||||
id: deactivateAccountButton
|
||||
text: i18n("Deactivate Account")
|
||||
onClicked: pageStack.pushDialogLayer("qrc:/ConfirmDeactivateAccountDialog.qml", {connection: root.connection}, {title: i18nc("@title", "Confirm Deactivating Account")})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Component {
|
||||
id: openFileDialog
|
||||
|
||||
@@ -88,6 +88,7 @@
|
||||
<file alias="EmojiItem.qml">qml/Dialog/KeyVerification/EmojiItem.qml</file>
|
||||
<file alias="EmojiRow.qml">qml/Dialog/KeyVerification/EmojiRow.qml</file>
|
||||
<file alias="EmojiSas.qml">qml/Dialog/KeyVerification/EmojiSas.qml</file>
|
||||
<file alias="ConfirmDeactivateAccountDialog.qml">qml/Dialog/ConfirmDeactivateAccountDialog.qml</file>
|
||||
<file alias="VerificationCanceled.qml">qml/Dialog/KeyVerification/VerificationCanceled.qml</file>
|
||||
<file alias="GlobalMenu.qml">qml/Menu/GlobalMenu.qml</file>
|
||||
<file alias="EditMenu.qml">qml/Menu/EditMenu.qml</file>
|
||||
|
||||
Reference in New Issue
Block a user