Properly handle login errors with new exceptions

This commit is contained in:
miruka
2019-11-11 06:39:11 -04:00
parent de7053f196
commit 7f48c1b35d
4 changed files with 48 additions and 15 deletions

View File

@@ -34,23 +34,33 @@ HPage {
undefined, serverField.text,
]
py.callCoro("login_client", args, ([success, data]) => {
if (! success) {
errorMessage.text = qsTr(data)
button.loading = false
return
}
loginTimeout.restart()
py.callCoro("login_client", args, userId => {
loginTimeout.stop()
errorMessage.text = ""
button.loading = false
py.callCoro(
"saved_accounts." +
(rememberAccount.checked ? "add": "delete"),
[data]
)
pageLoader.showPage(
"AccountSettings/AccountSettings", {userId: data}
)
}, type => {
loginTimeout.stop()
let txt = qsTr("Invalid request or login type")
errorMessage.text = ""
if (type === "MatrixForbidden")
txt = qsTr("Invalid username or password")
if (type === "MatrixUserDeactivated")
txt = qsTr("This account was deactivated")
errorMessage.text = txt
button.loading = false
})
},
@@ -58,6 +68,17 @@ HPage {
forgot: button => {}
})
Timer {
id: loginTimeout
interval: 30 * 1000
onTriggered: {
errorMessage.text = qsTr(
"This server seems unavailable. Verify your internet " +
"connection or try again in a few minutes."
)
}
}
HRowLayout {
spacing: signInBox.horizontalSpacing * 1.25
Layout.alignment: Qt.AlignHCenter