Files
amnezia-client/client/ui/qml/Pages2/PageSetupWizardCredentials.qml
T

242 lines
7.7 KiB
QML
Raw Normal View History

import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import PageEnum 1.0
import Style 1.0
import "./"
import "../Controls2"
import "../Config"
import "../Controls2/TextTypes"
PageType {
id: root
2023-06-05 15:49:10 +08:00
BackButtonType {
id: backButton
anchors.top: parent.top
anchors.left: parent.left
anchors.right: parent.right
anchors.topMargin: 20 + PageController.safeAreaTopMargin
2024-04-18 17:54:55 +04:00
2024-12-31 04:16:52 +01:00
onFocusChanged: {
if (this.activeFocus) {
listView.positionViewAtBeginning()
}
}
2023-06-05 15:49:10 +08:00
}
ListViewType {
2024-12-31 04:16:52 +01:00
id: listView
2023-06-05 15:49:10 +08:00
anchors.top: backButton.bottom
anchors.bottom: parent.bottom
2024-12-31 04:16:52 +01:00
anchors.right: parent.right
anchors.left: parent.left
header: ColumnLayout {
width: listView.width
2025-05-02 23:54:36 -07:00
BaseHeaderType {
Layout.fillWidth: true
2024-12-31 04:16:52 +01:00
Layout.leftMargin: 16
Layout.rightMargin: 16
Layout.bottomMargin: 16
2023-10-14 15:55:07 +01:00
headerText: qsTr("Configure your server")
}
2024-12-31 04:16:52 +01:00
}
2024-12-31 04:16:52 +01:00
model: inputFields
spacing: 16
2024-12-31 04:16:52 +01:00
delegate: ColumnLayout {
width: listView.width
TextFieldWithHeaderType {
id: delegate
Layout.fillWidth: true
2024-12-31 04:16:52 +01:00
Layout.leftMargin: 16
Layout.rightMargin: 16
2024-03-14 15:59:16 +05:00
2024-12-31 04:16:52 +01:00
headerText: title
textField.echoMode: hideContent ? TextInput.Password : TextInput.Normal
textField.placeholderText: placeholderContent
textField.text: textField.text
2024-12-31 04:16:52 +01:00
rightButtonClickedOnEnter: true
2024-12-31 04:16:52 +01:00
clickedFunc: function () {
clickedHandler()
2025-11-28 05:00:53 +02:00
buttonImageSource = textField.text !== "" ? imageSource : ""
}
2024-03-14 15:59:16 +05:00
textField.onFocusChanged: {
textField.text = textField.text.replace(/^\s+|\s+$/g, '')
}
2024-12-31 04:16:52 +01:00
textField.onTextChanged: {
2026-03-24 12:06:40 +04:00
if (headerText === qsTr("Password or SSH private key")) {
2025-11-28 05:00:53 +02:00
buttonImageSource = textField.text !== "" ? imageSource : ""
2024-12-31 04:16:52 +01:00
}
}
}
2026-03-24 12:06:40 +04:00
WarningType {
Layout.fillWidth: true
Layout.leftMargin: 16
Layout.rightMargin: 16
Layout.topMargin: 8
visible: title === qsTr("Password or SSH private key")
backGroundColor: AmneziaStyle.color.translucentWhite
iconPath: "qrc:/images/controls/alert-circle.svg"
2026-04-10 21:24:00 +07:00
textString: qsTr("SSH key requirements: supported key types are ED25519 and RSA in PEM format. Paste the private key, including the BEGIN/END lines. If your key doesnt work, generate a compatible one")
2026-03-24 12:06:40 +04:00
}
2024-12-31 04:16:52 +01:00
}
footer: ColumnLayout {
width: listView.width
BasicButtonType {
id: continueButton
Layout.fillWidth: true
2024-12-31 04:16:52 +01:00
Layout.topMargin: 32
Layout.leftMargin: 16
Layout.rightMargin: 16
text: qsTr("Continue")
clickedFunc: function() {
2024-12-31 04:16:52 +01:00
if (!root.isCredentialsFilled()) {
return
}
var _hostname = listView.itemAtIndex(vars.hostnameIndex).children[0].textField.text
var _username = listView.itemAtIndex(vars.usernameIndex).children[0].textField.text
var _secretData = listView.itemAtIndex(vars.secretDataIndex).children[0].textField.text
2024-12-31 04:16:52 +01:00
InstallController.setProcessedServerCredentials(_hostname, _username, _secretData)
2026-05-28 10:57:08 +08:00
ServersUiController.setProcessedServerId("")
PageController.showBusyIndicator(true)
var isConnectionOpened = InstallController.checkSshConnection()
PageController.showBusyIndicator(false)
if (!isConnectionOpened) {
return
}
2023-09-06 13:37:37 +05:00
PageController.goToPage(PageEnum.PageSetupWizardEasy)
}
}
2023-10-14 15:55:07 +01:00
LabelTextType {
Layout.fillWidth: true
2024-12-31 04:16:52 +01:00
Layout.topMargin: 24
Layout.leftMargin: 16
Layout.rightMargin: 16
Layout.bottomMargin: 16
2023-10-14 15:55:07 +01:00
text: qsTr("All data you enter will remain strictly confidential and will not be shared or disclosed to the Amnezia or any third parties")
2023-10-14 15:55:07 +01:00
}
CardWithIconsType {
id: siteLink
Layout.fillWidth: true
2024-12-31 04:16:52 +01:00
Layout.leftMargin: 16
Layout.rightMargin: 16
Layout.bottomMargin: 16
headerText: qsTr("How to run your VPN server")
bodyText: qsTr("Where to get connection data, step-by-step instructions for buying a VPS")
rightImageSource: "qrc:/images/controls/chevron-right.svg"
leftImageSource: "qrc:/images/controls/help-circle.svg"
onClicked: {
Qt.openUrlExternally(LanguageUiController.getCurrentSiteUrl("starter-guide"))
}
Keys.onEnterPressed: this.clicked()
Keys.onReturnPressed: this.clicked()
}
}
}
function isCredentialsFilled() {
var hasEmptyField = false
var hostnameItem = listView.itemAtIndex(vars.hostnameIndex).children[0]
if (hostnameItem.textField.text === "") {
hostnameItem.errorText = qsTr("Ip address cannot be empty")
hasEmptyField = true
} else if (!hostnameItem.textField.acceptableInput) {
hostnameItem.errorText = qsTr("Enter the address in the format 255.255.255.255:88")
}
var usernameItem = listView.itemAtIndex(vars.usernameIndex).children[0]
if (usernameItem.textField.text === "") {
usernameItem.errorText = qsTr("Login cannot be empty")
hasEmptyField = true
}
2024-12-31 04:16:52 +01:00
var secretDataItem = listView.itemAtIndex(vars.secretDataIndex).children[0]
if (secretDataItem.textField.text === "") {
secretDataItem.errorText = qsTr("Password/private key cannot be empty")
hasEmptyField = true
}
2024-12-31 04:16:52 +01:00
return !hasEmptyField
}
2024-12-31 04:16:52 +01:00
property list<QtObject> inputFields: [
hostnameObject,
usernameObject,
secretDataObject
2024-12-31 04:16:52 +01:00
]
QtObject {
id: hostnameObject
2024-12-31 04:16:52 +01:00
property string title: qsTr("Server IP address [:port]")
readonly property string placeholderContent: qsTr("255.255.255.255:22")
property bool hideContent: false
readonly property var clickedHandler: undefined
2024-12-31 04:16:52 +01:00
}
QtObject {
id: usernameObject
2024-12-31 04:16:52 +01:00
property string title: qsTr("SSH Username")
readonly property string placeholderContent: "root"
property bool hideContent: false
2024-12-31 04:16:52 +01:00
readonly property var clickedHandler: undefined
}
QtObject {
id: secretDataObject
2024-12-31 04:16:52 +01:00
property string title: qsTr("Password or SSH private key")
readonly property string placeholderContent: ""
property bool hideContent: true
2025-11-28 05:00:53 +02:00
property string imageSource: "qrc:/images/controls/eye.svg"
2024-12-31 04:16:52 +01:00
readonly property var clickedHandler: function() {
hideContent = !hideContent
2025-11-28 05:00:53 +02:00
imageSource = hideContent ? "qrc:/images/controls/eye.svg" : "qrc:/images/controls/eye-off.svg"
2024-12-31 04:16:52 +01:00
}
}
QtObject {
id: vars
readonly property int hostnameIndex: 0
readonly property int usernameIndex: 1
readonly property int secretDataIndex: 2
}
}