Improved api key ux
This commit is contained in:
@@ -118,8 +118,6 @@ public class ApiKeysController : Controller
|
|||||||
throw new HttpApiException("No api key with that id found", 404);
|
throw new HttpApiException("No api key with that id found", 404);
|
||||||
|
|
||||||
apiKey.Description = request.Description;
|
apiKey.Description = request.Description;
|
||||||
apiKey.PermissionsJson = request.PermissionsJson;
|
|
||||||
apiKey.ExpiresAt = request.ExpiresAt;
|
|
||||||
|
|
||||||
await ApiKeyRepository.Update(apiKey);
|
await ApiKeyRepository.Update(apiKey);
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
@inject NavigationManager Navigation
|
@inject NavigationManager Navigation
|
||||||
@inject ToastService ToastService
|
@inject ToastService ToastService
|
||||||
@inject AlertService AlertService
|
@inject AlertService AlertService
|
||||||
|
@inject DownloadService DownloadService
|
||||||
|
|
||||||
<PageHeader Title="Create API Key">
|
<PageHeader Title="Create API Key">
|
||||||
<a href="/admin/api" class="btn btn-secondary">
|
<a href="/admin/api" class="btn btn-secondary">
|
||||||
@@ -38,7 +39,7 @@
|
|||||||
<div class="sm:col-span-2">
|
<div class="sm:col-span-2">
|
||||||
<label class="block text-sm font-medium leading-6 text-white">Expires at</label>
|
<label class="block text-sm font-medium leading-6 text-white">Expires at</label>
|
||||||
<div class="mt-2">
|
<div class="mt-2">
|
||||||
<input @bind="Request.ExpiresAt" type="datetime" autocomplete="off" class="form-input w-full">
|
<input @bind="Request.ExpiresAt" type="date" autocomplete="off" class="form-input w-full">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -57,11 +58,18 @@
|
|||||||
|
|
||||||
private async Task OnSubmit()
|
private async Task OnSubmit()
|
||||||
{
|
{
|
||||||
|
Request.ExpiresAt = Request.ExpiresAt.ToUniversalTime();
|
||||||
|
|
||||||
var response = await ApiClient.PostJson<CreateApiKeyResponse>("api/admin/apikeys", Request);
|
var response = await ApiClient.PostJson<CreateApiKeyResponse>("api/admin/apikeys", Request);
|
||||||
|
|
||||||
|
await DownloadService.DownloadString(
|
||||||
|
$"moonlight-key-{response.Id}.txt",
|
||||||
|
response.Secret
|
||||||
|
);
|
||||||
|
|
||||||
await AlertService.Success(
|
await AlertService.Success(
|
||||||
"API Key successfully created",
|
"API Key successfully created",
|
||||||
$"Copy the following secret. It wont be shown again. '{response.Secret}'"
|
"The API Key has been downloaded. Dont lose it, you cant view it anymore"
|
||||||
);
|
);
|
||||||
|
|
||||||
await ToastService.Success("Successfully created api key");
|
await ToastService.Success("Successfully created api key");
|
||||||
|
|||||||
@@ -29,18 +29,6 @@
|
|||||||
<input @bind="Request.Description" type="text" autocomplete="off" class="form-input w-full">
|
<input @bind="Request.Description" type="text" autocomplete="off" class="form-input w-full">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="sm:col-span-2">
|
|
||||||
<label class="block text-sm font-medium leading-6 text-white">Permissions</label>
|
|
||||||
<div class="mt-2">
|
|
||||||
<input @bind="Request.PermissionsJson" type="email" autocomplete="off" class="form-input w-full">
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="sm:col-span-2">
|
|
||||||
<label class="block text-sm font-medium leading-6 text-white">Expires at</label>
|
|
||||||
<div class="mt-2">
|
|
||||||
<input @bind="Request.ExpiresAt" type="datetime" autocomplete="off" class="form-input w-full">
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</HandleForm>
|
</HandleForm>
|
||||||
</div>
|
</div>
|
||||||
@@ -56,7 +44,11 @@
|
|||||||
private async Task Load(LazyLoader _)
|
private async Task Load(LazyLoader _)
|
||||||
{
|
{
|
||||||
var detail = await ApiClient.GetJson<ApiKeyResponse>($"api/admin/apikeys/{Id}");
|
var detail = await ApiClient.GetJson<ApiKeyResponse>($"api/admin/apikeys/{Id}");
|
||||||
Request = Mapper.Map<UpdateApiKeyRequest>(detail);
|
|
||||||
|
Request = new()
|
||||||
|
{
|
||||||
|
Description = detail.Description
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task OnSubmit()
|
private async Task OnSubmit()
|
||||||
|
|||||||
@@ -6,10 +6,4 @@ public class UpdateApiKeyRequest
|
|||||||
{
|
{
|
||||||
[Required(ErrorMessage = "You need to specify a description")]
|
[Required(ErrorMessage = "You need to specify a description")]
|
||||||
public string Description { get; set; }
|
public string Description { get; set; }
|
||||||
|
|
||||||
[Required(ErrorMessage = "You need to specify permissions for the api key")]
|
|
||||||
public string PermissionsJson { get; set; } = "[]";
|
|
||||||
|
|
||||||
[Required(ErrorMessage = "You need to specify an expire date")]
|
|
||||||
public DateTime ExpiresAt { get; set; }
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user