mirror of
https://github.com/status-im/status-desktop.git
synced 2025-02-02 01:38:00 +00:00
feat: add validation on the create password form
This commit is contained in:
parent
847eb2623f
commit
fab4029318
@ -6,6 +6,30 @@ import "../shared"
|
|||||||
|
|
||||||
ModalPopup {
|
ModalPopup {
|
||||||
property bool loading: false
|
property bool loading: false
|
||||||
|
property string passwordValidationError: ""
|
||||||
|
property string repeatPasswordValidationError: ""
|
||||||
|
|
||||||
|
function validate() {
|
||||||
|
if (firstPasswordField.text === "") {
|
||||||
|
passwordValidationError = qsTr("You need to enter a password")
|
||||||
|
} else if (firstPasswordField.text.length < 4) {
|
||||||
|
passwordValidationError = qsTr("Password needs to be 4 characters or more")
|
||||||
|
} else {
|
||||||
|
passwordValidationError = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
if (repeatPasswordField.text === "") {
|
||||||
|
repeatPasswordValidationError = qsTr("You need to repeat your password")
|
||||||
|
} else if (repeatPasswordField.text !== firstPasswordField.text) {
|
||||||
|
repeatPasswordValidationError = qsTr("Both passwords must match")
|
||||||
|
} else {
|
||||||
|
repeatPasswordValidationError = ""
|
||||||
|
}
|
||||||
|
console.log('Validation?', passwordValidationError, repeatPasswordValidationError)
|
||||||
|
|
||||||
|
return passwordValidationError === "" && repeatPasswordValidationError === ""
|
||||||
|
}
|
||||||
|
|
||||||
id: popup
|
id: popup
|
||||||
title: qsTr("Create a password")
|
title: qsTr("Create a password")
|
||||||
height: 500
|
height: 500
|
||||||
@ -23,6 +47,7 @@ ModalPopup {
|
|||||||
anchors.topMargin: 88
|
anchors.topMargin: 88
|
||||||
placeholderText: qsTr("New password...")
|
placeholderText: qsTr("New password...")
|
||||||
textField.echoMode: TextInput.Password
|
textField.echoMode: TextInput.Password
|
||||||
|
validationError: popup.passwordValidationError
|
||||||
}
|
}
|
||||||
|
|
||||||
Input {
|
Input {
|
||||||
@ -35,6 +60,7 @@ ModalPopup {
|
|||||||
anchors.topMargin: Theme.xlPadding
|
anchors.topMargin: Theme.xlPadding
|
||||||
placeholderText: qsTr("Confirm password…")
|
placeholderText: qsTr("Confirm password…")
|
||||||
textField.echoMode: TextInput.Password
|
textField.echoMode: TextInput.Password
|
||||||
|
validationError: popup.repeatPasswordValidationError
|
||||||
Keys.onReturnPressed: {
|
Keys.onReturnPressed: {
|
||||||
submitBtn.clicked()
|
submitBtn.clicked()
|
||||||
}
|
}
|
||||||
@ -113,18 +139,6 @@ ModalPopup {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MessageDialog {
|
|
||||||
id: passwordsDontMatchError
|
|
||||||
title: qsTr("Error")
|
|
||||||
text: qsTr("Passwords don't match")
|
|
||||||
icon: StandardIcon.Warning
|
|
||||||
standardButtons: StandardButton.Ok
|
|
||||||
onAccepted: {
|
|
||||||
repeatPasswordField.clear()
|
|
||||||
repeatPasswordField.forceActiveFocus(Qt.MouseFocusReason)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Connections {
|
Connections {
|
||||||
target: onboardingModel
|
target: onboardingModel
|
||||||
ignoreUnknownSignals: true
|
ignoreUnknownSignals: true
|
||||||
@ -136,13 +150,10 @@ ModalPopup {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onClicked : {
|
onClicked: {
|
||||||
if (firstPasswordField.text === "" || repeatPasswordField.text === "") {
|
if (!validate()) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (repeatPasswordField.text !== firstPasswordField.text) {
|
|
||||||
return passwordsDontMatchError.open()
|
|
||||||
}
|
|
||||||
// TODO this doesn't seem to work because the function freezes the view
|
// TODO this doesn't seem to work because the function freezes the view
|
||||||
loading = true
|
loading = true
|
||||||
const result = onboardingModel.storeDerivedAndLogin(repeatPasswordField.text);
|
const result = onboardingModel.storeDerivedAndLogin(repeatPasswordField.text);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user