Warn for overwrite on new credentials

This commit is contained in:
Dag Heyman 2017-03-01 14:38:02 +01:00
parent 4c13323eb7
commit 0a099dab7b
No known key found for this signature in database
GPG Key ID: 06FC004369E7D338
2 changed files with 67 additions and 48 deletions

View File

@ -8,7 +8,8 @@ Dialog {
title: qsTr("Add credential") title: qsTr("Add credential")
standardButtons: StandardButton.NoButton standardButtons: StandardButton.NoButton
modality: Qt.ApplicationModal modality: Qt.ApplicationModal
onAccepted: addCredential() property var settings
property var device
ColumnLayout { ColumnLayout {
anchors.fill: parent anchors.fill: parent
@ -45,34 +46,32 @@ Dialog {
} }
} }
ColumnLayout {
ColumnLayout { Label {
Label { text: qsTr("YubiKey Slot")
text: qsTr("YubiKey Slot") visible: settings.slotMode
visible: settings.slotMode
}
ExclusiveGroup {
id: slotSelected
}
RadioButton {
id: slot1
visible: settings.slotMode
enabled: settings.slot1
text: qsTr("Slot 1")
checked: true
exclusiveGroup: slotSelected
property string name: "1"
}
RadioButton {
id: slot2
visible: settings.slotMode
enabled: settings.slot2
text: qsTr("Slot 2")
exclusiveGroup: slotSelected
property string name: "2"
}
} }
ExclusiveGroup {
id: slotSelected
}
RadioButton {
id: slot1
visible: settings.slotMode
enabled: settings.slot1
text: qsTr("Slot 1")
checked: true
exclusiveGroup: slotSelected
property string name: "1"
}
RadioButton {
id: slot2
visible: settings.slotMode
enabled: settings.slot2
text: qsTr("Slot 2")
exclusiveGroup: slotSelected
property string name: "2"
}
}
GroupBox { GroupBox {
title: qsTr("Credential type") title: qsTr("Credential type")
@ -169,7 +168,14 @@ Dialog {
text: qsTr("Add credential") text: qsTr("Add credential")
enabled: acceptableInput() enabled: acceptableInput()
Layout.alignment: Qt.AlignRight | Qt.AlignBottom Layout.alignment: Qt.AlignRight | Qt.AlignBottom
onClicked: accept() onClicked: {
if (device.credentialExists(name.text)
&& !settings.slotMode) {
confirmOverWrite.open()
} else {
addCredential()
}
}
} }
Button { Button {
text: qsTr("Cancel") text: qsTr("Cancel")
@ -194,6 +200,15 @@ Dialog {
standardButtons: StandardButton.Ok standardButtons: StandardButton.Ok
} }
MessageDialog {
id: confirmOverWrite
icon: StandardIcon.Warning
title: qsTr("Overwrite credential?")
text: qsTr("A credential with this name already exists. Are you sure you want to overwrite this credential?")
standardButtons: StandardButton.Ok | StandardButton.Cancel
onAccepted: addCredential()
}
function clear() { function clear() {
name.text = "" name.text = ""
key.text = "" key.text = ""
@ -211,8 +226,7 @@ Dialog {
} }
} }
function acceptableInput() {
function acceptableInput(){
if (!settings.slotMode) { if (!settings.slotMode) {
return name.text.length !== 0 && key.text.length !== 0 return name.text.length !== 0 && key.text.length !== 0
} }
@ -240,7 +254,6 @@ Dialog {
} }
key.text = uri.secret key.text = uri.secret
} else { } else {
noQr.open() noQr.open()
} }
@ -248,22 +261,27 @@ Dialog {
function addCredential() { function addCredential() {
if (settings.slotMode) { if (settings.slotMode) {
device.addSlotCredential(slotSelected.current.name, key.text, touch.checked, function(error) { device.addSlotCredential(slotSelected.current.name, key.text,
if (error === 'Incorrect padding') { touch.checked, function (error) {
paddingError.open() if (error === 'Incorrect padding') {
} paddingError.open()
if (error) { }
console.log(error) if (error) {
} console.log(error)
}) }
close()
refreshDependingOnMode(true)
})
} else { } else {
device.addCredential(name.text, key.text, oathType.current.name, device.addCredential(name.text, key.text, oathType.current.name,
digits.current.digits, algorithm.current.name, digits.current.digits, algorithm.current.name,
touch.checked, function (error) { touch.checked, function (error) {
if (error === 'Incorrect padding') { if (error === 'Incorrect padding') {
paddingError.open() paddingError.open()
} }
}) close()
refreshDependingOnMode(true)
})
} }
} }
} }

View File

@ -91,7 +91,8 @@ ApplicationWindow {
AddCredential { AddCredential {
id: addCredential id: addCredential
onAccepted: refreshDependingOnMode(true) settings: settings
device: yk
} }
SettingsDialog { SettingsDialog {