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-08-11 09:55:59 +00:00
|
|
|
import "../../../../shared"
|
2021-10-14 11:07:19 +00:00
|
|
|
import "../../../../shared/controls"
|
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 {
|
2021-08-11 09:55:59 +00:00
|
|
|
id: popup
|
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
|
|
|
|
|
|
|
onOpened: {
|
2021-09-09 14:04:05 +00:00
|
|
|
reset();
|
2021-08-11 09:55:59 +00:00
|
|
|
}
|
|
|
|
|
2021-09-09 14:04:05 +00:00
|
|
|
property var successPopup
|
|
|
|
property string indicationText: ""
|
|
|
|
property bool passwordInputValid
|
|
|
|
property bool currPasswordInputValid
|
|
|
|
property string currPasswordValidationError: ""
|
2021-08-11 09:55:59 +00:00
|
|
|
|
|
|
|
function reset() {
|
2021-09-09 14:04:05 +00:00
|
|
|
passwordInput.text = "";
|
|
|
|
currentPasswordInput.text = "";
|
|
|
|
currentPasswordInput.forceActiveFocus(Qt.MouseFocusReason);
|
|
|
|
popup.indicationText = "At least 6 characters. Your password protects your keys. You need it to unlock Status and transact.";
|
|
|
|
popup.currPasswordValidationError = "";
|
|
|
|
passwordInput.validationError = "";
|
|
|
|
popup.passwordInputValid = false;
|
|
|
|
popup.currPasswordInputValid = false;
|
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 {
|
|
|
|
topMargin: (Style.current.xlPadding + popup.topPadding)
|
|
|
|
leftMargin: Style.current.xlPadding
|
|
|
|
rightMargin: Style.current.xlPadding
|
|
|
|
bottomMargin: (Style.current.xlPadding + popup.bottomPadding)
|
|
|
|
}
|
|
|
|
spacing: Style.current.padding
|
2021-08-11 09:55:59 +00:00
|
|
|
|
2021-09-09 14:04:05 +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
|
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
|
|
|
placeholderText: ""
|
|
|
|
label: qsTr("Current password")
|
2021-08-11 09:55:59 +00:00
|
|
|
textField.echoMode: TextInput.Password
|
|
|
|
onTextChanged: {
|
2021-09-09 14:04:05 +00:00
|
|
|
popup.currPasswordInputValid = (currentPasswordInput.text.length >= 6);
|
2021-08-11 09:55:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-09 14:04:05 +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
|
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
|
|
|
placeholderText: ""
|
|
|
|
label: qsTrId("new-password...")
|
2021-08-11 09:55:59 +00:00
|
|
|
textField.echoMode: TextInput.Password
|
|
|
|
onTextChanged: {
|
2021-09-09 14:04:05 +00:00
|
|
|
popup.passwordInputValid = ((passwordInput.text !== "") && (passwordInput.text.length >= 6));
|
|
|
|
//setting validationError so that input becomes red
|
|
|
|
passwordInput.validationError = (!popup.passwordInputValid) ? " " : "";
|
|
|
|
popup.indicationText = (!popup.passwordInputValid ? "<font color=\"#FF2D55\">" : "")
|
|
|
|
+ "At least 6 characters." + (!popup.passwordInputValid ? "</font>" : "")
|
|
|
|
+ "Your password protects your keys. You need it to unlock Status and transact."
|
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 {
|
|
|
|
id: validationError
|
2021-09-09 14:04:05 +00:00
|
|
|
Layout.preferredWidth: parent.width
|
2021-08-11 09:55:59 +00:00
|
|
|
Layout.alignment: Qt.AlignHCenter
|
|
|
|
horizontalAlignment: Text.AlignHCenter
|
2021-09-09 14:04:05 +00:00
|
|
|
visible: (text !== "")
|
2021-08-12 12:09:57 +00:00
|
|
|
font.pixelSize: Style.current.tertiaryTextFontSize
|
2021-09-09 14:04:05 +00:00
|
|
|
color: Style.current.danger
|
|
|
|
text: popup.currPasswordValidationError
|
2021-08-11 09:55:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
StyledText {
|
2021-09-09 14:04:05 +00:00
|
|
|
text: qsTr(indicationText)
|
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
|
|
|
|
text: qsTr("Change password")
|
2021-09-09 14:04:05 +00:00
|
|
|
enabled: (popup.passwordInputValid && popup.currPasswordInputValid && !submitBtn.loading)
|
|
|
|
|
|
|
|
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() {
|
|
|
|
if (profileModel.changePassword(currentPasswordInput.text, passwordInput.text)) {
|
|
|
|
popup.successPopup.open();
|
|
|
|
submitBtn.enabled = false;
|
2021-08-12 11:13:26 +00:00
|
|
|
} else {
|
2021-09-09 14:04:05 +00:00
|
|
|
reset();
|
|
|
|
passwordInput.validationError = " ";
|
|
|
|
popup.currPasswordValidationError = qsTr("Incorrect password");
|
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
|
|
|
}
|