fix(Profile flow) Validate nickname on edit

- align the nickname validation and min/max limits with displayName

Fixes #13591
This commit is contained in:
Lukáš Tinkl 2024-03-12 00:15:19 +01:00 committed by Lukáš Tinkl
parent a6f5f0bc94
commit 5b1f2e8de2
4 changed files with 39 additions and 11 deletions

View File

@ -50,6 +50,10 @@ SplitView {
logs.logEvent("Utils::downloadImageByUrl", ["url", "path"], arguments)
}
function isAlias(name) {
return false
}
Component.onCompleted: {
Utils.globalUtilsInst = this
root.globalUtilsReady = true

View File

@ -10,6 +10,7 @@ import StatusQ.Controls.Validators 0.1
import StatusQ.Popups.Dialog 0.1
import shared.controls 1.0
import utils 1.0
CommonContactDialog {
id: root
@ -28,7 +29,6 @@ CommonContactDialog {
readonly property var d: QtObject {
id: d
readonly property bool editMode: root.nickname !== ""
readonly property int maxNicknameLength: 32
}
StatusInput {
@ -37,16 +37,36 @@ CommonContactDialog {
label: qsTr("Nickname")
input.clearable: true
text: root.nickname
charLimit: d.maxNicknameLength
validationMode: StatusInput.ValidationMode.IgnoreInvalidInput
charLimit: Constants.keypair.nameLengthMax
validators: [
StatusValidator {
validatorObj: RXValidator { regularExpression: /^[\w\d_ -]*$/u }
validatorObj: RXValidator { regularExpression: /^[\w\d_ -\.]*$/u }
validate: (value) => validatorObj.test(value)
errorMessage: qsTr("Invalid characters (use A-Z and 0-9, hyphens and underscores only)")
},
StatusMinLengthValidator {
minLength: Constants.keypair.nameLengthMin
errorMessage: qsTr("Nicknames must be at least %n character(s) long", "", minLength)
},
StatusValidator {
name: "startsWithSpaceValidator"
validate: function (t) { return !(t.startsWith(" ") || t.endsWith(" "))}
errorMessage: qsTr("Nicknames cant start or end with a space")
},
StatusValidator {
name: "endsWith-ethValidator"
validate: function (t) { return !(t.endsWith("-eth") || t.endsWith("_eth") || t.endsWith(".eth")) }
errorMessage: qsTr("Nicknames cant end in “.eth”, “_eth” or “-eth”")
},
StatusValidator {
name: "isAliasValidator"
validate: function (t) { return !Utils.isAlias(t) }
errorMessage: qsTr("Adjective-animal nickname formats are not allowed")
}
]
Keys.onReleased: {
onKeyPressed: {
if (event.key === Qt.Key_Return || event.key === Qt.Key_Enter) {
if (root.nickname !== nicknameInput.text && nicknameInput.valid)
root.editDone(nicknameInput.text)
}
}

View File

@ -560,7 +560,7 @@ QtObject {
},
StatusValidator {
name: "isAliasValidator"
validate: function (t) { return !globalUtils.isAlias(t) }
validate: function (t) { return !Utils.isAlias(t) }
errorMessage: qsTr("Adjective-animal Display Name formats are not allowed")
}
// https://github.com/status-im/status-desktop/issues/13434
@ -673,7 +673,7 @@ QtObject {
readonly property QtObject regularExpressions: QtObject {
readonly property var alphanumerical: /^$|^[a-zA-Z0-9]+$/
readonly property var alphanumericalExpanded: /^$|^[a-zA-Z0-9\-_.\u0020]+$/
readonly property var alphanumericalExpanded: /^$|^[a-zA-Z0-9\-_\.\u0020]+$/
readonly property var alphanumericalExpanded1: /^[a-zA-Z0-9\-_]+(?: [a-zA-Z0-9\-_]+)*$/
readonly property var alphanumericalWithSpace: /^$|^[a-zA-Z0-9\s]+$/
readonly property var asciiPrintable: /^$|^[!-~]+$/

View File

@ -45,6 +45,10 @@ QtObject {
return globalUtilsInst.isCompressedPubKey(pubKey)
}
function isAlias(name) {
return globalUtilsInst.isAlias(name)
}
function getCommunityIdFromFullChatId(fullChatId) {
return fullChatId.substr(0, communityIdLength)
}