2019-07-13 05:39:01 -04:00
|
|
|
import QtQuick 2.12
|
|
|
|
import QtQuick.Layouts 1.12
|
2019-04-28 15:18:36 -04:00
|
|
|
import "../Base"
|
2019-04-27 18:54:33 -04:00
|
|
|
|
2019-08-17 13:01:43 -04:00
|
|
|
HPage {
|
2019-04-27 18:54:33 -04:00
|
|
|
property string loginWith: "username"
|
2019-09-07 17:24:58 -04:00
|
|
|
readonly property bool canLogin:
|
2019-11-11 06:57:33 -04:00
|
|
|
serverField.text && idField.text && passwordField.text &&
|
|
|
|
! serverField.error
|
2019-08-16 16:44:28 -04:00
|
|
|
|
2019-07-02 13:59:52 -04:00
|
|
|
onFocusChanged: idField.forceActiveFocus()
|
2019-04-27 18:54:33 -04:00
|
|
|
|
2019-08-28 11:56:05 -04:00
|
|
|
HBox {
|
2019-04-27 18:54:33 -04:00
|
|
|
id: signInBox
|
2019-08-17 13:01:43 -04:00
|
|
|
Layout.alignment: Qt.AlignCenter
|
2019-04-27 18:54:33 -04:00
|
|
|
|
2019-08-17 13:01:43 -04:00
|
|
|
title: qsTr("Sign in")
|
2019-09-09 07:41:48 -04:00
|
|
|
clickButtonOnEnter: "login"
|
2019-04-27 18:54:33 -04:00
|
|
|
|
|
|
|
buttonModel: [
|
2019-07-18 20:39:13 -04:00
|
|
|
{ name: "register", text: qsTr("Register"), enabled: false },
|
2019-11-11 09:12:31 -04:00
|
|
|
{ name: "login", text: qsTr("Login"), enabled: canLogin,
|
|
|
|
disableWhileLoading: false },
|
2019-08-17 13:01:43 -04:00
|
|
|
{ name: "forgot", text: qsTr("Forgot?"), enabled: false },
|
2019-04-27 18:54:33 -04:00
|
|
|
]
|
|
|
|
|
2019-07-18 04:17:35 -04:00
|
|
|
buttonCallbacks: ({
|
|
|
|
register: button => {},
|
2019-04-27 18:54:33 -04:00
|
|
|
|
2019-07-18 04:17:35 -04:00
|
|
|
login: button => {
|
2019-11-09 11:15:24 -04:00
|
|
|
button.loading = true
|
|
|
|
errorMessage.text = ""
|
|
|
|
|
2019-09-07 17:24:58 -04:00
|
|
|
let args = [
|
|
|
|
idField.text, passwordField.text,
|
|
|
|
undefined, serverField.text,
|
|
|
|
]
|
2019-07-02 13:59:52 -04:00
|
|
|
|
2019-11-11 06:39:11 -04:00
|
|
|
loginTimeout.restart()
|
|
|
|
|
|
|
|
py.callCoro("login_client", args, userId => {
|
|
|
|
loginTimeout.stop()
|
|
|
|
errorMessage.text = ""
|
|
|
|
button.loading = false
|
2019-08-17 13:01:43 -04:00
|
|
|
|
|
|
|
py.callCoro(
|
2019-11-12 18:12:41 -04:00
|
|
|
rememberAccount.checked ?
|
|
|
|
"saved_accounts.add": "saved_accounts.delete",
|
|
|
|
|
|
|
|
[userId]
|
2019-08-17 13:01:43 -04:00
|
|
|
)
|
2019-11-11 06:39:11 -04:00
|
|
|
|
2019-08-19 15:37:48 -04:00
|
|
|
pageLoader.showPage(
|
2019-11-12 18:12:41 -04:00
|
|
|
"AccountSettings/AccountSettings", {userId}
|
2019-08-17 13:01:43 -04:00
|
|
|
)
|
2019-11-12 18:12:41 -04:00
|
|
|
|
2019-11-11 06:39:11 -04:00
|
|
|
}, type => {
|
2019-11-11 09:12:31 -04:00
|
|
|
if (type === "CancelledError") return
|
|
|
|
|
2019-11-11 06:39:11 -04:00
|
|
|
loginTimeout.stop()
|
|
|
|
let txt = qsTr("Invalid request or login type")
|
2019-08-17 13:01:43 -04:00
|
|
|
|
2019-11-11 06:39:11 -04:00
|
|
|
if (type === "MatrixForbidden")
|
|
|
|
txt = qsTr("Invalid username or password")
|
|
|
|
|
|
|
|
if (type === "MatrixUserDeactivated")
|
|
|
|
txt = qsTr("This account was deactivated")
|
|
|
|
|
|
|
|
errorMessage.text = txt
|
2019-08-17 13:01:43 -04:00
|
|
|
button.loading = false
|
2019-04-27 21:07:20 -04:00
|
|
|
})
|
2019-04-27 18:54:33 -04:00
|
|
|
},
|
|
|
|
|
2019-07-18 04:17:35 -04:00
|
|
|
forgot: button => {}
|
|
|
|
})
|
2019-04-27 18:54:33 -04:00
|
|
|
|
2019-11-11 06:39:11 -04:00
|
|
|
Timer {
|
|
|
|
id: loginTimeout
|
|
|
|
interval: 30 * 1000
|
|
|
|
onTriggered: {
|
2019-11-11 06:57:33 -04:00
|
|
|
errorMessage.text =
|
|
|
|
serverField.knownServerChosen ?
|
|
|
|
|
|
|
|
qsTr("This server seems unavailable. Verify your inter" +
|
|
|
|
"net connection or try again in a few minutes.") :
|
|
|
|
|
|
|
|
qsTr("This server seems unavailable. Verify the " +
|
|
|
|
"entered URL, your internet connection or try " +
|
|
|
|
"again in a few minutes.")
|
2019-11-11 06:39:11 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-28 15:18:36 -04:00
|
|
|
HRowLayout {
|
2019-08-17 13:01:43 -04:00
|
|
|
spacing: signInBox.horizontalSpacing * 1.25
|
2019-04-27 18:54:33 -04:00
|
|
|
Layout.alignment: Qt.AlignHCenter
|
2019-08-17 13:01:43 -04:00
|
|
|
Layout.topMargin: signInBox.verticalSpacing / 2
|
|
|
|
Layout.bottomMargin: Layout.topMargin
|
2019-04-27 18:54:33 -04:00
|
|
|
|
|
|
|
Repeater {
|
|
|
|
model: ["username", "email", "phone"]
|
|
|
|
|
2019-08-20 17:41:24 -04:00
|
|
|
HButton {
|
2019-08-21 15:45:13 -04:00
|
|
|
icon.name: modelData
|
2019-04-27 18:54:33 -04:00
|
|
|
circle: true
|
|
|
|
checked: loginWith == modelData
|
2019-07-24 18:41:40 -04:00
|
|
|
enabled: modelData == "username"
|
2019-04-27 18:54:33 -04:00
|
|
|
autoExclusive: true
|
|
|
|
onClicked: loginWith = modelData
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-07 17:24:58 -04:00
|
|
|
HTextField {
|
|
|
|
id: serverField
|
|
|
|
placeholderText: qsTr("Homeserver URL")
|
|
|
|
text: "https://matrix.org"
|
2019-11-11 06:57:33 -04:00
|
|
|
error: ! /.+:\/\/.+/.test(cleanText)
|
2019-09-07 17:24:58 -04:00
|
|
|
|
|
|
|
Layout.fillWidth: true
|
2019-11-11 06:57:33 -04:00
|
|
|
|
|
|
|
|
|
|
|
readonly property string cleanText: text.toLowerCase().trim()
|
|
|
|
|
|
|
|
// 2019-11-11 https://www.hello-matrix.net/public_servers.php
|
|
|
|
readonly property var knownServers: [
|
|
|
|
"https://matrix.org",
|
|
|
|
"https://chat.weho.st",
|
|
|
|
"https://tchncs.de",
|
|
|
|
"https://chat.privacytools.io",
|
|
|
|
"https://hackerspaces.be",
|
|
|
|
"https://matrix.allmende.io",
|
|
|
|
"https://feneas.org",
|
|
|
|
"https://junta.pl",
|
|
|
|
"https://perthchat.org",
|
|
|
|
"https://matrix.tedomum.net",
|
|
|
|
"https://converser.eu",
|
|
|
|
"https://ru-matrix.org",
|
|
|
|
"https://matrix.sibnsk.net",
|
|
|
|
"https://alternanet.fr",
|
|
|
|
]
|
|
|
|
|
|
|
|
readonly property bool knownServerChosen:
|
|
|
|
knownServers.includes(cleanText)
|
2019-09-07 17:24:58 -04:00
|
|
|
}
|
|
|
|
|
2019-04-28 15:18:36 -04:00
|
|
|
HTextField {
|
2019-07-02 13:59:52 -04:00
|
|
|
id: idField
|
2019-04-27 18:54:33 -04:00
|
|
|
placeholderText: qsTr(
|
|
|
|
loginWith === "email" ? "Email" :
|
|
|
|
loginWith === "phone" ? "Phone" :
|
|
|
|
"Username"
|
|
|
|
)
|
|
|
|
|
|
|
|
Layout.fillWidth: true
|
|
|
|
}
|
|
|
|
|
2019-04-28 15:18:36 -04:00
|
|
|
HTextField {
|
2019-04-27 18:54:33 -04:00
|
|
|
id: passwordField
|
|
|
|
placeholderText: qsTr("Password")
|
2019-04-28 15:36:43 -04:00
|
|
|
echoMode: HTextField.Password
|
2019-04-27 18:54:33 -04:00
|
|
|
|
|
|
|
Layout.fillWidth: true
|
2019-08-17 13:01:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
HCheckBox {
|
|
|
|
id: rememberAccount
|
|
|
|
text: qsTr("Automatically sign in")
|
|
|
|
checked: true
|
|
|
|
spacing: signInBox.horizontalSpacing
|
|
|
|
|
|
|
|
Layout.maximumWidth: parent.width
|
|
|
|
Layout.alignment: Qt.AlignHCenter
|
2019-04-27 18:54:33 -04:00
|
|
|
}
|
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
|
|
|
|
}
|
2019-04-27 18:54:33 -04:00
|
|
|
}
|
|
|
|
}
|