2020-06-17 19:18:31 +00:00
|
|
|
import QtQuick 2.13
|
|
|
|
import QtQuick.Controls 2.13
|
|
|
|
import QtQuick.Layouts 1.13
|
2020-05-27 07:15:42 +00:00
|
|
|
import QtQuick.Dialogs 1.3
|
2020-06-17 19:18:31 +00:00
|
|
|
import QtGraphicalEffects 1.13
|
2021-10-12 18:26:02 +00:00
|
|
|
|
|
|
|
import "../../../../shared"
|
2021-10-14 10:01:34 +00:00
|
|
|
import "../../../../shared/popups"
|
2021-10-14 12:14:11 +00:00
|
|
|
import "../../../../shared/panels"
|
2021-10-14 11:07:19 +00:00
|
|
|
import "../../../../shared/controls"
|
2021-10-12 18:26:02 +00:00
|
|
|
import "../../../../shared/status"
|
|
|
|
import "../popups"
|
|
|
|
import "../stores"
|
2021-09-28 15:04:06 +00:00
|
|
|
|
|
|
|
import utils 1.0
|
2020-05-27 07:15:42 +00:00
|
|
|
|
2020-06-11 21:23:27 +00:00
|
|
|
Item {
|
2020-06-12 20:47:44 +00:00
|
|
|
property var onGenKeyClicked: function () {}
|
|
|
|
property var onExistingKeyClicked: function () {}
|
2020-06-11 21:23:27 +00:00
|
|
|
property bool loading: false
|
2020-06-01 14:36:06 +00:00
|
|
|
|
2020-06-11 21:23:27 +00:00
|
|
|
id: loginView
|
2020-05-27 07:15:42 +00:00
|
|
|
anchors.fill: parent
|
|
|
|
|
2020-06-29 19:49:34 +00:00
|
|
|
function setCurrentFlow(isLogin) {
|
2021-10-12 18:26:02 +00:00
|
|
|
LoginStore.loginModelInst.isCurrentFlow = isLogin;
|
|
|
|
OnboardingStore.onBoardingModel.isCurrentFlow = !isLogin;
|
2020-06-29 19:49:34 +00:00
|
|
|
}
|
|
|
|
|
2021-09-13 11:51:47 +00:00
|
|
|
function doLogin(password) {
|
|
|
|
if (loading || password.length === 0)
|
|
|
|
return
|
|
|
|
|
|
|
|
setCurrentFlow(true);
|
|
|
|
loading = true
|
2021-10-12 18:26:02 +00:00
|
|
|
LoginStore.login(password)
|
|
|
|
applicationWindow.checkForStoringPassToKeychain(LoginStore.currentAccount.username, password, false)
|
2021-09-13 11:51:47 +00:00
|
|
|
txtPassword.textField.clear()
|
|
|
|
}
|
|
|
|
|
|
|
|
function resetLogin() {
|
2021-09-22 08:10:54 +00:00
|
|
|
if(accountSettings.storeToKeychain === Constants.storeToKeychainValueStore)
|
2021-09-13 11:51:47 +00:00
|
|
|
{
|
|
|
|
connection.enabled = true
|
|
|
|
txtPassword.visible = false
|
2021-10-12 18:26:02 +00:00
|
|
|
LoginStore.tryToObtainPassword()
|
2021-09-13 11:51:47 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
txtPassword.visible = true
|
|
|
|
txtPassword.forceActiveFocus(Qt.MouseFocusReason)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-11 21:23:27 +00:00
|
|
|
Component.onCompleted: {
|
2021-09-13 11:51:47 +00:00
|
|
|
resetLogin()
|
|
|
|
}
|
|
|
|
|
|
|
|
Connections{
|
|
|
|
id: connection
|
2021-10-12 18:26:02 +00:00
|
|
|
target: LoginStore.loginModelInst
|
2021-09-13 11:51:47 +00:00
|
|
|
|
|
|
|
onObtainingPasswordError: {
|
|
|
|
enabled = false
|
|
|
|
obtainingPasswordErrorNotification.confirmationText = errorDescription
|
|
|
|
obtainingPasswordErrorNotification.open()
|
|
|
|
}
|
|
|
|
|
|
|
|
onObtainingPasswordSuccess: {
|
|
|
|
enabled = false
|
|
|
|
doLogin(password)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ConfirmationDialog {
|
|
|
|
id: obtainingPasswordErrorNotification
|
|
|
|
height: 270
|
|
|
|
confirmButtonLabel: qsTr("Ok")
|
|
|
|
|
|
|
|
onConfirmButtonClicked: {
|
|
|
|
close()
|
|
|
|
}
|
|
|
|
|
|
|
|
onClosed: {
|
|
|
|
txtPassword.visible = true
|
|
|
|
}
|
2020-05-28 04:06:57 +00:00
|
|
|
}
|
2020-06-30 20:01:37 +00:00
|
|
|
|
2020-06-11 21:23:27 +00:00
|
|
|
Item {
|
|
|
|
id: element
|
|
|
|
width: 360
|
|
|
|
height: 200
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
2020-05-27 07:15:42 +00:00
|
|
|
|
2020-09-22 14:45:09 +00:00
|
|
|
StatusImageIdenticon {
|
2020-06-11 21:23:27 +00:00
|
|
|
id: userImage
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
2021-10-12 18:26:02 +00:00
|
|
|
source: LoginStore.currentAccount.thumbnailImage
|
2020-06-04 13:00:17 +00:00
|
|
|
}
|
2020-05-27 07:15:42 +00:00
|
|
|
|
2020-06-19 18:06:58 +00:00
|
|
|
StyledText {
|
2020-06-11 21:23:27 +00:00
|
|
|
id: usernameText
|
2021-10-12 18:26:02 +00:00
|
|
|
text: LoginStore.currentAccount.username
|
2020-06-11 21:23:27 +00:00
|
|
|
font.weight: Font.Bold
|
|
|
|
font.pixelSize: 17
|
|
|
|
anchors.top: userImage.bottom
|
|
|
|
anchors.topMargin: 4
|
2020-05-27 07:15:42 +00:00
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
}
|
|
|
|
|
2020-06-12 20:47:44 +00:00
|
|
|
ConfirmAddExistingKeyModal {
|
|
|
|
id: confirmAddExstingKeyModal
|
|
|
|
onOpenModalClick: function () {
|
2020-06-29 19:49:34 +00:00
|
|
|
setCurrentFlow(false);
|
2020-06-12 20:47:44 +00:00
|
|
|
onExistingKeyClicked()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-11 21:23:27 +00:00
|
|
|
SelectAnotherAccountModal {
|
|
|
|
id: selectAnotherAccountModal
|
|
|
|
onAccountSelect: function (index) {
|
2021-10-12 18:26:02 +00:00
|
|
|
LoginStore.setCurrentAccount(index)
|
2021-09-13 11:51:47 +00:00
|
|
|
resetLogin()
|
2020-06-11 21:23:27 +00:00
|
|
|
}
|
2020-06-12 20:47:44 +00:00
|
|
|
onOpenModalClick: function () {
|
2020-06-29 19:49:34 +00:00
|
|
|
setCurrentFlow(true);
|
2020-07-06 11:17:39 +00:00
|
|
|
onExistingKeyClicked()
|
2020-06-12 20:47:44 +00:00
|
|
|
}
|
2020-06-11 21:23:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
property bool isHovered: false
|
|
|
|
id: changeAccountBtn
|
|
|
|
width: 24
|
|
|
|
height: 24
|
|
|
|
anchors.left: usernameText.right
|
|
|
|
anchors.leftMargin: 4
|
|
|
|
anchors.verticalCenter: usernameText.verticalCenter
|
|
|
|
|
2020-09-29 06:39:29 +00:00
|
|
|
color: isHovered ? Style.current.backgroundHover : Style.current.transparent
|
2020-06-11 21:23:27 +00:00
|
|
|
|
|
|
|
radius: 4
|
|
|
|
|
2020-06-25 13:23:17 +00:00
|
|
|
SVGImage {
|
2020-06-11 21:23:27 +00:00
|
|
|
id: caretImg
|
|
|
|
width: 10
|
|
|
|
height: 6
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
2021-09-28 15:04:06 +00:00
|
|
|
source: Style.svg("caret")
|
2020-06-11 21:23:27 +00:00
|
|
|
fillMode: Image.PreserveAspectFit
|
|
|
|
}
|
|
|
|
ColorOverlay {
|
|
|
|
anchors.fill: caretImg
|
|
|
|
source: caretImg
|
2020-09-29 06:39:29 +00:00
|
|
|
color: Style.current.secondaryText
|
2020-06-03 06:38:26 +00:00
|
|
|
}
|
2020-06-11 21:23:27 +00:00
|
|
|
MouseArea {
|
|
|
|
hoverEnabled: true
|
|
|
|
anchors.fill: parent
|
|
|
|
cursorShape: Qt.PointingHandCursor
|
|
|
|
onEntered: {
|
|
|
|
changeAccountBtn.isHovered = true
|
|
|
|
}
|
|
|
|
onExited: {
|
|
|
|
changeAccountBtn.isHovered = false
|
|
|
|
}
|
|
|
|
onClicked: {
|
2021-10-12 18:26:02 +00:00
|
|
|
if (LoginStore.rowCount() > 1) {
|
2020-06-12 20:47:44 +00:00
|
|
|
selectAnotherAccountModal.open()
|
|
|
|
} else {
|
2020-07-01 15:26:19 +00:00
|
|
|
confirmAddExstingKeyModal.open()
|
2020-06-12 20:47:44 +00:00
|
|
|
}
|
2020-06-03 06:38:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-29 19:54:06 +00:00
|
|
|
Input {
|
|
|
|
id: txtPassword
|
2021-07-26 07:17:49 +00:00
|
|
|
anchors.top: changeAccountBtn.bottom
|
2020-07-02 15:14:31 +00:00
|
|
|
anchors.topMargin: Style.current.padding * 2
|
2021-07-21 05:50:35 +00:00
|
|
|
enabled: !loading
|
2021-07-30 16:02:22 +00:00
|
|
|
placeholderText: loading ?
|
|
|
|
//% "Connecting..."
|
|
|
|
qsTrId("connecting") :
|
|
|
|
//% "Enter password"
|
|
|
|
qsTrId("enter-password")
|
2020-06-04 14:53:10 +00:00
|
|
|
textField.echoMode: TextInput.Password
|
2020-06-11 21:23:27 +00:00
|
|
|
textField.focus: true
|
2020-05-29 19:54:06 +00:00
|
|
|
Keys.onReturnPressed: {
|
2021-09-13 11:51:47 +00:00
|
|
|
doLogin(textField.text)
|
2020-05-27 07:15:42 +00:00
|
|
|
}
|
2021-01-26 18:37:58 +00:00
|
|
|
onTextEdited: {
|
|
|
|
errMsg.visible = false
|
|
|
|
loading = false
|
|
|
|
}
|
2020-05-27 07:15:42 +00:00
|
|
|
}
|
2021-07-21 05:50:35 +00:00
|
|
|
|
2020-09-29 06:39:29 +00:00
|
|
|
StatusRoundButton {
|
2020-09-29 18:32:36 +00:00
|
|
|
id: submitBtn
|
2020-09-29 06:39:29 +00:00
|
|
|
size: "medium"
|
2021-03-16 19:19:48 +00:00
|
|
|
type: "secondary"
|
2020-09-29 06:39:29 +00:00
|
|
|
icon.name: "arrow-right"
|
|
|
|
icon.width: 18
|
|
|
|
icon.height: 14
|
2021-07-21 05:50:35 +00:00
|
|
|
opacity: (loading || txtPassword.text.length > 0) ? 1 : 0
|
2021-09-13 11:51:47 +00:00
|
|
|
anchors.left: txtPassword.visible? txtPassword.right : changeAccountBtn.right
|
2021-07-21 05:50:35 +00:00
|
|
|
anchors.leftMargin: (loading || txtPassword.text.length > 0) ? Style.current.padding : Style.current.smallPadding
|
2021-09-13 11:51:47 +00:00
|
|
|
anchors.verticalCenter: txtPassword.visible? txtPassword.verticalCenter : changeAccountBtn.verticalCenter
|
2020-09-29 06:39:29 +00:00
|
|
|
state: loading ? "pending" : "default"
|
2020-06-11 21:23:27 +00:00
|
|
|
onClicked: {
|
2021-09-13 11:51:47 +00:00
|
|
|
doLogin(txtPassword.textField.text)
|
2021-07-21 05:50:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// https://www.figma.com/file/BTS422M9AkvWjfRrXED3WC/%F0%9F%91%8B-Onboarding%E2%8E%9CDesktop?node-id=6%3A0
|
|
|
|
Behavior on opacity {
|
|
|
|
OpacityAnimator {
|
|
|
|
from: 0.5
|
|
|
|
duration: 200
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Behavior on anchors.leftMargin {
|
|
|
|
NumberAnimation {
|
|
|
|
duration: 200
|
|
|
|
}
|
2020-06-11 21:23:27 +00:00
|
|
|
}
|
2020-06-22 19:32:00 +00:00
|
|
|
}
|
|
|
|
|
2020-05-27 07:15:42 +00:00
|
|
|
Connections {
|
2021-10-12 18:26:02 +00:00
|
|
|
target: LoginStore.loginModelInst
|
2020-06-02 08:41:24 +00:00
|
|
|
ignoreUnknownSignals: true
|
2020-05-27 07:15:42 +00:00
|
|
|
onLoginResponseChanged: {
|
2020-06-11 21:23:27 +00:00
|
|
|
if (error) {
|
2021-07-21 05:50:35 +00:00
|
|
|
// SQLITE_NOTADB: "file is not a database"
|
|
|
|
if (error === "file is not a database") {
|
|
|
|
errMsg.text = errMsg.incorrectPasswordMsg
|
|
|
|
} else {
|
2021-07-30 16:02:22 +00:00
|
|
|
//% "Login failed: %1"
|
|
|
|
errMsg.text = qsTrId("login-failed---1").arg(error.toUpperCase())
|
2021-07-21 05:50:35 +00:00
|
|
|
}
|
|
|
|
errMsg.visible = true
|
|
|
|
loading = false
|
|
|
|
txtPassword.textField.forceActiveFocus()
|
2020-06-11 21:23:27 +00:00
|
|
|
}
|
2020-05-27 07:15:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-08 03:23:11 +00:00
|
|
|
StatusButton {
|
|
|
|
id: generateKeysLinkText
|
|
|
|
//% "Generate new keys"
|
|
|
|
text: qsTrId("generate-new-keys")
|
2021-09-13 11:51:47 +00:00
|
|
|
anchors.top: txtPassword.visible? txtPassword.bottom : changeAccountBtn.bottom
|
2021-01-26 18:37:58 +00:00
|
|
|
anchors.topMargin: 16
|
2020-05-27 07:15:42 +00:00
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
2020-10-08 03:23:11 +00:00
|
|
|
font.pixelSize: 13
|
2021-01-25 15:51:37 +00:00
|
|
|
type: "secondary"
|
2020-06-12 20:47:44 +00:00
|
|
|
onClicked: {
|
2020-06-29 19:49:34 +00:00
|
|
|
setCurrentFlow(false);
|
2020-06-12 20:47:44 +00:00
|
|
|
onGenKeyClicked()
|
|
|
|
}
|
2020-05-27 07:15:42 +00:00
|
|
|
}
|
2021-01-26 18:37:58 +00:00
|
|
|
|
|
|
|
StyledText {
|
|
|
|
id: errMsg
|
2021-07-21 05:50:35 +00:00
|
|
|
//% "Login failed. Please re-enter your password and try again."
|
|
|
|
readonly property string incorrectPasswordMsg: qsTrId("login-failed--please-re-enter-your-password-and-try-again-")
|
2021-01-26 18:37:58 +00:00
|
|
|
anchors.top: generateKeysLinkText.bottom
|
|
|
|
anchors.topMargin: Style.current.smallPadding
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
visible: false
|
2021-07-21 05:50:35 +00:00
|
|
|
text: incorrectPasswordMsg
|
2021-01-26 18:37:58 +00:00
|
|
|
font.pixelSize: 13
|
|
|
|
color: Style.current.danger
|
|
|
|
}
|
2020-05-27 07:15:42 +00:00
|
|
|
}
|
|
|
|
}
|