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
|
2022-09-26 11:57:32 +00:00
|
|
|
import StatusQ.Controls.Validators 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: ""
|
|
|
|
|
2022-04-11 11:39:15 +00:00
|
|
|
signal offerToStorePassword(string password, bool runStoreToKeychainPopup)
|
|
|
|
|
2020-06-12 20:47:44 +00:00
|
|
|
id: popup
|
2022-07-20 12:34:59 +00:00
|
|
|
title: qsTr("Store password")
|
2020-06-12 20:47:44 +00:00
|
|
|
height: 500
|
|
|
|
|
|
|
|
onOpened: {
|
2022-09-26 11:57:32 +00:00
|
|
|
if (userProfile.isKeycardUser) {
|
|
|
|
firstPinInputField.statesInitialization()
|
|
|
|
firstPinInputField.forceFocus()
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
firstPasswordField.text = "";
|
|
|
|
firstPasswordField.forceActiveFocus(Qt.MouseFocusReason)
|
|
|
|
}
|
2020-06-12 20:47:44 +00:00
|
|
|
}
|
2020-06-30 20:01:37 +00:00
|
|
|
|
2022-09-26 11:57:32 +00:00
|
|
|
Column {
|
|
|
|
anchors.fill: parent
|
|
|
|
leftPadding: d.padding
|
|
|
|
rightPadding: d.padding
|
|
|
|
topPadding: Style.current.xlPadding
|
|
|
|
bottomPadding: Style.current.xlPadding
|
|
|
|
spacing: Style.current.xlPadding
|
|
|
|
|
|
|
|
QtObject {
|
|
|
|
id: d
|
|
|
|
|
|
|
|
readonly property int padding: 56
|
|
|
|
readonly property int fontSize: 15
|
2020-12-03 22:26:05 +00:00
|
|
|
}
|
2020-06-12 20:47:44 +00:00
|
|
|
|
2022-09-26 11:57:32 +00:00
|
|
|
Input {
|
|
|
|
id: firstPasswordField
|
|
|
|
width: parent.width - 2 * d.padding
|
|
|
|
visible: !userProfile.isKeycardUser
|
|
|
|
placeholderText: qsTr("Current password...")
|
|
|
|
textField.echoMode: TextInput.Password
|
|
|
|
onTextChanged: {
|
|
|
|
[firstPasswordFieldValid, passwordValidationError] =
|
|
|
|
Utils.validatePasswords("first", firstPasswordField, repeatPasswordField);
|
|
|
|
[repeatPasswordFieldValid, repeatPasswordValidationError] =
|
|
|
|
Utils.validatePasswords("repeat", firstPasswordField, repeatPasswordField);
|
2021-09-08 13:28:23 +00:00
|
|
|
}
|
2020-06-12 20:47:44 +00:00
|
|
|
}
|
2022-09-26 11:57:32 +00:00
|
|
|
|
|
|
|
Input {
|
|
|
|
id: repeatPasswordField
|
|
|
|
visible: !userProfile.isKeycardUser
|
|
|
|
width: parent.width - 2 * d.padding
|
|
|
|
enabled: firstPasswordFieldValid
|
|
|
|
placeholderText: qsTr("Confirm password…")
|
|
|
|
textField.echoMode: TextInput.Password
|
|
|
|
Keys.onReturnPressed: function(event) {
|
|
|
|
if (submitBtn.enabled) {
|
|
|
|
submitBtn.clicked(event)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
onTextChanged: {
|
|
|
|
[repeatPasswordFieldValid, repeatPasswordValidationError] =
|
|
|
|
Utils.validatePasswords("repeat", firstPasswordField, repeatPasswordField);
|
|
|
|
}
|
2020-12-03 22:26:05 +00:00
|
|
|
}
|
2020-06-12 20:47:44 +00:00
|
|
|
|
2022-09-26 11:57:32 +00:00
|
|
|
StyledText {
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
visible: userProfile.isKeycardUser
|
|
|
|
text: qsTr("Enter new PIN")
|
|
|
|
font.pixelSize: d.fontSize
|
|
|
|
}
|
|
|
|
|
|
|
|
StatusPinInput {
|
|
|
|
id: firstPinInputField
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
visible: userProfile.isKeycardUser
|
|
|
|
validator: StatusIntValidator{bottom: 0; top: 999999;}
|
|
|
|
pinLen: Constants.keycard.general.keycardPinLength
|
|
|
|
|
|
|
|
onPinInputChanged: {
|
|
|
|
if (pinInput.length == Constants.keycard.general.keycardPinLength) {
|
|
|
|
repeatPinInputField.statesInitialization()
|
|
|
|
repeatPinInputField.forceFocus()
|
|
|
|
}
|
|
|
|
|
|
|
|
[firstPasswordFieldValid, passwordValidationError] =
|
|
|
|
Utils.validatePINs("first", firstPinInputField, repeatPinInputField);
|
|
|
|
[repeatPasswordFieldValid, repeatPasswordValidationError] =
|
|
|
|
Utils.validatePINs("repeat", firstPinInputField, repeatPinInputField);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
StyledText {
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
visible: userProfile.isKeycardUser
|
|
|
|
text: qsTr("Repeat PIN")
|
|
|
|
font.pixelSize: d.fontSize
|
|
|
|
}
|
|
|
|
|
|
|
|
StatusPinInput {
|
|
|
|
id: repeatPinInputField
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
visible: userProfile.isKeycardUser
|
|
|
|
validator: StatusIntValidator{bottom: 0; top: 999999;}
|
|
|
|
pinLen: Constants.keycard.general.keycardPinLength
|
|
|
|
|
|
|
|
onPinInputChanged: {
|
|
|
|
[repeatPasswordFieldValid, repeatPasswordValidationError] =
|
|
|
|
Utils.validatePINs("repeat", firstPinInputField, repeatPinInputField);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
StyledText {
|
|
|
|
id: validationError
|
|
|
|
text: {
|
|
|
|
if (passwordValidationError !== "") return passwordValidationError;
|
|
|
|
if (repeatPasswordValidationError !== "") return repeatPasswordValidationError;
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
color: Style.current.danger
|
|
|
|
font.pixelSize: 11
|
2020-12-05 21:00:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2022-09-26 11:57:32 +00:00
|
|
|
text: userProfile.isKeycardUser? qsTr("Store PIN") : qsTr("Store 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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-23 19:31:35 +00:00
|
|
|
onClicked: {
|
2022-09-26 11:57:32 +00:00
|
|
|
if (!userProfile.isKeycardUser) {
|
|
|
|
// validate the entered password
|
|
|
|
var validatePassword = privacyStore.validatePassword(repeatPasswordField.text)
|
|
|
|
if(!validatePassword) {
|
|
|
|
firstPasswordFieldValid = false
|
|
|
|
passwordValidationError = qsTr("Incorrect password")
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
popup.offerToStorePassword(repeatPasswordField.text, true)
|
|
|
|
popup.close()
|
|
|
|
}
|
2021-09-13 11:51:47 +00:00
|
|
|
}
|
2022-07-20 12:34:59 +00:00
|
|
|
else {
|
2022-09-26 11:57:32 +00:00
|
|
|
popup.offerToStorePassword(repeatPinInputField.pinInput, true)
|
2022-07-20 12:34:59 +00:00
|
|
|
popup.close()
|
2020-06-22 19:32:00 +00:00
|
|
|
}
|
2020-06-12 20:47:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|