settings: pasting private key should update pubkey
ci/woodpecker/push/woodpecker Pipeline was successful Details
ci/woodpecker/pr/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.
OFF0 2 years ago
parent cfb7a2dc35
commit 6b251c9d12
Signed by: offbyn
GPG Key ID: 94A2F643C51F37FA

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

@ -579,6 +579,19 @@ importBtn.addEventListener('click', () => {
});
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) {
try {

Loading…
Cancel
Save