|
20 | 20 |
|
21 | 21 | <div class="row mb-4"> |
22 | 22 | <div class="col-md-12"> |
23 | | - <button class="btn btn-primary" @onclick="ShowCreateDialog"> |
| 23 | + <div class="alert alert-info"> |
| 24 | + <strong><i class="bi bi-shield-check"></i> Security Best Practices:</strong> |
| 25 | + <ul class="mb-0 mt-2"> |
| 26 | + <li>Store API keys securely in environment variables or secret managers</li> |
| 27 | + <li>Rotate keys regularly and revoke unused ones</li> |
| 28 | + <li>Use separate keys for different environments (dev, staging, production)</li> |
| 29 | + <li>Set expiration dates to limit key lifespan</li> |
| 30 | + </ul> |
| 31 | + </div> |
| 32 | + </div> |
| 33 | + </div> |
| 34 | + |
| 35 | + <div class="row mb-4"> |
| 36 | + <div class="col-md-12"> |
| 37 | + <button class="btn btn-sm btn-primary" @onclick="ShowCreateDialog"> |
24 | 38 | <i class="bi bi-plus-circle"></i> Create New API Key |
25 | 39 | </button> |
26 | 40 | </div> |
|
39 | 53 | } |
40 | 54 | else if (_error != null) |
41 | 55 | { |
42 | | - <div class="alert alert-danger" role="alert"> |
43 | | - <i class="bi bi-exclamation-triangle-fill"></i> @_error |
| 56 | + <div class="alert alert-danger alert-dismissible fade show" role="alert"> |
| 57 | + <i class="bi bi-exclamation-triangle-fill"></i> |
| 58 | + <strong>Error:</strong> @_error |
| 59 | + <button type="button" class="btn-close" @onclick="() => _error = null"></button> |
44 | 60 | </div> |
45 | 61 | } |
46 | 62 | else if (_apiKeys?.Any() == true) |
47 | 63 | { |
48 | 64 | <div class="table-responsive"> |
49 | | - <table class="table table-striped table-hover"> |
| 65 | + <table class="table table-sm table-hover table-border"> |
50 | 66 | <thead> |
51 | 67 | <tr> |
52 | 68 | <th>Name</th> |
|
64 | 80 | <td> |
65 | 81 | <div> |
66 | 82 | <strong>@key.Name</strong> |
67 | | - <br /> |
68 | | - <small class="text-muted font-monospace">@key.Key[..8]...</small> |
69 | 83 | </div> |
70 | 84 | </td> |
71 | 85 | <td> |
|
85 | 99 | <td> |
86 | 100 | @if (key.CanPushNewPlugins) |
87 | 101 | { |
88 | | - <span class="badge bg-info me-1">New Plugins</span> |
| 102 | + <span class="badge border border-secondary text-secondary me-1">New Plugins</span> |
89 | 103 | } |
90 | 104 | @if (key.CanPushPluginVersions) |
91 | 105 | { |
92 | | - <span class="badge bg-info me-1">Versions</span> |
| 106 | + <span class="badge border border-secondary text-secondary me-1">Versions</span> |
93 | 107 | } |
94 | 108 | @if (key.AssignedPlugins.Any()) |
95 | 109 | { |
|
100 | 114 | <td> |
101 | 115 | @if (key.ExpiresAt.HasValue) |
102 | 116 | { |
103 | | - @key.ExpiresAt.Value.ToString("yyyy-MM-dd") |
| 117 | + var daysUntilExpiry = (key.ExpiresAt.Value - DateTime.UtcNow).Days; |
| 118 | + <span class="@(daysUntilExpiry <= 7 ? "text-danger fw-bold" : "")"> |
| 119 | + @key.ExpiresAt.Value.ToString("yyyy-MM-dd") |
| 120 | + @if (daysUntilExpiry <= 7 && daysUntilExpiry > 0) |
| 121 | + { |
| 122 | + <i class="bi bi-exclamation-triangle-fill text-warning ms-1" |
| 123 | + title="Expires in @daysUntilExpiry days"></i> |
| 124 | + } |
| 125 | + </span> |
104 | 126 | } |
105 | 127 | else |
106 | 128 | { |
|
110 | 132 | <td> |
111 | 133 | @if (key.IsActive) |
112 | 134 | { |
113 | | - <button class="btn btn-sm btn-danger" @onclick="() => ConfirmRevoke(key.Id)"> |
| 135 | + <button class="btn btn-xs btn-danger" @onclick="() => ConfirmRevoke(key.Id)"> |
114 | 136 | <i class="bi bi-trash"></i> Revoke |
115 | 137 | </button> |
116 | 138 | } |
|
128 | 150 | <i class="bi bi-key" style="font-size: 3rem; color: #6c757d;"></i> |
129 | 151 | <h5 class="mt-3">No API Keys</h5> |
130 | 152 | <p class="text-muted">Create your first API key to start uploading plugins programmatically.</p> |
| 153 | + <button class="btn btn-sm btn-primary mt-3" @onclick="ShowCreateDialog"> |
| 154 | + <i class="bi bi-plus-circle"></i> Create Your First API Key |
| 155 | + </button> |
131 | 156 | </div> |
132 | 157 | </div> |
133 | 158 | } |
|
170 | 195 | <label class="form-label fw-bold">API Key</label> |
171 | 196 | <div class="input-group"> |
172 | 197 | <input type="text" class="form-control font-monospace" value="@_newRawKey" readonly /> |
173 | | - <button class="btn btn-outline-secondary" type="button" @onclick="CopyToClipboard"> |
174 | | - <i class="bi bi-clipboard"></i> Copy |
| 198 | + <button class="btn btn-outline-secondary" type="button" @onclick="CopyToClipboard" disabled="@_copying"> |
| 199 | + @if (_copying) |
| 200 | + { |
| 201 | + <span class="spinner-border spinner-border-sm" role="status"></span> |
| 202 | + } |
| 203 | + else |
| 204 | + { |
| 205 | + <i class="bi bi-clipboard"></i> |
| 206 | + } |
| 207 | + Copy |
175 | 208 | </button> |
176 | 209 | </div> |
177 | 210 | </div> |
|
220 | 253 | </div> |
221 | 254 | } |
222 | 255 |
|
| 256 | +@if (_showToast) |
| 257 | +{ |
| 258 | + <div class="position-fixed bottom-0 end-0 p-3" style="z-index: 11"> |
| 259 | + <div class="toast fade show" role="alert" aria-live="assertive" aria-atomic="true"> |
| 260 | + <div class="toast-header"> |
| 261 | + <strong class="me-auto">API Key Status</strong> |
| 262 | + <button type="button" class="btn-close" @onclick="() => _showToast = false" aria-label="Close"></button> |
| 263 | + </div> |
| 264 | + <div class="toast-body"> |
| 265 | + @_toastMessage |
| 266 | + </div> |
| 267 | + </div> |
| 268 | + </div> |
| 269 | +} |
| 270 | + |
223 | 271 | @code { |
224 | 272 | private List<ApiKeyViewModel>? _apiKeys; |
225 | 273 | private bool _loading = true; |
|
230 | 278 | private bool _revoking; |
231 | 279 | private string _newRawKey = string.Empty; |
232 | 280 | private Guid _keyToRevoke; |
| 281 | + private string? _toastMessage; |
| 282 | + private bool _showToast; |
| 283 | + private string? _successMessage; |
| 284 | + private bool _copying = false; |
233 | 285 |
|
234 | 286 | protected override async Task OnInitializedAsync() |
235 | 287 | { |
|
288 | 340 |
|
289 | 341 | private async Task CopyToClipboard() |
290 | 342 | { |
| 343 | + _copying = true; |
| 344 | + StateHasChanged(); |
| 345 | + |
291 | 346 | try |
292 | 347 | { |
293 | 348 | await JSRuntime.InvokeVoidAsync("navigator.clipboard.writeText", _newRawKey); |
294 | | - await JSRuntime.InvokeVoidAsync("alert", "API key copied to clipboard!"); |
| 349 | + _toastMessage = "API key copied to clipboard!"; |
| 350 | + _showToast = true; |
| 351 | + StateHasChanged(); |
| 352 | + await Task.Delay(3000); |
| 353 | + _showToast = false; |
295 | 354 | } |
296 | 355 | catch |
297 | 356 | { |
298 | | - await JSRuntime.InvokeVoidAsync("alert", "Failed to copy to clipboard"); |
| 357 | + _toastMessage = "Failed to copy to clipboard. Please copy manually."; |
| 358 | + _showToast = true; |
| 359 | + } |
| 360 | + finally |
| 361 | + { |
| 362 | + _copying = false; |
299 | 363 | } |
300 | 364 | } |
301 | 365 |
|
|
319 | 383 | var result = await ApiKeyService.RevokeApiKeyAsync(_keyToRevoke); |
320 | 384 | if (result?.Succeeded == true) |
321 | 385 | { |
| 386 | + _successMessage = "API key revoked successfully."; |
322 | 387 | await LoadApiKeys(); |
323 | 388 | HideConfirmDialog(); |
324 | 389 | } |
|
0 commit comments