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);
|
||||
|
||||
apiKey.Description = request.Description;
|
||||
apiKey.PermissionsJson = request.PermissionsJson;
|
||||
apiKey.ExpiresAt = request.ExpiresAt;
|
||||
|
||||
await ApiKeyRepository.Update(apiKey);
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
@inject NavigationManager Navigation
|
||||
@inject ToastService ToastService
|
||||
@inject AlertService AlertService
|
||||
@inject DownloadService DownloadService
|
||||
|
||||
<PageHeader Title="Create API Key">
|
||||
<a href="/admin/api" class="btn btn-secondary">
|
||||
@@ -38,7 +39,7 @@
|
||||
<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">
|
||||
<input @bind="Request.ExpiresAt" type="date" autocomplete="off" class="form-input w-full">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -57,11 +58,18 @@
|
||||
|
||||
private async Task OnSubmit()
|
||||
{
|
||||
Request.ExpiresAt = Request.ExpiresAt.ToUniversalTime();
|
||||
|
||||
var response = await ApiClient.PostJson<CreateApiKeyResponse>("api/admin/apikeys", Request);
|
||||
|
||||
await DownloadService.DownloadString(
|
||||
$"moonlight-key-{response.Id}.txt",
|
||||
response.Secret
|
||||
);
|
||||
|
||||
await AlertService.Success(
|
||||
"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");
|
||||
|
||||
@@ -29,18 +29,6 @@
|
||||
<input @bind="Request.Description" type="text" 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">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>
|
||||
</HandleForm>
|
||||
</div>
|
||||
@@ -56,7 +44,11 @@
|
||||
private async Task Load(LazyLoader _)
|
||||
{
|
||||
var detail = await ApiClient.GetJson<ApiKeyResponse>($"api/admin/apikeys/{Id}");
|
||||
Request = Mapper.Map<UpdateApiKeyRequest>(detail);
|
||||
|
||||
Request = new()
|
||||
{
|
||||
Description = detail.Description
|
||||
};
|
||||
}
|
||||
|
||||
private async Task OnSubmit()
|
||||
|
||||
@@ -6,10 +6,4 @@ public class UpdateApiKeyRequest
|
||||
{
|
||||
[Required(ErrorMessage = "You need to specify a description")]
|
||||
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