2020-06-17 19:18:31 +00:00
|
|
|
import QtQuick 2.13
|
|
|
|
import QtQuick.Controls 2.13
|
2020-06-12 20:47:44 +00:00
|
|
|
import QtQuick.Dialogs 1.3
|
2021-10-12 18:26:02 +00:00
|
|
|
|
2021-07-23 09:22:14 +00:00
|
|
|
import StatusQ.Controls 0.1
|
2021-09-28 15:04:06 +00:00
|
|
|
|
|
|
|
import utils 1.0
|
2021-10-27 21:27:49 +00:00
|
|
|
import shared 1.0
|
|
|
|
import shared.panels 1.0
|
|
|
|
import shared.popups 1.0
|
|
|
|
import shared.controls 1.0
|
2020-06-12 20:47:44 +00:00
|
|
|
|
2022-03-07 22:59:38 +00:00
|
|
|
import "../stores"
|
|
|
|
|
2021-10-14 11:07:19 +00:00
|
|
|
// TODO: replace with StatusModal
|
2020-06-12 20:47:44 +00:00
|
|
|
ModalPopup {
|
2022-02-24 12:18:21 +00:00
|
|
|
property var privacyStore
|
2020-06-12 20:47:44 +00:00
|
|
|
property bool loading: false
|
2020-12-03 22:26:05 +00:00
|
|
|
property bool firstPasswordFieldValid: false
|
|
|
|
property bool repeatPasswordFieldValid: false
|
2020-06-23 19:31:35 +00:00
|
|
|
property string passwordValidationError: ""
|
|
|
|
property string repeatPasswordValidationError: ""
|
2021-09-13 11:51:47 +00:00
|
|
|
property bool storingPasswordModal: false
|
2020-06-23 19:31:35 +00:00
|
|
|
|
2022-04-11 11:39:15 +00:00
|
|
|
signal offerToStorePassword(string password, bool runStoreToKeychainPopup)
|
|
|
|
|
2020-06-12 20:47:44 +00:00
|
|
|
id: popup
|
2021-09-13 11:51:47 +00:00
|
|
|
title: storingPasswordModal?
|
|
|
|
qsTr("Store password") :
|
2022-04-04 11:26:30 +00:00
|
|
|
qsTr("Create a password")
|
2020-06-12 20:47:44 +00:00
|
|
|
height: 500
|
|
|
|
|
|
|
|
onOpened: {
|
|
|
|
firstPasswordField.text = "";
|
|
|
|
firstPasswordField.forceActiveFocus(Qt.MouseFocusReason)
|
|
|
|
}
|
2020-06-30 20:01:37 +00:00
|
|
|
|
2020-06-12 20:47:44 +00:00
|
|
|
Input {
|
|
|
|
id: firstPasswordField
|
|
|
|
anchors.rightMargin: 56
|
|
|
|
anchors.leftMargin: 56
|
|
|
|
anchors.top: parent.top
|
2021-09-13 11:51:47 +00:00
|
|
|
anchors.topMargin: storingPasswordModal? Style.current.xlPadding : 88
|
|
|
|
placeholderText: storingPasswordModal?
|
|
|
|
qsTr("Current password...") :
|
2022-04-04 11:26:30 +00:00
|
|
|
qsTr("New password...")
|
2020-06-12 20:47:44 +00:00
|
|
|
textField.echoMode: TextInput.Password
|
2020-12-03 22:26:05 +00:00
|
|
|
onTextChanged: {
|
|
|
|
[firstPasswordFieldValid, passwordValidationError] =
|
2020-12-04 14:53:00 +00:00
|
|
|
Utils.validatePasswords("first", firstPasswordField, repeatPasswordField);
|
2022-02-24 12:18:21 +00:00
|
|
|
[repeatPasswordFieldValid, repeatPasswordValidationError] =
|
|
|
|
Utils.validatePasswords("repeat", firstPasswordField, repeatPasswordField);
|
2020-12-03 22:26:05 +00:00
|
|
|
}
|
2020-06-12 20:47:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Input {
|
|
|
|
id: repeatPasswordField
|
2020-12-03 22:26:05 +00:00
|
|
|
enabled: firstPasswordFieldValid
|
2020-06-12 20:47:44 +00:00
|
|
|
anchors.rightMargin: 0
|
|
|
|
anchors.leftMargin: 0
|
|
|
|
anchors.right: firstPasswordField.right
|
|
|
|
anchors.left: firstPasswordField.left
|
|
|
|
anchors.top: firstPasswordField.bottom
|
2020-07-02 15:14:31 +00:00
|
|
|
anchors.topMargin: Style.current.xlPadding
|
2022-04-04 11:26:30 +00:00
|
|
|
placeholderText: qsTr("Confirm password…")
|
2020-06-12 20:47:44 +00:00
|
|
|
textField.echoMode: TextInput.Password
|
2021-07-26 08:11:01 +00:00
|
|
|
Keys.onReturnPressed: function(event) {
|
2021-09-08 13:28:23 +00:00
|
|
|
if (submitBtn.enabled) {
|
|
|
|
submitBtn.clicked(event)
|
|
|
|
}
|
2020-06-12 20:47:44 +00:00
|
|
|
}
|
2020-12-03 22:26:05 +00:00
|
|
|
onTextChanged: {
|
|
|
|
[repeatPasswordFieldValid, repeatPasswordValidationError] =
|
2020-12-04 14:53:00 +00:00
|
|
|
Utils.validatePasswords("repeat", firstPasswordField, repeatPasswordField);
|
2020-12-03 22:26:05 +00:00
|
|
|
}
|
2020-06-12 20:47:44 +00:00
|
|
|
}
|
|
|
|
|
2020-12-05 21:00:28 +00:00
|
|
|
StyledText {
|
|
|
|
id: validationError
|
|
|
|
text: {
|
|
|
|
if (passwordValidationError !== "") return passwordValidationError;
|
|
|
|
if (repeatPasswordValidationError !== "") return repeatPasswordValidationError;
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
anchors.top: repeatPasswordField.bottom
|
|
|
|
anchors.topMargin: 20
|
|
|
|
anchors.right: parent.right
|
|
|
|
anchors.rightMargin: Style.current.xlPadding
|
|
|
|
anchors.left: parent.left
|
|
|
|
anchors.leftMargin: Style.current.xlPadding
|
|
|
|
horizontalAlignment: Text.AlignHCenter
|
|
|
|
color: Style.current.danger
|
|
|
|
font.pixelSize: 11
|
|
|
|
}
|
|
|
|
|
2020-06-19 18:06:58 +00:00
|
|
|
StyledText {
|
2021-09-13 11:51:47 +00:00
|
|
|
visible: !storingPasswordModal
|
2022-04-04 11:26:30 +00:00
|
|
|
text: qsTr("At least 6 characters. You will use this password to unlock status on this device & sign transactions.")
|
2020-06-12 20:47:44 +00:00
|
|
|
wrapMode: Text.WordWrap
|
|
|
|
anchors.right: parent.right
|
2020-07-02 15:14:31 +00:00
|
|
|
anchors.rightMargin: Style.current.xlPadding
|
2020-06-12 20:47:44 +00:00
|
|
|
anchors.left: parent.left
|
2020-07-02 15:14:31 +00:00
|
|
|
anchors.leftMargin: Style.current.xlPadding
|
2020-06-12 20:47:44 +00:00
|
|
|
horizontalAlignment: Text.AlignHCenter
|
|
|
|
anchors.bottom: parent.bottom
|
|
|
|
anchors.bottomMargin: 0
|
2020-09-29 06:39:29 +00:00
|
|
|
color: Style.current.secondaryText
|
2020-06-12 20:47:44 +00:00
|
|
|
font.pixelSize: 12
|
|
|
|
}
|
|
|
|
|
2020-06-22 19:32:00 +00:00
|
|
|
footer: Item {
|
2021-01-13 19:15:52 +00:00
|
|
|
width: parent.width
|
|
|
|
height: submitBtn.height
|
2020-06-12 20:47:44 +00:00
|
|
|
|
2020-09-29 06:39:29 +00:00
|
|
|
StatusButton {
|
2020-06-22 19:32:00 +00:00
|
|
|
id: submitBtn
|
|
|
|
anchors.bottom: parent.bottom
|
2020-07-02 15:14:31 +00:00
|
|
|
anchors.topMargin: Style.current.padding
|
2020-06-22 19:32:00 +00:00
|
|
|
anchors.right: parent.right
|
2020-10-26 14:23:36 +00:00
|
|
|
state: loading ? "pending" : "default"
|
2021-09-13 11:51:47 +00:00
|
|
|
|
|
|
|
text: storingPasswordModal?
|
|
|
|
qsTr("Store password") :
|
2022-04-04 11:26:30 +00:00
|
|
|
qsTr("Create password")
|
2020-06-12 20:47:44 +00:00
|
|
|
|
2020-12-03 22:26:05 +00:00
|
|
|
enabled: firstPasswordFieldValid && repeatPasswordFieldValid && !loading
|
2020-06-22 19:32:00 +00:00
|
|
|
|
|
|
|
MessageDialog {
|
|
|
|
id: importError
|
2022-04-04 11:26:30 +00:00
|
|
|
title: qsTr("Error importing account")
|
|
|
|
text: qsTr("An error occurred while importing your account: ")
|
2020-06-22 19:32:00 +00:00
|
|
|
icon: StandardIcon.Critical
|
|
|
|
standardButtons: StandardButton.Ok
|
|
|
|
onVisibilityChanged: {
|
|
|
|
loading = false
|
|
|
|
}
|
2020-06-12 20:47:44 +00:00
|
|
|
}
|
|
|
|
|
2020-06-22 19:32:00 +00:00
|
|
|
MessageDialog {
|
|
|
|
id: importLoginError
|
2022-04-04 11:26:30 +00:00
|
|
|
title: qsTr("Login failed")
|
|
|
|
text: qsTr("Login failed. Please re-enter your password and try again.")
|
2020-06-22 19:32:00 +00:00
|
|
|
icon: StandardIcon.Critical
|
|
|
|
standardButtons: StandardButton.Ok
|
|
|
|
onVisibilityChanged: {
|
2020-06-12 20:47:44 +00:00
|
|
|
loading = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-14 08:04:15 +00:00
|
|
|
Connections {
|
2022-03-07 22:59:38 +00:00
|
|
|
target: OnboardingStore.onboardingModuleInst
|
2021-10-14 08:04:15 +00:00
|
|
|
onAccountSetupError: {
|
|
|
|
importLoginError.open()
|
|
|
|
}
|
|
|
|
}
|
2020-06-22 19:32:00 +00:00
|
|
|
|
2020-06-23 19:31:35 +00:00
|
|
|
onClicked: {
|
2021-09-13 11:51:47 +00:00
|
|
|
if (storingPasswordModal)
|
|
|
|
{
|
2022-02-24 12:18:21 +00:00
|
|
|
// validate the entered password
|
|
|
|
var validatePassword = privacyStore.validatePassword(repeatPasswordField.text)
|
|
|
|
if(!validatePassword) {
|
|
|
|
firstPasswordFieldValid = false
|
|
|
|
passwordValidationError = qsTr("Incorrect password")
|
|
|
|
}
|
|
|
|
else {
|
2022-04-11 11:39:15 +00:00
|
|
|
popup.offerToStorePassword(repeatPasswordField.text, true)
|
2022-02-24 12:18:21 +00:00
|
|
|
popup.close()
|
|
|
|
}
|
2021-09-13 11:51:47 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
loading = true
|
2022-03-07 22:59:38 +00:00
|
|
|
OnboardingStore.onboardingModuleInst.storeSelectedAccountAndLogin(repeatPasswordField.text);
|
2022-04-11 11:39:15 +00:00
|
|
|
popup.offerToStorePassword(repeatPasswordField.text, false)
|
2020-06-22 19:32:00 +00:00
|
|
|
}
|
2020-06-12 20:47:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|