status-desktop/ui/app/AppLayouts/Onboarding/shared/CreatePasswordModal.qml

143 lines
4.6 KiB
QML
Raw Normal View History

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
import StatusQ.Controls 0.1
import utils 1.0
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
import "../stores"
// TODO: replace with StatusModal
2020-06-12 20:47:44 +00:00
ModalPopup {
property var privacyStore
2020-06-12 20:47:44 +00:00
property bool loading: false
property bool firstPasswordFieldValid: false
property bool repeatPasswordFieldValid: false
property string passwordValidationError: ""
property string repeatPasswordValidationError: ""
signal offerToStorePassword(string password, bool runStoreToKeychainPopup)
2020-06-12 20:47:44 +00:00
id: popup
title: qsTr("Store password")
2020-06-12 20:47:44 +00:00
height: 500
onOpened: {
firstPasswordField.text = "";
firstPasswordField.forceActiveFocus(Qt.MouseFocusReason)
}
2020-06-12 20:47:44 +00:00
Input {
id: firstPasswordField
anchors.rightMargin: 56
anchors.leftMargin: 56
anchors.top: parent.top
anchors.topMargin: Style.current.xlPadding
placeholderText: qsTr("Current password...")
2020-06-12 20:47:44 +00:00
textField.echoMode: TextInput.Password
onTextChanged: {
[firstPasswordFieldValid, passwordValidationError] =
2020-12-04 14:53:00 +00:00
Utils.validatePasswords("first", firstPasswordField, repeatPasswordField);
[repeatPasswordFieldValid, repeatPasswordValidationError] =
Utils.validatePasswords("repeat", firstPasswordField, repeatPasswordField);
}
2020-06-12 20:47:44 +00:00
}
Input {
id: repeatPasswordField
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
anchors.topMargin: Style.current.xlPadding
placeholderText: qsTr("Confirm password…")
2020-06-12 20:47:44 +00:00
textField.echoMode: TextInput.Password
Keys.onReturnPressed: function(event) {
if (submitBtn.enabled) {
submitBtn.clicked(event)
}
2020-06-12 20:47:44 +00:00
}
onTextChanged: {
[repeatPasswordFieldValid, repeatPasswordValidationError] =
2020-12-04 14:53:00 +00:00
Utils.validatePasswords("repeat", firstPasswordField, repeatPasswordField);
}
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-22 19:32:00 +00:00
footer: Item {
width: parent.width
height: submitBtn.height
2020-06-12 20:47:44 +00:00
StatusButton {
2020-06-22 19:32:00 +00:00
id: submitBtn
anchors.bottom: parent.bottom
anchors.topMargin: Style.current.padding
2020-06-22 19:32:00 +00:00
anchors.right: parent.right
state: loading ? "pending" : "default"
text: qsTr("Store password")
2020-06-12 20:47:44 +00:00
enabled: firstPasswordFieldValid && repeatPasswordFieldValid && !loading
2020-06-22 19:32:00 +00:00
MessageDialog {
id: importError
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
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
}
}
onClicked: {
// 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()
2020-06-22 19:32:00 +00:00
}
2020-06-12 20:47:44 +00:00
}
}
}
}