2021-08-11 09:55:59 +00:00
|
|
|
import QtQuick 2.13
|
|
|
|
import QtQuick.Controls 2.13
|
|
|
|
import QtQuick.Layouts 1.12
|
2021-09-09 14:04:05 +00:00
|
|
|
|
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.controls 1.0
|
2021-08-11 09:55:59 +00:00
|
|
|
|
2021-09-09 14:04:05 +00:00
|
|
|
import StatusQ.Popups 0.1
|
|
|
|
import StatusQ.Controls 0.1
|
|
|
|
|
|
|
|
StatusModal {
|
2022-01-10 23:30:39 +00:00
|
|
|
id: root
|
|
|
|
|
|
|
|
signal passwordChanged()
|
|
|
|
|
2021-09-09 14:04:05 +00:00
|
|
|
width: 480
|
2021-08-11 09:55:59 +00:00
|
|
|
height: 510
|
2021-09-09 14:04:05 +00:00
|
|
|
closePolicy: Popup.NoAutoClose
|
|
|
|
header.title: qsTr("Change password")
|
2021-08-11 09:55:59 +00:00
|
|
|
|
2022-01-10 23:30:39 +00:00
|
|
|
onOpened: d.reset()
|
|
|
|
|
|
|
|
QtObject {
|
|
|
|
id: d
|
|
|
|
|
|
|
|
function lengthValidator(text) {
|
|
|
|
return text.length >= 6 ? "" : qsTr("At least 6 characters")
|
|
|
|
}
|
2021-08-11 09:55:59 +00:00
|
|
|
|
2022-01-10 23:30:39 +00:00
|
|
|
function reset() {
|
|
|
|
currentPasswordInput.state = "init"
|
|
|
|
passwordInput.state = "init"
|
|
|
|
confirmPasswordInput.state = "init"
|
|
|
|
currentPasswordInput.forceActiveFocus(Qt.MouseFocusReason)
|
|
|
|
}
|
2021-08-11 09:55:59 +00:00
|
|
|
}
|
|
|
|
|
2021-09-09 14:04:05 +00:00
|
|
|
contentItem: ColumnLayout {
|
|
|
|
id: contentItem
|
2021-08-11 09:55:59 +00:00
|
|
|
anchors.fill: parent
|
2021-09-09 14:04:05 +00:00
|
|
|
anchors {
|
2022-01-10 23:30:39 +00:00
|
|
|
topMargin: Style.current.xlPadding + root.topPadding
|
2021-09-09 14:04:05 +00:00
|
|
|
leftMargin: Style.current.xlPadding
|
|
|
|
rightMargin: Style.current.xlPadding
|
2022-01-10 23:30:39 +00:00
|
|
|
bottomMargin: Style.current.xlPadding + root.bottomPadding
|
2021-09-09 14:04:05 +00:00
|
|
|
}
|
|
|
|
spacing: Style.current.padding
|
2021-08-11 09:55:59 +00:00
|
|
|
|
2022-01-10 23:30:39 +00:00
|
|
|
// TODO replace with StatusInput as soon as it supports password
|
2021-08-11 09:55:59 +00:00
|
|
|
Input {
|
2021-09-09 14:04:05 +00:00
|
|
|
id: currentPasswordInput
|
2022-01-10 23:30:39 +00:00
|
|
|
|
|
|
|
readonly property bool ready: state == "typing" && validationError == ""
|
|
|
|
|
2021-08-11 09:55:59 +00:00
|
|
|
anchors.left: undefined
|
|
|
|
anchors.right: undefined
|
|
|
|
Layout.fillWidth: true
|
2021-09-09 14:04:05 +00:00
|
|
|
label: qsTr("Current password")
|
2022-01-10 23:30:39 +00:00
|
|
|
|
2021-08-11 09:55:59 +00:00
|
|
|
textField.echoMode: TextInput.Password
|
2022-01-10 23:30:39 +00:00
|
|
|
keepHeight: true
|
|
|
|
placeholderText: ""
|
|
|
|
state: "init"
|
|
|
|
|
|
|
|
onTextChanged: if (text != "" && state != "typing") state = "typing"
|
|
|
|
onStateChanged: if (state == "init") resetInternal()
|
|
|
|
|
|
|
|
states: [
|
|
|
|
State {
|
|
|
|
name: "init"
|
|
|
|
},
|
|
|
|
State {
|
|
|
|
name: "typing"
|
|
|
|
PropertyChanges { target: currentPasswordInput; validationError: d.lengthValidator(text) }
|
|
|
|
},
|
|
|
|
State {
|
|
|
|
name: "incorrect"
|
|
|
|
PropertyChanges { target: currentPasswordInput; validationError: qsTr("Incorrect password") }
|
|
|
|
}
|
|
|
|
]
|
2021-08-11 09:55:59 +00:00
|
|
|
}
|
|
|
|
|
2022-01-10 23:30:39 +00:00
|
|
|
// TODO replace with StatusInput as soon as it supports password
|
2021-08-11 09:55:59 +00:00
|
|
|
Input {
|
2021-09-09 14:04:05 +00:00
|
|
|
id: passwordInput
|
2022-01-10 23:30:39 +00:00
|
|
|
|
|
|
|
readonly property bool ready: state == "typing" && validationError == ""
|
|
|
|
|
2021-08-11 09:55:59 +00:00
|
|
|
anchors.left: undefined
|
|
|
|
anchors.right: undefined
|
|
|
|
Layout.fillWidth: true
|
2022-01-10 23:30:39 +00:00
|
|
|
label: qsTr("New password")
|
|
|
|
|
|
|
|
textField.echoMode: TextInput.Password
|
|
|
|
keepHeight: true
|
2021-09-09 14:04:05 +00:00
|
|
|
placeholderText: ""
|
2022-01-10 23:30:39 +00:00
|
|
|
state: "init"
|
|
|
|
|
|
|
|
onTextChanged: if (text != "" && state != "typing") state = "typing"
|
|
|
|
onStateChanged: if (state == "init") resetInternal()
|
|
|
|
|
|
|
|
states: [
|
|
|
|
State {
|
|
|
|
name: "init"
|
|
|
|
},
|
|
|
|
State {
|
|
|
|
name: "typing"
|
|
|
|
PropertyChanges { target: passwordInput; validationError: d.lengthValidator(text) }
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO replace with StatusInput as soon as it supports password
|
|
|
|
Input {
|
|
|
|
id: confirmPasswordInput
|
|
|
|
|
|
|
|
readonly property bool ready: state == "typing" && validationError == ""
|
|
|
|
|
|
|
|
anchors.left: undefined
|
|
|
|
anchors.right: undefined
|
|
|
|
Layout.fillWidth: true
|
|
|
|
label: qsTr("Confirm new password")
|
|
|
|
|
2021-08-11 09:55:59 +00:00
|
|
|
textField.echoMode: TextInput.Password
|
2022-01-10 23:30:39 +00:00
|
|
|
keepHeight: true
|
|
|
|
placeholderText: ""
|
|
|
|
state: "init"
|
|
|
|
|
|
|
|
onTextChanged: if (text != "" && state != "typing") state = "typing"
|
|
|
|
onStateChanged: if (state == "init") resetInternal()
|
|
|
|
|
|
|
|
states: [
|
|
|
|
State {
|
|
|
|
name: "init"
|
|
|
|
},
|
|
|
|
State {
|
|
|
|
name: "typing"
|
|
|
|
PropertyChanges {
|
|
|
|
target: confirmPasswordInput;
|
|
|
|
validationError: confirmPasswordInput.text != passwordInput.text ? qsTr("Password does not match") : ""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
2021-08-11 09:55:59 +00:00
|
|
|
}
|
|
|
|
|
2021-09-09 14:04:05 +00:00
|
|
|
Item {
|
|
|
|
Layout.fillHeight: true
|
2021-08-11 09:55:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
StyledText {
|
2022-01-10 23:30:39 +00:00
|
|
|
text: qsTr("Your password protects your keys. You need it to unlock Status and transact.")
|
2021-08-11 09:55:59 +00:00
|
|
|
wrapMode: Text.WordWrap
|
|
|
|
Layout.preferredWidth: 340
|
|
|
|
Layout.alignment: Qt.AlignHCenter
|
|
|
|
horizontalAlignment: Text.AlignHCenter
|
|
|
|
color: Style.current.secondaryText
|
2021-08-12 12:09:57 +00:00
|
|
|
font.pixelSize: Style.current.tertiaryTextFontSize
|
2021-08-11 09:55:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-09 14:04:05 +00:00
|
|
|
rightButtons: [
|
2021-08-11 09:55:59 +00:00
|
|
|
StatusButton {
|
|
|
|
id: submitBtn
|
2022-01-10 23:30:39 +00:00
|
|
|
|
2021-08-11 09:55:59 +00:00
|
|
|
text: qsTr("Change password")
|
2022-01-10 23:30:39 +00:00
|
|
|
enabled: !submitBtn.loading && currentPasswordInput.ready &&
|
|
|
|
passwordInput.ready && confirmPasswordInput.ready
|
2021-09-09 14:04:05 +00:00
|
|
|
|
|
|
|
property Timer sim: Timer {
|
|
|
|
id: pause
|
|
|
|
interval: 20
|
|
|
|
onTriggered: {
|
|
|
|
submitBtn.changePasswordBegin();
|
|
|
|
}
|
|
|
|
}
|
2021-08-11 09:55:59 +00:00
|
|
|
|
|
|
|
onClicked: {
|
2021-09-09 14:04:05 +00:00
|
|
|
submitBtn.loading = true;
|
|
|
|
//changePassword operation blocks the UI so loading = true; will never
|
|
|
|
//have any affect until changePassword is done. Getting around it with a
|
|
|
|
//small pause (timer) in order to get the desired behavior
|
|
|
|
pause.start();
|
|
|
|
}
|
|
|
|
|
|
|
|
function changePasswordBegin() {
|
2021-10-22 18:26:11 +00:00
|
|
|
if (privacyModule.changePassword(currentPasswordInput.text, passwordInput.text)) {
|
2022-01-10 23:30:39 +00:00
|
|
|
passwordChanged()
|
2021-09-09 14:04:05 +00:00
|
|
|
submitBtn.enabled = false;
|
2021-08-12 11:13:26 +00:00
|
|
|
} else {
|
2022-01-10 23:30:39 +00:00
|
|
|
currentPasswordInput.state = "incorrect"
|
|
|
|
currentPasswordInput.forceActiveFocus(Qt.MouseFocusReason)
|
2021-08-12 11:13:26 +00:00
|
|
|
}
|
2021-09-09 14:04:05 +00:00
|
|
|
submitBtn.loading = false;
|
2021-08-11 09:55:59 +00:00
|
|
|
}
|
|
|
|
}
|
2021-09-09 14:04:05 +00:00
|
|
|
]
|
2021-08-11 09:55:59 +00:00
|
|
|
}
|