|
| 1 | +<script setup lang="ts"> |
| 2 | +import { ref } from 'vue'; |
| 3 | +import type { KeyResult } from '../api/registration'; |
| 4 | +
|
| 5 | +const props = withDefaults( |
| 6 | + defineProps<{ result: KeyResult; variant?: 'register' | 'restore' }>(), |
| 7 | + { variant: 'register' }, |
| 8 | +); |
| 9 | +
|
| 10 | +const pubCopied = ref(false); |
| 11 | +const privCopied = ref(false); |
| 12 | +
|
| 13 | +async function copy(text: string | null, flag: 'pub' | 'priv') { |
| 14 | + if (!text) return; |
| 15 | + try { |
| 16 | + await navigator.clipboard.writeText(text); |
| 17 | + if (flag === 'pub') { |
| 18 | + pubCopied.value = true; |
| 19 | + setTimeout(() => (pubCopied.value = false), 1500); |
| 20 | + } else { |
| 21 | + privCopied.value = true; |
| 22 | + setTimeout(() => (privCopied.value = false), 1500); |
| 23 | + } |
| 24 | + } catch { |
| 25 | + /* ignore */ |
| 26 | + } |
| 27 | +} |
| 28 | +
|
| 29 | +const hasPrivkey = !!props.result.privkey; |
| 30 | +</script> |
| 31 | + |
| 32 | +<template> |
| 33 | + <v-card class="term-panel" style="padding: 1.5rem"> |
| 34 | + <div class="term-eyebrow" style="margin-bottom: 0.5rem"> |
| 35 | + // key material |
| 36 | + </div> |
| 37 | + <h2 class="term-display term-hot" style="font-size: 1.5rem; margin: 0 0 1rem"> |
| 38 | + ACCESS GRANTED |
| 39 | + </h2> |
| 40 | + |
| 41 | + <!-- Register page: explain how the key got here. --> |
| 42 | + <v-alert |
| 43 | + v-if="props.variant === 'register' && hasPrivkey" |
| 44 | + type="info" |
| 45 | + density="compact" |
| 46 | + style="margin-bottom: 1.25rem" |
| 47 | + > |
| 48 | + A keypair was generated for you. Your private key is stored |
| 49 | + server-side — if you lose it, you can retrieve it again via |
| 50 | + <strong>Restore Key</strong> with your matriculation number and |
| 51 | + password. |
| 52 | + </v-alert> |
| 53 | + <v-alert |
| 54 | + v-else-if="props.variant === 'register' && !hasPrivkey" |
| 55 | + type="info" |
| 56 | + density="compact" |
| 57 | + style="margin-bottom: 1.25rem" |
| 58 | + > |
| 59 | + You provided your own public key. No private key is stored server-side. |
| 60 | + </v-alert> |
| 61 | + |
| 62 | + <!-- Restore Key page: the user just re-fetched an existing keypair. --> |
| 63 | + <v-alert |
| 64 | + v-else-if="props.variant === 'restore' && hasPrivkey" |
| 65 | + type="info" |
| 66 | + density="compact" |
| 67 | + style="margin-bottom: 1.25rem" |
| 68 | + > |
| 69 | + Your stored keypair is shown below. Download whichever key you need. |
| 70 | + </v-alert> |
| 71 | + <v-alert |
| 72 | + v-else-if="props.variant === 'restore' && !hasPrivkey" |
| 73 | + type="info" |
| 74 | + density="compact" |
| 75 | + style="margin-bottom: 1.25rem" |
| 76 | + > |
| 77 | + Only your public key is on file — you supplied your own at |
| 78 | + registration time, so the private key stays with you. |
| 79 | + </v-alert> |
| 80 | + |
| 81 | + <div style="display: flex; flex-direction: column; gap: 1.5rem"> |
| 82 | + <div> |
| 83 | + <div class="term-eyebrow" style="margin-bottom: 0.4rem"> |
| 84 | + public key |
| 85 | + </div> |
| 86 | + <v-textarea |
| 87 | + :model-value="props.result.pubkey" |
| 88 | + readonly |
| 89 | + rows="3" |
| 90 | + auto-grow |
| 91 | + hide-details |
| 92 | + /> |
| 93 | + <div style="display: flex; gap: 0.5rem; margin-top: 0.5rem"> |
| 94 | + <v-btn |
| 95 | + :href="props.result.pubkey_url" |
| 96 | + download="id_rsa.pub" |
| 97 | + prepend-icon="mdi-download" |
| 98 | + size="small" |
| 99 | + > |
| 100 | + Download id_rsa.pub |
| 101 | + </v-btn> |
| 102 | + <v-btn |
| 103 | + size="small" |
| 104 | + :prepend-icon="pubCopied ? 'mdi-check' : 'mdi-content-copy'" |
| 105 | + @click="copy(props.result.pubkey, 'pub')" |
| 106 | + > |
| 107 | + {{ pubCopied ? 'Copied' : 'Copy' }} |
| 108 | + </v-btn> |
| 109 | + </div> |
| 110 | + </div> |
| 111 | + |
| 112 | + <div v-if="hasPrivkey"> |
| 113 | + <div class="term-eyebrow" style="margin-bottom: 0.4rem"> |
| 114 | + private key |
| 115 | + </div> |
| 116 | + <v-textarea |
| 117 | + :model-value="props.result.privkey ?? ''" |
| 118 | + readonly |
| 119 | + rows="6" |
| 120 | + auto-grow |
| 121 | + hide-details |
| 122 | + /> |
| 123 | + <div style="display: flex; gap: 0.5rem; margin-top: 0.5rem"> |
| 124 | + <v-btn |
| 125 | + v-if="props.result.privkey_url" |
| 126 | + :href="props.result.privkey_url" |
| 127 | + download="id_rsa" |
| 128 | + prepend-icon="mdi-download" |
| 129 | + size="small" |
| 130 | + > |
| 131 | + Download id_rsa |
| 132 | + </v-btn> |
| 133 | + <v-btn |
| 134 | + size="small" |
| 135 | + :prepend-icon="privCopied ? 'mdi-check' : 'mdi-content-copy'" |
| 136 | + @click="copy(props.result.privkey, 'priv')" |
| 137 | + > |
| 138 | + {{ privCopied ? 'Copied' : 'Copy' }} |
| 139 | + </v-btn> |
| 140 | + </div> |
| 141 | + </div> |
| 142 | + </div> |
| 143 | + </v-card> |
| 144 | +</template> |
0 commit comments