Unverified Commit 3d180d00 authored by Melvin Keskin's avatar Melvin Keskin Committed by Linus Jahn

Refactor password changing

* Move showing passive notifications out of RegistrationManager
* RegistrationManager: Move signal calls
parent f760263d
Pipeline #35236 passed with stage
in 5 minutes and 17 seconds
...@@ -419,9 +419,11 @@ signals: ...@@ -419,9 +419,11 @@ signals:
void passwordChangeSucceeded(); void passwordChangeSucceeded();
/** /**
* Emitted, when changing the password has failed. * Emitted when changing the user's password failed.
*
* @param errorMessage message describing the error
*/ */
void passwordChangeFailed(); void passwordChangeFailed(const QString &errorMessage);
/** /**
* Emitted, when a contact was muted/unmuted. * Emitted, when a contact was muted/unmuted.
......
...@@ -69,12 +69,7 @@ RegistrationManager::RegistrationManager(ClientWorker *clientWorker, QXmppClient ...@@ -69,12 +69,7 @@ RegistrationManager::RegistrationManager(ClientWorker *clientWorker, QXmppClient
connect(m_manager, &QXmppRegistrationManager::accountDeletionFailed, m_clientWorker, &ClientWorker::handleAccountDeletionFromServerFailed); connect(m_manager, &QXmppRegistrationManager::accountDeletionFailed, m_clientWorker, &ClientWorker::handleAccountDeletionFromServerFailed);
connect(m_manager, &QXmppRegistrationManager::accountDeleted, m_clientWorker, &ClientWorker::handleAccountDeletedFromServer); connect(m_manager, &QXmppRegistrationManager::accountDeleted, m_clientWorker, &ClientWorker::handleAccountDeletedFromServer);
connect(m_manager, &QXmppRegistrationManager::passwordChanged, Kaidan::instance(), &Kaidan::setPassword);
connect(m_manager, &QXmppRegistrationManager::passwordChanged, Kaidan::instance(), &Kaidan::passwordChangeSucceeded);
connect(m_manager, &QXmppRegistrationManager::passwordChanged, this, &RegistrationManager::handlePasswordChangeSucceeded); connect(m_manager, &QXmppRegistrationManager::passwordChanged, this, &RegistrationManager::handlePasswordChangeSucceeded);
connect(m_manager, &QXmppRegistrationManager::passwordChangeFailed, Kaidan::instance(), &Kaidan::passwordChangeFailed);
connect(m_manager, &QXmppRegistrationManager::passwordChangeFailed, this, &RegistrationManager::handlePasswordChangeFailed); connect(m_manager, &QXmppRegistrationManager::passwordChangeFailed, this, &RegistrationManager::handlePasswordChangeFailed);
} }
...@@ -123,16 +118,13 @@ void RegistrationManager::handlePasswordChangeSucceeded(const QString &newPasswo ...@@ -123,16 +118,13 @@ void RegistrationManager::handlePasswordChangeSucceeded(const QString &newPasswo
QString::fromUtf8(newPassword.toUtf8().toBase64()) QString::fromUtf8(newPassword.toUtf8().toBase64())
); );
emit Kaidan::instance()->passiveNotificationRequested( QMetaObject::invokeMethod(Kaidan::instance(), "setPassword", Q_ARG(QString, newPassword));
tr("Password changed successfully.") emit Kaidan::instance()->passwordChangeSucceeded();
);
} }
void RegistrationManager::handlePasswordChangeFailed(const QXmppStanza::Error &error) void RegistrationManager::handlePasswordChangeFailed(const QXmppStanza::Error &error)
{ {
emit Kaidan::instance()->passiveNotificationRequested( emit Kaidan::instance()->passwordChangeFailed(error.text());
tr("Failed to change password: %1").arg(error.text())
);
} }
void RegistrationManager::handleRegistrationFormReceived(const QXmppRegisterIq &iq) void RegistrationManager::handleRegistrationFormReceived(const QXmppRegisterIq &iq)
......
...@@ -50,6 +50,7 @@ Kirigami.Page { ...@@ -50,6 +50,7 @@ Kirigami.Page {
ColumnLayout { ColumnLayout {
id: content id: content
visible: !busyIndicator.visible
anchors.fill: parent anchors.fill: parent
spacing: 0 spacing: 0
...@@ -140,24 +141,24 @@ Kirigami.Page { ...@@ -140,24 +141,24 @@ Kirigami.Page {
} }
Kaidan.changePassword(password1.text) Kaidan.changePassword(password1.text)
content.visible = false
busyIndicator.visible = true busyIndicator.visible = true
} }
} }
} }
} }
function handleChangeResult() { Connections {
busyIndicator.visible = false target: Kaidan
stack.pop()
}
Component.onCompleted: { onPasswordChangeSucceeded: {
Kaidan.passwordChangeSucceeded.connect(handleChangeResult) busyIndicator.visible = false
Kaidan.passwordChangeFailed.connect(handleChangeResult) passiveNotification(qsTr("Password changed successfully"))
} stack.pop()
Component.onDestruction: { }
Kaidan.passwordChangeSucceeded.disconnect(handleChangeResult)
Kaidan.passwordChangeFailed.disconnect(handleChangeResult) onPasswordChangeFailed: {
busyIndicator.visible = false
passiveNotification(qsTr("Failed to change password: %1").arg(errorMessage))
}
} }
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment