settings: pasting private key should update pubkey
ci/woodpecker/pr/woodpecker Pipeline was successful Details
ci/woodpecker/push/woodpecker Pipeline was successful Details

If the user pastes a private-key and the pubkey field is empty,
it should be ok to generate and autofill the pubkey without
confusing the user. There might be circumstances where it is
preferred to see an error if the pubkey does not correspond with
the private key.

Added an on paste event listener that tries to generate and auto-
fill the pubkey (if empty).

Also disabled autocomplete on the settings form to indicate to not
save the key in password manager.
pull/24/head
OFF0 2 years ago
parent 8ec9420be8
commit 71945b105f
Signed by: offbyn
GPG Key ID: 94A2F643C51F37FA

@ -59,16 +59,16 @@
<input type="text" name="username" id="username" placeholder="username"> <input type="text" name="username" id="username" placeholder="username">
<button type="button" name="publish-username" tabindex="0">publish</button> <button type="button" name="publish-username" tabindex="0">publish</button>
</div> --> </div> -->
<form action="#" name="settings"> <form action="#" name="settings" autocomplete="new-password">
<label for="pubkey">public-key</label> <label for="pubkey">public-key</label>
<input type="text" id="pubkey"> <input type="text" id="pubkey" autocomplete="off">
<label for="privatekey"> <label for="privatekey">
private-key private-key
<button type="button" name="privatekey-toggle" class="btn-inline" > <button type="button" name="privatekey-toggle" class="btn-inline" >
<small>show</small> <small>show</small>
</button> </button>
</label> </label>
<input type="password" id="privatekey"> <input type="password" id="privatekey" autocomplete="off">
<div class="buttons"> <div class="buttons">
<small id="keystatus" class="form-status" hidden></small> <small id="keystatus" class="form-status" hidden></small>
<button type="button" name="generate" tabindex="0">new</button> <button type="button" name="generate" tabindex="0">new</button>

@ -604,6 +604,19 @@ importBtn.addEventListener('click', () => {
}); });
settingsForm.addEventListener('input', () => validKeys(privateKeyInput.value, pubKeyInput.value)); settingsForm.addEventListener('input', () => validKeys(privateKeyInput.value, pubKeyInput.value));
privateKeyInput.addEventListener('paste', (event) => {
if (pubKeyInput.value || !event.clipboardData) {
return;
}
if (privateKeyInput.value === '' || (
privateKeyInput.selectionStart === 0
&& privateKeyInput.selectionEnd === privateKeyInput.value.length
)) {
try {
pubKeyInput.value = getPublicKey(event.clipboardData.getData('text'));
} catch(err) {} // settings form will call validKeys on input and display the error
}
});
function validKeys(privatekey, pubkey) { function validKeys(privatekey, pubkey) {
try { try {

Loading…
Cancel
Save