mirror of
https://github.com/status-im/status-desktop.git
synced 2025-02-22 11:38:57 +00:00
fix: password count and disable repeat until first is valid
cleanup
This commit is contained in:
parent
d797880e6e
commit
fad0bb858e
@ -20,9 +20,8 @@ ModalPopup {
|
||||
if (passwordInput.text === "") {
|
||||
//% "You need to enter a password"
|
||||
passwordValidationError = qsTrId("you-need-to-enter-a-password")
|
||||
} else if (passwordInput.text.length < 4) {
|
||||
//% "Password needs to be 4 characters or more"
|
||||
passwordValidationError = qsTrId("password-needs-to-be-4-characters-or-more")
|
||||
} else if (passwordInput.text.length < 6) {
|
||||
passwordValidationError = qsTr("Password needs to be 6 characters or more")
|
||||
} else {
|
||||
passwordValidationError = ""
|
||||
}
|
||||
|
@ -24,9 +24,8 @@ ModalPopup {
|
||||
if (passwordInput.text === "") {
|
||||
//% "You need to enter a password"
|
||||
passwordValidationError = qsTrId("you-need-to-enter-a-password")
|
||||
} else if (passwordInput.text.length < 4) {
|
||||
//% "Password needs to be 4 characters or more"
|
||||
passwordValidationError = qsTrId("password-needs-to-be-4-characters-or-more")
|
||||
} else if (passwordInput.text.length < 6) {
|
||||
passwordValidationError = qsTr("Password needs to be 6 characters or more")
|
||||
} else {
|
||||
passwordValidationError = ""
|
||||
}
|
||||
|
@ -18,9 +18,8 @@ ModalPopup {
|
||||
if (passwordInput.text === "") {
|
||||
//% "You need to enter a password"
|
||||
passwordValidationError = qsTrId("you-need-to-enter-a-password")
|
||||
} else if (passwordInput.text.length < 4) {
|
||||
//% "Password needs to be 4 characters or more"
|
||||
passwordValidationError = qsTrId("password-needs-to-be-4-characters-or-more")
|
||||
} else if (passwordInput.text.length < 6) {
|
||||
passwordValidationError = qsTr("Password needs to be 6 characters or more")
|
||||
} else {
|
||||
passwordValidationError = ""
|
||||
}
|
||||
|
@ -197,4 +197,31 @@ QtObject {
|
||||
default: return network
|
||||
}
|
||||
}
|
||||
|
||||
function validate(item, firstPasswordField, repeatPasswordField) {
|
||||
console.log("validate");
|
||||
switch (item) {
|
||||
case "first":
|
||||
if (firstPasswordField.text === "") {
|
||||
//% "You need to enter a password"
|
||||
return [false, qsTrId("you-need-to-enter-a-password")];
|
||||
} else if (firstPasswordField.text.length < 6) {
|
||||
return [false, qsTrId("Password needs to be 6 characters or more")];
|
||||
}
|
||||
return [true, ""];
|
||||
|
||||
case "repeat":
|
||||
if (repeatPasswordField.text === "") {
|
||||
//% "You need to repeat your password"
|
||||
return [false, qsTrId("you-need-to-repeat-your-password")];
|
||||
} else if (repeatPasswordField.text !== firstPasswordField.text) {
|
||||
//% Both passwords must match
|
||||
return [true, qsTrId("both-passwords-must-match")];
|
||||
}
|
||||
return [true, ""];
|
||||
|
||||
default:
|
||||
return [false, ""];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,33 +7,11 @@ import "../shared/status"
|
||||
|
||||
ModalPopup {
|
||||
property bool loading: false
|
||||
property bool firstPasswordFieldValid: false
|
||||
property bool repeatPasswordFieldValid: false
|
||||
property string passwordValidationError: ""
|
||||
property string repeatPasswordValidationError: ""
|
||||
|
||||
function validate() {
|
||||
if (firstPasswordField.text === "") {
|
||||
//% "You need to enter a password"
|
||||
passwordValidationError = qsTrId("you-need-to-enter-a-password")
|
||||
} else if (firstPasswordField.text.length < 4) {
|
||||
//% "Password needs to be 4 characters or more"
|
||||
passwordValidationError = qsTrId("password-needs-to-be-4-characters-or-more")
|
||||
} else {
|
||||
passwordValidationError = ""
|
||||
}
|
||||
|
||||
if (repeatPasswordField.text === "") {
|
||||
//% "You need to repeat your password"
|
||||
repeatPasswordValidationError = qsTrId("you-need-to-repeat-your-password")
|
||||
} else if (repeatPasswordField.text !== firstPasswordField.text) {
|
||||
//% "Both passwords must match"
|
||||
repeatPasswordValidationError = qsTrId("both-passwords-must-match")
|
||||
} else {
|
||||
repeatPasswordValidationError = ""
|
||||
}
|
||||
|
||||
return passwordValidationError === "" && repeatPasswordValidationError === ""
|
||||
}
|
||||
|
||||
id: popup
|
||||
//% "Create a password"
|
||||
title: qsTrId("intro-wizard-title-alt4")
|
||||
@ -54,10 +32,15 @@ ModalPopup {
|
||||
placeholderText: qsTrId("new-password...")
|
||||
textField.echoMode: TextInput.Password
|
||||
validationError: popup.passwordValidationError
|
||||
onTextChanged: {
|
||||
[firstPasswordFieldValid, passwordValidationError] =
|
||||
Utils.validate("first", firstPasswordField, repeatPasswordField);
|
||||
}
|
||||
}
|
||||
|
||||
Input {
|
||||
id: repeatPasswordField
|
||||
enabled: firstPasswordFieldValid
|
||||
anchors.rightMargin: 0
|
||||
anchors.leftMargin: 0
|
||||
anchors.right: firstPasswordField.right
|
||||
@ -71,6 +54,10 @@ ModalPopup {
|
||||
Keys.onReturnPressed: {
|
||||
submitBtn.clicked()
|
||||
}
|
||||
onTextChanged: {
|
||||
[repeatPasswordFieldValid, repeatPasswordValidationError] =
|
||||
Utils.validate("repeat", firstPasswordField, repeatPasswordField);
|
||||
}
|
||||
}
|
||||
|
||||
StyledText {
|
||||
@ -103,7 +90,7 @@ ModalPopup {
|
||||
//% "Create password"
|
||||
text: qsTrId("create-password")
|
||||
|
||||
enabled: firstPasswordField.text !== "" && repeatPasswordField.text !== "" && !loading
|
||||
enabled: firstPasswordFieldValid && repeatPasswordFieldValid && !loading
|
||||
|
||||
MessageDialog {
|
||||
id: importError
|
||||
@ -144,10 +131,6 @@ ModalPopup {
|
||||
}
|
||||
|
||||
onClicked: {
|
||||
if (!validate()) {
|
||||
errorSound.play()
|
||||
return
|
||||
}
|
||||
loading = true
|
||||
loginModel.isCurrentFlow = false;
|
||||
onboardingModel.isCurrentFlow = true;
|
||||
|
@ -13,8 +13,7 @@ Item {
|
||||
property alias validationError: txtPassword.validationError
|
||||
//% "You need to enter a password"
|
||||
property string noInputErrorMessage: qsTrId("you-need-to-enter-a-password")
|
||||
//% "Password needs to be 4 characters or more"
|
||||
property string invalidInputErrorMessage: qsTrId("password-needs-to-be-4-characters-or-more")
|
||||
property string invalidInputErrorMessage: qsTr("Password needs to be 6 characters or more")
|
||||
property bool isValid: false
|
||||
|
||||
function forceActiveFocus(reason) {
|
||||
@ -26,7 +25,7 @@ Item {
|
||||
const noInput = txtPassword.text === ""
|
||||
if (noInput) {
|
||||
txtPassword.validationError = noInputErrorMessage
|
||||
} else if (txtPassword.text.length < 4) {
|
||||
} else if (txtPassword.text.length < 6) {
|
||||
txtPassword.validationError = invalidInputErrorMessage
|
||||
}
|
||||
isValid = txtPassword.validationError === ""
|
||||
|
Loading…
x
Reference in New Issue
Block a user