Also display erroneous PGP keys
continuous-integration/drone/push Build is passing Details

This commit is contained in:
nemunaire 2022-09-20 00:52:25 +02:00
parent 16d7fe4beb
commit 57d37544f9
3 changed files with 30 additions and 3 deletions

View File

@ -126,8 +126,7 @@ func declareAPIAuthKeysRoutes(router *gin.RouterGroup) {
k := c.MustGet("key").(*Key)
if err := k.ReadInfos(u); err != nil {
log.Println("Unable to ReadInfos:", err)
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Unable to read your public key. Please try again in a few moment."})
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": fmt.Sprintf("Unable to read your public key: %s", err.Error())})
return
}

View File

@ -59,3 +59,15 @@ export async function getKey(kid, userid) {
throw new Error((await res.json()).errmsg);
}
}
export async function deleteKey(kid, userid) {
const res = await fetch(userid?`api/users/${userid}/keys/${kid}`:`api/keys/${kid}`, {
method: 'DELETE',
headers: {'Accept': 'application/json'}
})
if (res.status == 200) {
return await res.json();
} else {
throw new Error((await res.json()).errmsg);
}
}

View File

@ -1,5 +1,5 @@
<script>
import { getKeys, getKey, Key } from '../lib/key';
import { deleteKey, getKeys, getKey, Key } from '../lib/key';
import { user } from '../stores/user';
import { ToastsStore } from '../stores/toasts';
@ -72,6 +72,22 @@
</button>
</div>
</div>
{:catch err}
<div class="alert alert-danger d-flex justify-content-between">
<p>
<strong>Il y a une erreur avec cette clef&nbsp;:</strong>
{err}
</p>
<div class="d-flex flex-column justify-content-center">
<button
type="button"
class="btn btn-outline-danger float-end"
on:click={() => deleteKey(keyid).then(() => { keysP = getKeys(); })}
>
Supprimer la clef
</button>
</div>
</div>
{/await}
{/each}
{:else}