Merge pull request #1737 from demmm/calamares

[usersq] use validator for login & hostname
This commit is contained in:
Adriaan de Groot 2021-07-05 11:28:48 +02:00 committed by GitHub
commit f1c46d01e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 126 additions and 51 deletions

View File

@ -545,7 +545,7 @@ Config::passwordStatus( const QString& pw1, const QString& pw2 ) const
} }
} }
return qMakePair( PasswordValidity::Valid, QString() ); return qMakePair( PasswordValidity::Valid, tr( "OK!" ) );
} }

View File

@ -11,7 +11,7 @@
import io.calamares.core 1.0 import io.calamares.core 1.0
import io.calamares.ui 1.0 import io.calamares.ui 1.0
import QtQuick 2.10 import QtQuick 2.15
import QtQuick.Controls 2.10 import QtQuick.Controls 2.10
import QtQuick.Layouts 1.3 import QtQuick.Layouts 1.3
import org.kde.kirigami 2.7 as Kirigami import org.kde.kirigami 2.7 as Kirigami
@ -55,14 +55,10 @@ Kirigami.ScrollablePage {
enabled: config.isEditable("fullName") enabled: config.isEditable("fullName")
placeholderText: qsTr("Your Full Name") placeholderText: qsTr("Your Full Name")
text: config.fullName text: config.fullName
onTextChanged: config.setFullName(text); onTextChanged: config.setFullName(text)
background: Rectangle { palette.base: _userNameField.text.length ? "#f0fff0" : "#FBFBFB"
radius: 2 palette.highlight : _userNameField.text.length ? "#dcffdc" : "#FBFBFB"
opacity: 0.9
//border.color: _userNameField.text === "" ? Kirigami.Theme.backgroundColor : ( config.fullNameReady ? Kirigami.Theme.backgroundColor : Kirigami.Theme.negativeTextColor)
color: _userNameField.text.length ? ( config.fullNameChanged ? "#f0fff0" : "#ffdae0") : "#FBFBFB"
}
} }
} }
@ -81,14 +77,20 @@ Kirigami.ScrollablePage {
enabled: config.isEditable("loginName") enabled: config.isEditable("loginName")
placeholderText: qsTr("Login Name") placeholderText: qsTr("Login Name")
text: config.loginName text: config.loginName
//onTextChanged: config.setLoginName(text) validator: RegularExpressionValidator { regularExpression: /[a-z_][a-z0-9_-]*[$]?$/ }
onTextChanged: config.loginNameStatusChanged ? ( config.setLoginName(text),userMessage.visible = false ) : ( userMessage.visible = true )
background: Rectangle { onTextChanged: acceptableInput
opacity: 0.9 ? ( _userLoginField.text === "root"
//border.color: _userLoginField.text === "" ? Kirigami.Theme.backgroundColor : ( config.userNameReady ? Kirigami.Theme.backgroundColor : Kirigami.Theme.negativeTextColor) ? forbiddenMessage.visible=true
color: _userLoginField.text.length ? ( config.loginNameStatusChanged ? "#f0fff0" : "#ffdae0") : "#FBFBFB" : ( config.setLoginName(text),
} userMessage.visible = false,forbiddenMessage.visible=false ) )
: ( userMessage.visible = true,console.log("Invalid") )
palette.base: _userLoginField.text.length
? ( acceptableInput
? ( _userLoginField.text === "root"
? "#ffdae0" : "#f0fff0" ) : "#ffdae0" ) : "#FBFBFB"
palette.highlight : _userLoginField.text.length ? "#dcffdc" : "#FBFBFB"
} }
Label { Label {
@ -105,7 +107,15 @@ Kirigami.ScrollablePage {
Layout.fillWidth: true Layout.fillWidth: true
visible: false visible: false
type: Kirigami.MessageType.Error type: Kirigami.MessageType.Error
text: qsTr("Your username must start with a lowercase letter or underscore.") text: qsTr("Only lowercase letters, numbers, underscore and hyphen are allowed.")
}
Kirigami.InlineMessage {
id: forbiddenMessage
Layout.fillWidth: true
visible: false
type: Kirigami.MessageType.Error
text: qsTr("root is not allowed as username.")
} }
Column { Column {
@ -122,13 +132,21 @@ Kirigami.ScrollablePage {
width: parent.width width: parent.width
placeholderText: qsTr("Computer Name") placeholderText: qsTr("Computer Name")
text: config.hostName text: config.hostName
onTextChanged: config.hostNameStatusChanged ? (config.setHostName(text),hostMessage.visible = false) : hostMessage.visible = true validator: RegularExpressionValidator { regularExpression: /[a-zA-Z0-9][-a-zA-Z0-9_]+/ }
background: Rectangle { onTextChanged: acceptableInput
opacity: 0.9 ? ( _hostName.text === "localhost"
//border.color: _hostName.text === "" ? Kirigami.Theme.backgroundColor : ( config.hostNameStatusChanged ? Kirigami.Theme.backgroundColor : Kirigami.Theme.negativeTextColor) ? forbiddenHost.visible=true
color: _hostName.text.length ? ( config.hostNameStatusChanged ? "#f0fff0" : "#ffdae0") : "#FBFBFB" : ( config.setHostName(text),
} hostMessage.visible = false,forbiddenHost.visible = false ) )
: hostMessage.visible = true
palette.base: _hostName.text.length
? ( acceptableInput
? ( _hostName.text === "localhost" ? "#ffdae0" : "#f0fff0" )
: "#ffdae0")
: "#FBFBFB"
palette.highlight : _hostName.text.length ? "#dcffdc" : "#FBFBFB"
} }
Label { Label {
@ -145,7 +163,15 @@ Kirigami.ScrollablePage {
Layout.fillWidth: true Layout.fillWidth: true
visible: false visible: false
type: Kirigami.MessageType.Error type: Kirigami.MessageType.Error
text: qsTr("Only letter, numbers, underscore and hyphen are allowed.") text: qsTr("Only letter, numbers, underscore and hyphen are allowed, minimal of two characters.")
}
Kirigami.InlineMessage {
id: forbiddenHost
Layout.fillWidth: true
visible: false
type: Kirigami.MessageType.Error
text: qsTr("localhost is not allowed as hostname.")
} }
Column { Column {
@ -168,15 +194,12 @@ Kirigami.ScrollablePage {
text: config.userPassword text: config.userPassword
onTextChanged: config.setUserPassword(text) onTextChanged: config.setUserPassword(text)
palette.base: _passwordField.text.length ? "#f0fff0" : "#FBFBFB"
palette.highlight : _passwordField.text.length ? "#dcffdc" : "#FBFBFB"
echoMode: TextInput.Password echoMode: TextInput.Password
passwordMaskDelay: 300 passwordMaskDelay: 300
inputMethodHints: Qt.ImhNoAutoUppercase inputMethodHints: Qt.ImhNoAutoUppercase
background: Rectangle {
opacity: 0.9
//border.color: _passwordField.text === "" ? Kirigami.Theme.backgroundColor : ( config.passwordReady ? Kirigami.Theme.backgroundColor : Kirigami.Theme.negativeTextColor)
color: _passwordField.text.length ? ( config.userPasswordStatusChanged ? "#f0fff0" : "#ffdae0") : "#FBFBFB"
}
} }
TextField { TextField {
@ -184,17 +207,23 @@ Kirigami.ScrollablePage {
width: parent.width / 2 - 10 width: parent.width / 2 - 10
placeholderText: qsTr("Repeat Password") placeholderText: qsTr("Repeat Password")
text: config.userPasswordSecondary text: config.userPasswordSecondary
onTextChanged: config.setUserPasswordSecondary(text)
onTextChanged: _passwordField.text === _verificationPasswordField.text
? ( config.setUserPasswordSecondary(text),
passMessage.visible = false,
validityMessage.visible = true )
: ( passMessage.visible = true,
validityMessage.visible = false )
palette.base: _verificationPasswordField.text.length
? ( _passwordField.text === _verificationPasswordField.text
? "#f0fff0" : "#ffdae0" )
: "#FBFBFB"
palette.highlight : _verificationPasswordField.text.length ? "#dcffdc" : "#FBFBFB"
echoMode: TextInput.Password echoMode: TextInput.Password
passwordMaskDelay: 300 passwordMaskDelay: 300
inputMethodHints: Qt.ImhNoAutoUppercase inputMethodHints: Qt.ImhNoAutoUppercase
background: Rectangle {
opacity: 0.9
//border.color: _verificationpasswordField.text === "" ? Kirigami.Theme.backgroundColor : ( config.passwordReady ? Kirigami.Theme.backgroundColor : Kirigami.Theme.negativeTextColor)
color: _verificationPasswordField.text.length ? ( config.userPasswordSecondaryChanged ? "#f0fff0" : "#ffdae0") : "#FBFBFB"
}
} }
} }
@ -208,6 +237,27 @@ Kirigami.ScrollablePage {
} }
} }
Kirigami.InlineMessage {
id: passMessage
Layout.fillWidth: true
showCloseButton: true
visible: false
type: Kirigami.MessageType.Error
text: config.userPasswordMessage
}
Kirigami.InlineMessage {
id: validityMessage
Layout.fillWidth: true
showCloseButton: true
visible: false
type: config.userPasswordValidity
? ( config.requireStrongPasswords
? Kirigami.MessageType.Error : Kirigami.MessageType.Warning )
: Kirigami.MessageType.Positive
text: config.userPasswordMessage
}
CheckBox { CheckBox {
id: root id: root
visible: config.writeRootPassword visible: config.writeRootPassword
@ -244,17 +294,15 @@ Kirigami.ScrollablePage {
width: parent.width / 2 -10 width: parent.width / 2 -10
placeholderText: qsTr("Root Password") placeholderText: qsTr("Root Password")
text: config.rootPassword text: config.rootPassword
onTextChanged: config.setRootPassword(text) onTextChanged: config.setRootPassword(text)
palette.base: _rootPasswordField.text.length ? "#f0fff0" : "#FBFBFB"
palette.highlight : _rootPasswordField.text.length ? "#dcffdc" : "#FBFBFB"
echoMode: TextInput.Password echoMode: TextInput.Password
passwordMaskDelay: 300 passwordMaskDelay: 300
inputMethodHints: Qt.ImhNoAutoUppercase inputMethodHints: Qt.ImhNoAutoUppercase
background: Rectangle {
opacity: 0.9
//border.color: _rootPasswordField.text === "" ? Kirigami.Theme.backgroundColor : ( config.rootPasswordReady ? Kirigami.Theme.backgroundColor : Kirigami.Theme.negativeTextColor)
color: _rootPasswordField.text.length ? ( config.rootPasswordReady ? "#f0fff0" : "#ffdae0") : "#FBFBFB"
}
} }
TextField { TextField {
@ -262,17 +310,22 @@ Kirigami.ScrollablePage {
width: parent.width / 2 -10 width: parent.width / 2 -10
placeholderText: qsTr("Repeat Root Password") placeholderText: qsTr("Repeat Root Password")
text: config.rootPasswordSecondary text: config.rootPasswordSecondary
onTextChanged: config.setRootPasswordSecondary(text)
onTextChanged: _rootPasswordField.text === _verificationRootPasswordField.text
? ( config.setRootPasswordSecondary(text),
rootPassMessage.visible = false,
rootValidityMessage.visible = true )
: ( rootPassMessage.visible = true,
rootValidityMessage.visible = false )
palette.base: _verificationRootPasswordField.text.length
? ( _rootPasswordField.text === _verificationRootPasswordField.text
? "#f0fff0" : "#ffdae0") : "#FBFBFB"
palette.highlight : _verificationRootPasswordField.text.length ? "#dcffdc" : "#FBFBFB"
echoMode: TextInput.Password echoMode: TextInput.Password
passwordMaskDelay: 300 passwordMaskDelay: 300
inputMethodHints: Qt.ImhNoAutoUppercase inputMethodHints: Qt.ImhNoAutoUppercase
background: Rectangle {
opacity: 0.9
//border.color: _verificationRootPasswordField.text === "" ? Kirigami.Theme.backgroundColor : ( config.rootPasswordReady ? Kirigami.Theme.backgroundColor : Kirigami.Theme.negativeTextColor)
color: _verificationRootPasswordField.text.length ? ( config.rootPasswordReady ? "#f0fff0" : "#ffdae0") : "#FBFBFB"
}
} }
} }
@ -286,6 +339,27 @@ Kirigami.ScrollablePage {
} }
} }
Kirigami.InlineMessage {
id: rootPassMessage
Layout.fillWidth: true
showCloseButton: true
visible: false
type: Kirigami.MessageType.Error
text: config.rootPasswordMessage
}
Kirigami.InlineMessage {
id: rootValidityMessage
Layout.fillWidth: true
showCloseButton: true
visible: false
type: config.rootPasswordValidity
? ( config.requireStrongPasswords
? Kirigami.MessageType.Error : Kirigami.MessageType.Warning )
: Kirigami.MessageType.Positive
text: config.rootPasswordMessage
}
CheckBox { CheckBox {
Layout.alignment: Qt.AlignCenter Layout.alignment: Qt.AlignCenter
text: qsTr("Log in automatically without asking for the password") text: qsTr("Log in automatically without asking for the password")
@ -298,7 +372,8 @@ Kirigami.ScrollablePage {
Layout.alignment: Qt.AlignCenter Layout.alignment: Qt.AlignCenter
text: qsTr("Validate passwords quality") text: qsTr("Validate passwords quality")
checked: config.requireStrongPasswords checked: config.requireStrongPasswords
onCheckedChanged: config.setRequireStrongPasswords(checked) onCheckedChanged: config.setRequireStrongPasswords(checked),
rootPassMessage.visible = false
} }
Label { Label {