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:
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.
......
......@@ -69,12 +69,7 @@ RegistrationManager::RegistrationManager(ClientWorker *clientWorker, QXmppClient
connect(m_manager, &QXmppRegistrationManager::accountDeletionFailed, m_clientWorker, &ClientWorker::handleAccountDeletionFromServerFailed);
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::passwordChangeFailed, Kaidan::instance(), &Kaidan::passwordChangeFailed);
connect(m_manager, &QXmppRegistrationManager::passwordChangeFailed, this, &RegistrationManager::handlePasswordChangeFailed);
}
......@@ -123,16 +118,13 @@ void RegistrationManager::handlePasswordChangeSucceeded(const QString &newPasswo
QString::fromUtf8(newPassword.toUtf8().toBase64())
);
emit Kaidan::instance()->passiveNotificationRequested(
tr("Password changed successfully.")
);
QMetaObject::invokeMethod(Kaidan::instance(), "setPassword", Q_ARG(QString, newPassword));
emit Kaidan::instance()->passwordChangeSucceeded();
}
void RegistrationManager::handlePasswordChangeFailed(const QXmppStanza::Error &error)
{
emit Kaidan::instance()->passiveNotificationRequested(
tr("Failed to change password: %1").arg(error.text())
);
emit Kaidan::instance()->passwordChangeFailed(error.text());
}
void RegistrationManager::handleRegistrationFormReceived(const QXmppRegisterIq &iq)
......
......@@ -50,6 +50,7 @@ Kirigami.Page {
ColumnLayout {
id: content
visible: !busyIndicator.visible
anchors.fill: parent
spacing: 0
......@@ -140,24 +141,24 @@ Kirigami.Page {
}
Kaidan.changePassword(password1.text)
content.visible = false
busyIndicator.visible = true
}
}
}
}
function handleChangeResult() {
Connections {
target: Kaidan
onPasswordChangeSucceeded: {
busyIndicator.visible = false
passiveNotification(qsTr("Password changed successfully"))
stack.pop()
}
Component.onCompleted: {
Kaidan.passwordChangeSucceeded.connect(handleChangeResult)
Kaidan.passwordChangeFailed.connect(handleChangeResult)
onPasswordChangeFailed: {
busyIndicator.visible = false
passiveNotification(qsTr("Failed to change password: %1").arg(errorMessage))
}
Component.onDestruction: {
Kaidan.passwordChangeSucceeded.disconnect(handleChangeResult)
Kaidan.passwordChangeFailed.disconnect(handleChangeResult)
}
}
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