moment/src/qml/Pages/SignIn.qml

154 lines
4.4 KiB
QML
Raw Normal View History

import QtQuick 2.12
import QtQuick.Layouts 1.12
import "../Base"
HPage {
property string loginWith: "username"
readonly property bool canLogin:
serverField.text && idField.text && passwordField.text
onFocusChanged: idField.forceActiveFocus()
2019-08-28 11:56:05 -04:00
HBox {
id: signInBox
Layout.alignment: Qt.AlignCenter
title: qsTr("Sign in")
clickButtonOnEnter: "login"
buttonModel: [
{ name: "register", text: qsTr("Register"), enabled: false },
{ name: "login", text: qsTr("Login"), enabled: canLogin },
{ name: "forgot", text: qsTr("Forgot?"), enabled: false },
]
buttonCallbacks: ({
register: button => {},
login: button => {
button.loading = true
errorMessage.text = ""
let args = [
idField.text, passwordField.text,
undefined, serverField.text,
]
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(
2019-11-10 09:07:35 -04:00
"AccountSettings/AccountSettings", {userId: data}
)
}, type => {
loginTimeout.stop()
let txt = qsTr("Invalid request or login type")
if (type === "MatrixForbidden")
txt = qsTr("Invalid username or password")
if (type === "MatrixUserDeactivated")
txt = qsTr("This account was deactivated")
errorMessage.text = txt
button.loading = false
2019-04-27 21:07:20 -04:00
})
},
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
Layout.topMargin: signInBox.verticalSpacing / 2
Layout.bottomMargin: Layout.topMargin
Repeater {
model: ["username", "email", "phone"]
2019-08-20 17:41:24 -04:00
HButton {
icon.name: modelData
iconItem.dimension: 24
circle: true
checked: loginWith == modelData
2019-07-24 18:41:40 -04:00
enabled: modelData == "username"
autoExclusive: true
onClicked: loginWith = modelData
}
}
}
HTextField {
id: serverField
placeholderText: qsTr("Homeserver URL")
text: "https://matrix.org"
Layout.fillWidth: true
}
HTextField {
id: idField
placeholderText: qsTr(
loginWith === "email" ? "Email" :
loginWith === "phone" ? "Phone" :
"Username"
)
Layout.fillWidth: true
}
HTextField {
id: passwordField
placeholderText: qsTr("Password")
2019-04-28 15:36:43 -04:00
echoMode: HTextField.Password
Layout.fillWidth: true
}
HCheckBox {
id: rememberAccount
text: qsTr("Automatically sign in")
checked: true
spacing: signInBox.horizontalSpacing
Layout.maximumWidth: parent.width
Layout.alignment: Qt.AlignHCenter
}
2019-08-16 16:30:18 -04:00
HLabel {
id: errorMessage
wrapMode: Text.Wrap
horizontalAlignment: Text.AlignHCenter
color: theme.colors.errorText
visible: Layout.maximumHeight > 0
Layout.maximumHeight: text ? implicitHeight : 0
Behavior on Layout.maximumHeight { HNumberAnimation {} }
Layout.fillWidth: true
}
}
}