Move PasswordStatus out of Controller
This commit is contained in:
@@ -65,16 +65,6 @@ class Controller : public QObject
|
|||||||
Q_PROPERTY(QStringList accountsLoading MEMBER m_accountsLoading NOTIFY accountsLoadingChanged)
|
Q_PROPERTY(QStringList accountsLoading MEMBER m_accountsLoading NOTIFY accountsLoadingChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
|
||||||
* @brief Defines the status after an attempt to change the password on an account.
|
|
||||||
*/
|
|
||||||
enum PasswordStatus {
|
|
||||||
Success, /**< The password was successfully changed. */
|
|
||||||
Wrong, /**< The current password entered was wrong. */
|
|
||||||
Other, /**< An unknown problem occurred. */
|
|
||||||
};
|
|
||||||
Q_ENUM(PasswordStatus)
|
|
||||||
|
|
||||||
static Controller &instance();
|
static Controller &instance();
|
||||||
static Controller *create(QQmlEngine *engine, QJSEngine *)
|
static Controller *create(QQmlEngine *engine, QJSEngine *)
|
||||||
{
|
{
|
||||||
@@ -162,7 +152,6 @@ Q_SIGNALS:
|
|||||||
void quitOnLastWindowClosedChanged();
|
void quitOnLastWindowClosedChanged();
|
||||||
void unreadCountChanged();
|
void unreadCountChanged();
|
||||||
void activeConnectionChanged();
|
void activeConnectionChanged();
|
||||||
void passwordStatus(Controller::PasswordStatus status);
|
|
||||||
void userConsentRequired(QUrl url);
|
void userConsentRequired(QUrl url);
|
||||||
void accountsLoadingChanged();
|
void accountsLoadingChanged();
|
||||||
|
|
||||||
|
|||||||
@@ -124,12 +124,11 @@ void NeoChatConnection::changePassword(const QString ¤tPassword, const QSt
|
|||||||
QJsonObject identifier = {{"type"_ls, "m.id.user"_ls}, {"user"_ls, user()->id()}};
|
QJsonObject identifier = {{"type"_ls, "m.id.user"_ls}, {"user"_ls, user()->id()}};
|
||||||
authData["identifier"_ls] = identifier;
|
authData["identifier"_ls] = identifier;
|
||||||
NeochatChangePasswordJob *innerJob = callApi<NeochatChangePasswordJob>(newPassword, false, authData);
|
NeochatChangePasswordJob *innerJob = callApi<NeochatChangePasswordJob>(newPassword, false, authData);
|
||||||
connect(innerJob, &BaseJob::success, this, []() {
|
connect(innerJob, &BaseJob::success, this, [this]() {
|
||||||
Q_EMIT Controller::instance().passwordStatus(Controller::PasswordStatus::Success);
|
Q_EMIT passwordStatus(PasswordStatus::Success);
|
||||||
});
|
});
|
||||||
connect(innerJob, &BaseJob::failure, this, [innerJob]() {
|
connect(innerJob, &BaseJob::failure, this, [innerJob, this]() {
|
||||||
Q_EMIT Controller::instance().passwordStatus(innerJob->jsonData()["errcode"_ls] == "M_FORBIDDEN"_ls ? Controller::PasswordStatus::Wrong
|
Q_EMIT passwordStatus(innerJob->jsonData()["errcode"_ls] == "M_FORBIDDEN"_ls ? PasswordStatus::Wrong : PasswordStatus::Other);
|
||||||
: Controller::PasswordStatus::Other);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -33,6 +33,16 @@ class NeoChatConnection : public Quotient::Connection
|
|||||||
Q_PROPERTY(bool isOnline READ isOnline WRITE setIsOnline NOTIFY isOnlineChanged)
|
Q_PROPERTY(bool isOnline READ isOnline WRITE setIsOnline NOTIFY isOnlineChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Defines the status after an attempt to change the password on an account.
|
||||||
|
*/
|
||||||
|
enum PasswordStatus {
|
||||||
|
Success, /**< The password was successfully changed. */
|
||||||
|
Wrong, /**< The current password entered was wrong. */
|
||||||
|
Other, /**< An unknown problem occurred. */
|
||||||
|
};
|
||||||
|
Q_ENUM(PasswordStatus)
|
||||||
|
|
||||||
NeoChatConnection(QObject *parent = nullptr);
|
NeoChatConnection(QObject *parent = nullptr);
|
||||||
NeoChatConnection(const QUrl &server, QObject *parent = nullptr);
|
NeoChatConnection(const QUrl &server, QObject *parent = nullptr);
|
||||||
|
|
||||||
@@ -88,6 +98,7 @@ public:
|
|||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void labelChanged();
|
void labelChanged();
|
||||||
void isOnlineChanged();
|
void isOnlineChanged();
|
||||||
|
void passwordStatus(NeoChatConnection::PasswordStatus status);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_isOnline = true;
|
bool m_isOnline = true;
|
||||||
|
|||||||
@@ -215,4 +215,17 @@ FormCard.FormCardPage {
|
|||||||
onClicked: pageStack.pushDialogLayer("qrc:/org/kde/neochat/qml/ConfirmDeactivateAccountDialog.qml", {connection: root.connection}, {title: i18nc("@title", "Confirm Deactivating Account")})
|
onClicked: pageStack.pushDialogLayer("qrc:/org/kde/neochat/qml/ConfirmDeactivateAccountDialog.qml", {connection: root.connection}, {title: i18nc("@title", "Confirm Deactivating Account")})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data: Connections {
|
||||||
|
target: root.connection
|
||||||
|
function onPasswordStatus(status) {
|
||||||
|
if (status === NeoChatConnection.Success) {
|
||||||
|
showPassiveNotification(i18n("Password changed successfully"));
|
||||||
|
} else if (status === NeoChatConnection.Wrong) {
|
||||||
|
showPassiveNotification(i18n("Wrong password entered"));
|
||||||
|
} else {
|
||||||
|
showPassiveNotification(i18n("Unknown problem while trying to change password"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -110,14 +110,5 @@ FormCard.FormCardPage {
|
|||||||
pageStack.layers.pop()
|
pageStack.layers.pop()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function onPasswordStatus(status) {
|
|
||||||
if (status === Controller.Success) {
|
|
||||||
showPassiveNotification(i18n("Password changed successfully"));
|
|
||||||
} else if (status === Controller.Wrong) {
|
|
||||||
showPassiveNotification(i18n("Wrong password entered"));
|
|
||||||
} else {
|
|
||||||
showPassiveNotification(i18n("Unknown problem while trying to change password"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user