2019-07-13 19:39:01 +10:00
|
|
|
import QtQuick 2.12
|
|
|
|
import QtQuick.Layouts 1.12
|
2019-04-29 05:18:36 +10:00
|
|
|
import "../Base"
|
2019-04-28 08:54:33 +10:00
|
|
|
|
2019-08-18 03:01:43 +10:00
|
|
|
HPage {
|
2019-04-28 08:54:33 +10:00
|
|
|
property string loginWith: "username"
|
2019-09-08 07:24:58 +10:00
|
|
|
readonly property bool canLogin:
|
|
|
|
serverField.text && idField.text && passwordField.text
|
2019-08-17 06:44:28 +10:00
|
|
|
|
2019-07-03 03:59:52 +10:00
|
|
|
onFocusChanged: idField.forceActiveFocus()
|
2019-04-28 08:54:33 +10:00
|
|
|
|
2019-08-29 01:56:05 +10:00
|
|
|
HBox {
|
2019-04-28 08:54:33 +10:00
|
|
|
id: signInBox
|
2019-08-18 03:01:43 +10:00
|
|
|
Layout.alignment: Qt.AlignCenter
|
2019-04-28 08:54:33 +10:00
|
|
|
|
2019-08-18 03:01:43 +10:00
|
|
|
multiplyWidth: 0.85
|
|
|
|
title: qsTr("Sign in")
|
2019-09-09 21:41:48 +10:00
|
|
|
clickButtonOnEnter: "login"
|
2019-04-28 08:54:33 +10:00
|
|
|
|
|
|
|
buttonModel: [
|
2019-07-19 10:39:13 +10:00
|
|
|
{ name: "register", text: qsTr("Register"), enabled: false },
|
2019-08-17 06:44:28 +10:00
|
|
|
{ name: "login", text: qsTr("Login"), enabled: canLogin },
|
2019-08-18 03:01:43 +10:00
|
|
|
{ name: "forgot", text: qsTr("Forgot?"), enabled: false },
|
2019-04-28 08:54:33 +10:00
|
|
|
]
|
|
|
|
|
2019-07-18 18:17:35 +10:00
|
|
|
buttonCallbacks: ({
|
|
|
|
register: button => {},
|
2019-04-28 08:54:33 +10:00
|
|
|
|
2019-07-18 18:17:35 +10:00
|
|
|
login: button => {
|
2019-07-03 03:59:52 +10:00
|
|
|
button.loading = true
|
2019-09-08 07:24:58 +10:00
|
|
|
let args = [
|
|
|
|
idField.text, passwordField.text,
|
|
|
|
undefined, serverField.text,
|
|
|
|
]
|
2019-07-03 03:59:52 +10:00
|
|
|
|
2019-08-17 06:30:18 +10:00
|
|
|
py.callCoro("login_client", args, ([success, data]) => {
|
2019-08-18 03:01:43 +10:00
|
|
|
if (! success) {
|
2019-08-17 06:30:18 +10:00
|
|
|
errorMessage.text = qsTr(data)
|
2019-08-18 03:01:43 +10:00
|
|
|
button.loading = false
|
|
|
|
return
|
2019-08-17 06:30:18 +10:00
|
|
|
}
|
2019-08-18 03:01:43 +10:00
|
|
|
|
|
|
|
py.callCoro(
|
|
|
|
"saved_accounts." +
|
|
|
|
(rememberAccount.checked ? "add": "delete"),
|
|
|
|
[data]
|
|
|
|
)
|
2019-08-20 05:37:48 +10:00
|
|
|
pageLoader.showPage(
|
2019-08-18 03:01:43 +10:00
|
|
|
"EditAccount/EditAccount", {userId: data}
|
|
|
|
)
|
|
|
|
|
|
|
|
errorMessage.text = ""
|
|
|
|
button.loading = false
|
2019-04-28 11:07:20 +10:00
|
|
|
})
|
2019-04-28 08:54:33 +10:00
|
|
|
},
|
|
|
|
|
2019-07-18 18:17:35 +10:00
|
|
|
forgot: button => {}
|
|
|
|
})
|
2019-04-28 08:54:33 +10:00
|
|
|
|
2019-04-29 05:18:36 +10:00
|
|
|
HRowLayout {
|
2019-08-18 03:01:43 +10:00
|
|
|
spacing: signInBox.horizontalSpacing * 1.25
|
2019-04-28 08:54:33 +10:00
|
|
|
Layout.alignment: Qt.AlignHCenter
|
2019-08-18 03:01:43 +10:00
|
|
|
Layout.topMargin: signInBox.verticalSpacing / 2
|
|
|
|
Layout.bottomMargin: Layout.topMargin
|
2019-04-28 08:54:33 +10:00
|
|
|
|
|
|
|
Repeater {
|
|
|
|
model: ["username", "email", "phone"]
|
|
|
|
|
2019-08-21 07:41:24 +10:00
|
|
|
HButton {
|
2019-08-22 05:45:13 +10:00
|
|
|
icon.name: modelData
|
|
|
|
iconItem.dimension: 24
|
2019-04-28 08:54:33 +10:00
|
|
|
circle: true
|
|
|
|
checked: loginWith == modelData
|
2019-07-25 08:41:40 +10:00
|
|
|
enabled: modelData == "username"
|
2019-04-28 08:54:33 +10:00
|
|
|
autoExclusive: true
|
|
|
|
onClicked: loginWith = modelData
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-08 07:24:58 +10:00
|
|
|
HTextField {
|
|
|
|
id: serverField
|
|
|
|
placeholderText: qsTr("Homeserver URL")
|
|
|
|
text: "https://matrix.org"
|
|
|
|
|
|
|
|
Layout.fillWidth: true
|
|
|
|
}
|
|
|
|
|
2019-04-29 05:18:36 +10:00
|
|
|
HTextField {
|
2019-07-03 03:59:52 +10:00
|
|
|
id: idField
|
2019-04-28 08:54:33 +10:00
|
|
|
placeholderText: qsTr(
|
|
|
|
loginWith === "email" ? "Email" :
|
|
|
|
loginWith === "phone" ? "Phone" :
|
|
|
|
"Username"
|
|
|
|
)
|
|
|
|
|
|
|
|
Layout.fillWidth: true
|
|
|
|
}
|
|
|
|
|
2019-04-29 05:18:36 +10:00
|
|
|
HTextField {
|
2019-04-28 08:54:33 +10:00
|
|
|
id: passwordField
|
|
|
|
placeholderText: qsTr("Password")
|
2019-04-29 05:36:43 +10:00
|
|
|
echoMode: HTextField.Password
|
2019-04-28 08:54:33 +10:00
|
|
|
|
|
|
|
Layout.fillWidth: true
|
2019-08-18 03:01:43 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
HCheckBox {
|
|
|
|
id: rememberAccount
|
|
|
|
text: qsTr("Automatically sign in")
|
|
|
|
checked: true
|
|
|
|
spacing: signInBox.horizontalSpacing
|
|
|
|
|
|
|
|
Layout.maximumWidth: parent.width
|
|
|
|
Layout.alignment: Qt.AlignHCenter
|
2019-04-28 08:54:33 +10:00
|
|
|
}
|
2019-08-17 06:30:18 +10: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
|
|
|
|
}
|
2019-04-28 08:54:33 +10:00
|
|
|
}
|
|
|
|
}
|