status-desktop/ui/app/AppLayouts/Profile/Sections/ChangePasswordModal.qml

133 lines
4.3 KiB
QML
Raw Normal View History

2021-08-11 09:55:59 +00:00
import QtQuick 2.13
import QtQuick.Controls 2.13
import QtQuick.Layouts 1.12
import StatusQ.Controls 0.1
import "../../../../imports"
import "../../../../shared"
ModalPopup {
id: popup
title: qsTr("Change password")
height: 510
onOpened: {
reset()
}
property bool loading: false
property bool firstPasswordFieldValid: false
property bool repeatPasswordFieldValid: false
property string passwordValidationError: ""
property string repeatPasswordValidationError: ""
property string changePasswordError: ""
function reset() {
currentPasswordField.text = ""
firstPasswordField.text = ""
repeatPasswordField.text = ""
currentPasswordField.forceActiveFocus(Qt.MouseFocusReason)
firstPasswordFieldValid = false
repeatPasswordFieldValid = false
passwordValidationError = ""
repeatPasswordValidationError = ""
changePasswordError = ""
loading = false
}
ColumnLayout {
anchors.fill: parent
2021-08-12 12:09:57 +00:00
anchors.margins: Style.current.xlPadding
2021-08-11 09:55:59 +00:00
spacing: Style.current.xlPadding
Input {
id: currentPasswordField
anchors.left: undefined
anchors.right: undefined
Layout.fillWidth: true
placeholderText: qsTr("Current password")
textField.echoMode: TextInput.Password
onTextChanged: {
changePasswordError = ""
}
}
Input {
id: firstPasswordField
anchors.left: undefined
anchors.right: undefined
Layout.fillWidth: true
//% "New password..."
placeholderText: qsTrId("new-password...")
textField.echoMode: TextInput.Password
onTextChanged: {
[firstPasswordFieldValid, passwordValidationError] =
Utils.validatePasswords("first", firstPasswordField, repeatPasswordField);
}
}
Input {
id: repeatPasswordField
anchors.left: undefined
anchors.right: undefined
Layout.fillWidth: true
enabled: firstPasswordFieldValid
//% "Confirm password…"
placeholderText: qsTrId("confirm-password…")
textField.echoMode: TextInput.Password
Keys.onReturnPressed: function(event) {
if (submitBtn.enabled) {
submitBtn.clicked(event)
}
}
onTextChanged: {
[repeatPasswordFieldValid, repeatPasswordValidationError] =
Utils.validatePasswords("repeat", firstPasswordField, repeatPasswordField);
}
}
StyledText {
id: validationError
text: passwordValidationError || repeatPasswordValidationError || changePasswordError
Layout.preferredWidth: 340
Layout.alignment: Qt.AlignHCenter
horizontalAlignment: Text.AlignHCenter
color: Style.current.danger
2021-08-12 12:09:57 +00:00
font.pixelSize: Style.current.tertiaryTextFontSize
2021-08-11 09:55:59 +00:00
}
StyledText {
text: qsTr("Status app will be terminated after password change. You need to restart it to login using the new password.")
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
}
}
footer: Item {
width: parent.width
height: submitBtn.height
StatusButton {
id: submitBtn
anchors.right: parent.right
text: qsTr("Change password")
enabled: popup.firstPasswordFieldValid && popup.repeatPasswordFieldValid && !popup.loading
state: popup.loading ? "pending" : "default"
onClicked: {
popup.loading = true
2021-08-12 11:13:26 +00:00
if (profileModel.changePassword(currentPasswordField.text, firstPasswordField.text)) {
popup.close()
} else {
reset()
changePasswordError = qsTr("Failed to change password.")
}
2021-08-11 09:55:59 +00:00
}
}
}
}