Updated mooncore dependency usage
This commit is contained in:
91
Moonlight.ApiServer/Database/Migrations/20250205073340_RemovedUnusedFieldsInUserModel.Designer.cs
generated
Normal file
91
Moonlight.ApiServer/Database/Migrations/20250205073340_RemovedUnusedFieldsInUserModel.Designer.cs
generated
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Metadata;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
using Moonlight.ApiServer.Database;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace Moonlight.ApiServer.Database.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(CoreDataContext))]
|
||||||
|
[Migration("20250205073340_RemovedUnusedFieldsInUserModel")]
|
||||||
|
partial class RemovedUnusedFieldsInUserModel
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
|
modelBuilder
|
||||||
|
.HasDefaultSchema("Core")
|
||||||
|
.HasAnnotation("ProductVersion", "8.0.8")
|
||||||
|
.HasAnnotation("Relational:MaxIdentifierLength", 64);
|
||||||
|
|
||||||
|
MySqlModelBuilderExtensions.AutoIncrementColumns(modelBuilder);
|
||||||
|
|
||||||
|
modelBuilder.Entity("Moonlight.ApiServer.Database.Entities.ApiKey", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("Description")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("longtext");
|
||||||
|
|
||||||
|
b.Property<DateTime>("ExpiresAt")
|
||||||
|
.HasColumnType("datetime(6)");
|
||||||
|
|
||||||
|
b.Property<string>("PermissionsJson")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("longtext");
|
||||||
|
|
||||||
|
b.Property<string>("Secret")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("longtext");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("ApiKeys", "Core");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Moonlight.ApiServer.Database.Entities.User", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("Email")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("longtext");
|
||||||
|
|
||||||
|
b.Property<string>("Password")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("longtext");
|
||||||
|
|
||||||
|
b.Property<string>("PermissionsJson")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("longtext");
|
||||||
|
|
||||||
|
b.Property<DateTime>("TokenValidTimestamp")
|
||||||
|
.HasColumnType("datetime(6)");
|
||||||
|
|
||||||
|
b.Property<string>("Username")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("longtext");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Users", "Core");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace Moonlight.ApiServer.Database.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class RemovedUnusedFieldsInUserModel : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "AccessToken",
|
||||||
|
schema: "Core",
|
||||||
|
table: "Users");
|
||||||
|
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "RefreshTimestamp",
|
||||||
|
schema: "Core",
|
||||||
|
table: "Users");
|
||||||
|
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "RefreshToken",
|
||||||
|
schema: "Core",
|
||||||
|
table: "Users");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AddColumn<string>(
|
||||||
|
name: "AccessToken",
|
||||||
|
schema: "Core",
|
||||||
|
table: "Users",
|
||||||
|
type: "longtext",
|
||||||
|
nullable: false)
|
||||||
|
.Annotation("MySql:CharSet", "utf8mb4");
|
||||||
|
|
||||||
|
migrationBuilder.AddColumn<DateTime>(
|
||||||
|
name: "RefreshTimestamp",
|
||||||
|
schema: "Core",
|
||||||
|
table: "Users",
|
||||||
|
type: "datetime(6)",
|
||||||
|
nullable: false,
|
||||||
|
defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified));
|
||||||
|
|
||||||
|
migrationBuilder.AddColumn<string>(
|
||||||
|
name: "RefreshToken",
|
||||||
|
schema: "Core",
|
||||||
|
table: "Users",
|
||||||
|
type: "longtext",
|
||||||
|
nullable: false)
|
||||||
|
.Annotation("MySql:CharSet", "utf8mb4");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -59,10 +59,6 @@ namespace Moonlight.ApiServer.Database.Migrations
|
|||||||
|
|
||||||
MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property<int>("Id"));
|
MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
b.Property<string>("AccessToken")
|
|
||||||
.IsRequired()
|
|
||||||
.HasColumnType("longtext");
|
|
||||||
|
|
||||||
b.Property<string>("Email")
|
b.Property<string>("Email")
|
||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasColumnType("longtext");
|
.HasColumnType("longtext");
|
||||||
@@ -75,13 +71,6 @@ namespace Moonlight.ApiServer.Database.Migrations
|
|||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasColumnType("longtext");
|
.HasColumnType("longtext");
|
||||||
|
|
||||||
b.Property<DateTime>("RefreshTimestamp")
|
|
||||||
.HasColumnType("datetime(6)");
|
|
||||||
|
|
||||||
b.Property<string>("RefreshToken")
|
|
||||||
.IsRequired()
|
|
||||||
.HasColumnType("longtext");
|
|
||||||
|
|
||||||
b.Property<DateTime>("TokenValidTimestamp")
|
b.Property<DateTime>("TokenValidTimestamp")
|
||||||
.HasColumnType("datetime(6)");
|
.HasColumnType("datetime(6)");
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using MoonCore.Attributes;
|
|
||||||
using MoonCore.Exceptions;
|
using MoonCore.Exceptions;
|
||||||
using MoonCore.Extended.Abstractions;
|
using MoonCore.Extended.Abstractions;
|
||||||
using MoonCore.Extended.Helpers;
|
using MoonCore.Extended.Helpers;
|
||||||
|
using MoonCore.Extended.PermFilter;
|
||||||
using MoonCore.Models;
|
using MoonCore.Models;
|
||||||
using Moonlight.ApiServer.Database.Entities;
|
using Moonlight.ApiServer.Database.Entities;
|
||||||
using Moonlight.Shared.Http.Requests.Admin.Users;
|
using Moonlight.Shared.Http.Requests.Admin.Users;
|
||||||
|
|||||||
@@ -6,7 +6,9 @@
|
|||||||
"launchBrowser": false,
|
"launchBrowser": false,
|
||||||
"applicationUrl": "http://localhost:5165",
|
"applicationUrl": "http://localhost:5165",
|
||||||
"environmentVariables": {
|
"environmentVariables": {
|
||||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
"ASPNETCORE_ENVIRONMENT": "Development",
|
||||||
|
"HTTP_PROXY": "",
|
||||||
|
"HTTPS_PROXY": ""
|
||||||
},
|
},
|
||||||
"hotReloadEnabled": true
|
"hotReloadEnabled": true
|
||||||
},
|
},
|
||||||
@@ -16,7 +18,9 @@
|
|||||||
"launchBrowser": false,
|
"launchBrowser": false,
|
||||||
"applicationUrl": "http://localhost:5165",
|
"applicationUrl": "http://localhost:5165",
|
||||||
"environmentVariables": {
|
"environmentVariables": {
|
||||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
"ASPNETCORE_ENVIRONMENT": "Development",
|
||||||
|
"HTTP_PROXY": "",
|
||||||
|
"HTTPS_PROXY": ""
|
||||||
},
|
},
|
||||||
"hotReloadEnabled": true,
|
"hotReloadEnabled": true,
|
||||||
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}"
|
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}"
|
||||||
|
|||||||
@@ -27,7 +27,7 @@
|
|||||||
<PackageReference Include="MoonCore" Version="1.8.2" />
|
<PackageReference Include="MoonCore" Version="1.8.2" />
|
||||||
<PackageReference Include="MoonCore.Blazor" Version="1.2.8" />
|
<PackageReference Include="MoonCore.Blazor" Version="1.2.8" />
|
||||||
<PackageReference Include="MoonCore.PluginFramework" Version="1.0.5"/>
|
<PackageReference Include="MoonCore.PluginFramework" Version="1.0.5"/>
|
||||||
<PackageReference Include="MoonCore.Blazor.Tailwind" Version="1.2.9" />
|
<PackageReference Include="MoonCore.Blazor.Tailwind" Version="1.3.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
|
|||||||
@@ -304,6 +304,7 @@
|
|||||||
"px-5",
|
"px-5",
|
||||||
"px-6",
|
"px-6",
|
||||||
"py-1",
|
"py-1",
|
||||||
|
"py-1.5",
|
||||||
"py-10",
|
"py-10",
|
||||||
"py-2",
|
"py-2",
|
||||||
"py-3",
|
"py-3",
|
||||||
|
|||||||
70
Moonlight.Client/UI/Views/Admin/Api/Create.razor
Normal file
70
Moonlight.Client/UI/Views/Admin/Api/Create.razor
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
@page "/admin/api/create"
|
||||||
|
|
||||||
|
@using MoonCore.Helpers
|
||||||
|
@using Moonlight.Shared.Http.Requests.Admin.ApiKeys
|
||||||
|
@using Moonlight.Shared.Http.Responses.Admin.ApiKeys
|
||||||
|
|
||||||
|
@inject HttpApiClient ApiClient
|
||||||
|
@inject NavigationManager Navigation
|
||||||
|
@inject ToastService ToastService
|
||||||
|
@inject AlertService AlertService
|
||||||
|
|
||||||
|
<PageHeader Title="Create API Key">
|
||||||
|
<a href="/admin/api" class="btn btn-secondary">
|
||||||
|
<i class="icon-chevron-left mr-1"></i>
|
||||||
|
Back
|
||||||
|
</a>
|
||||||
|
<WButton OnClick="_ => Form.Submit()" CssClasses="btn btn-primary">
|
||||||
|
<i class="icon-check mr-1"></i>
|
||||||
|
Create
|
||||||
|
</WButton>
|
||||||
|
</PageHeader>
|
||||||
|
|
||||||
|
<div class="mt-5">
|
||||||
|
<HandleForm @ref="Form" Model="Request" OnValidSubmit="OnSubmit">
|
||||||
|
<div class="grid grid-cols-1 gap-x-6 gap-y-8 sm:grid-cols-6">
|
||||||
|
<div class="sm:col-span-2">
|
||||||
|
<label class="block text-sm font-medium leading-6 text-white">Description</label>
|
||||||
|
<div class="mt-2">
|
||||||
|
<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>
|
||||||
|
|
||||||
|
@code
|
||||||
|
{
|
||||||
|
private HandleForm Form;
|
||||||
|
private CreateApiKeyRequest Request;
|
||||||
|
|
||||||
|
protected override void OnInitialized()
|
||||||
|
{
|
||||||
|
Request = new();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task OnSubmit()
|
||||||
|
{
|
||||||
|
var response = await ApiClient.PostJson<CreateApiKeyResponse>("api/admin/apikeys", Request);
|
||||||
|
|
||||||
|
await AlertService.Success(
|
||||||
|
"API Key successfully created",
|
||||||
|
$"Copy the following secret. It wont be shown again. '{response.Secret}'"
|
||||||
|
);
|
||||||
|
|
||||||
|
await ToastService.Success("Successfully created api key");
|
||||||
|
Navigation.NavigateTo("/admin/api");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,15 +1,13 @@
|
|||||||
@page "/admin/api"
|
@page "/admin/api"
|
||||||
@*
|
|
||||||
@using MoonCore.Attributes
|
|
||||||
@using MoonCore.Helpers
|
@using MoonCore.Helpers
|
||||||
@using MoonCore.Models
|
@using MoonCore.Models
|
||||||
@using Moonlight.Shared.Http.Requests.Admin.ApiKeys
|
@using MoonCore.Blazor.Tailwind.Dt
|
||||||
@using Moonlight.Shared.Http.Responses.Admin.ApiKeys
|
@using Moonlight.Shared.Http.Responses.Admin.ApiKeys
|
||||||
|
|
||||||
@attribute [RequirePermission("admin.apikeys.read")]
|
@inject HttpApiClient ApiClient
|
||||||
|
|
||||||
@inject HttpApiClient HttpApiClient
|
|
||||||
@inject AlertService AlertService
|
@inject AlertService AlertService
|
||||||
|
@inject ToastService ToastService
|
||||||
|
|
||||||
<div class="grid grid-cols-1 sm:grid-cols-3 mb-8 gap-x-3">
|
<div class="grid grid-cols-1 sm:grid-cols-3 mb-8 gap-x-3">
|
||||||
<div class="col-span-1 card card-body border-l-4 border-primary-500">
|
<div class="col-span-1 card card-body border-l-4 border-primary-500">
|
||||||
@@ -49,63 +47,57 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Crud TItem="ApiKeyDetailResponse"
|
<div class="mb-5 flex justify-end">
|
||||||
TCreateForm="CreateApiKeyRequest"
|
<a href="/admin/api/create" class="btn btn-primary">
|
||||||
TUpdateForm="UpdateApiKeyRequest"
|
Create
|
||||||
OnConfigure="OnConfigure">
|
</a>
|
||||||
<View>
|
</div>
|
||||||
<Column TItem="ApiKeyDetailResponse" Field="@(x => x.Id)" Title="Id"/>
|
|
||||||
<Column TItem="ApiKeyDetailResponse" Field="@(x => x.Description)" Title="Description"/>
|
<DataTable @ref="Table" TItem="ApiKeyDetailResponse" PageSize="15" LoadItemsPaginatedAsync="LoadData">
|
||||||
<Column TItem="ApiKeyDetailResponse" Field="@(x => x.ExpiresAt)" Title="Expires at">
|
<Configuration>
|
||||||
<Template>
|
<DataTableColumn TItem="ApiKeyDetailResponse" Field="@(x => x.Id)" Name="Id" />
|
||||||
@Formatter.FormatDate(context.ExpiresAt)
|
<DataTableColumn TItem="ApiKeyDetailResponse" Field="@(x => x.Description)" Name="Description" />
|
||||||
</Template>
|
<DataTableColumn TItem="ApiKeyDetailResponse" Field="@(x => x.ExpiresAt)" Name="Expires at">
|
||||||
</Column>
|
<ColumnTemplate>
|
||||||
</View>
|
@(Formatter.FormatDate(context.ExpiresAt))
|
||||||
</Crud>
|
</ColumnTemplate>
|
||||||
|
</DataTableColumn>
|
||||||
|
<DataTableColumn TItem="ApiKeyDetailResponse">
|
||||||
|
<ColumnTemplate>
|
||||||
|
<div class="flex justify-end">
|
||||||
|
<a href="/admin/api/update/@(context.Id)" class="text-primary-500 mr-2 sm:mr-3">
|
||||||
|
<i class="icon-pencil text-base"></i>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<a href="#" @onclick="() => Delete(context)" @onclick:preventDefault
|
||||||
|
class="text-danger-500">
|
||||||
|
<i class="icon-trash text-base"></i>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</ColumnTemplate>
|
||||||
|
</DataTableColumn>
|
||||||
|
</Configuration>
|
||||||
|
</DataTable>
|
||||||
|
|
||||||
@code
|
@code
|
||||||
{
|
{
|
||||||
private void OnConfigure(CrudOptions<ApiKeyDetailResponse, CreateApiKeyRequest, UpdateApiKeyRequest> crudOptions)
|
private DataTable<ApiKeyDetailResponse> Table;
|
||||||
|
|
||||||
|
private async Task<IPagedData<ApiKeyDetailResponse>> LoadData(PaginationOptions options)
|
||||||
|
=> await ApiClient.GetJson<PagedData<ApiKeyDetailResponse>>($"api/admin/apikeys?page={options.Page}&pageSize={options.PerPage}");
|
||||||
|
|
||||||
|
private async Task Delete(ApiKeyDetailResponse apiKeyDetailResponse)
|
||||||
{
|
{
|
||||||
crudOptions.ItemName = "API Key";
|
await AlertService.ConfirmDanger(
|
||||||
|
"API Key deletion",
|
||||||
crudOptions.ItemLoader = async (page, pageSize)
|
$"Do you really want to delete the api key '{apiKeyDetailResponse.Description}'",
|
||||||
=> await HttpApiClient.GetJson<PagedData<ApiKeyDetailResponse>>($"api/admin/apikeys?page={page}&pageSize={pageSize}");
|
async () =>
|
||||||
|
|
||||||
crudOptions.SingleItemLoader = async id
|
|
||||||
=> await HttpApiClient.GetJson<ApiKeyDetailResponse>($"api/admin/apikeys/{id}");
|
|
||||||
|
|
||||||
crudOptions.QueryIdentifier = response => response.Id.ToString();
|
|
||||||
|
|
||||||
crudOptions.OnCreate = async request =>
|
|
||||||
{
|
{
|
||||||
var response = await HttpApiClient.PostJson<CreateApiKeyResponse>("api/admin/apikeys", request);
|
await ApiClient.Delete($"api/admin/apikeys/{apiKeyDetailResponse.Id}");
|
||||||
|
await ToastService.Success("Successfully deleted api key");
|
||||||
|
|
||||||
await AlertService.Success(
|
await Table.Refresh();
|
||||||
"API Key successfully created",
|
}
|
||||||
$"Copy the following secret. It wont be shown again. '{response.Secret}'"
|
);
|
||||||
);
|
}
|
||||||
};
|
|
||||||
|
|
||||||
crudOptions.OnUpdate = async (item, request)
|
|
||||||
=> await HttpApiClient.Patch($"api/admin/apikeys/{item.Id}", request);
|
|
||||||
|
|
||||||
crudOptions.OnDelete = async item
|
|
||||||
=> await HttpApiClient.Delete($"api/admin/apikeys/{item.Id}");
|
|
||||||
|
|
||||||
crudOptions.OnConfigureCreate = configuration =>
|
|
||||||
{
|
|
||||||
configuration.WithField(x => x.Description);
|
|
||||||
configuration.WithField(x => x.PermissionsJson);
|
|
||||||
configuration.WithField(x => x.ExpiresAt, fieldConfiguration => { fieldConfiguration.DefaultValue = DateTime.UtcNow.AddMonths(1); });
|
|
||||||
};
|
|
||||||
|
|
||||||
crudOptions.OnConfigureUpdate = (_, configuration) =>
|
|
||||||
{
|
|
||||||
configuration.WithField(x => x.Description);
|
|
||||||
configuration.WithField(x => x.PermissionsJson);
|
|
||||||
configuration.WithField(x => x.ExpiresAt);
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}*@
|
|
||||||
69
Moonlight.Client/UI/Views/Admin/Api/Update.razor
Normal file
69
Moonlight.Client/UI/Views/Admin/Api/Update.razor
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
@page "/admin/api/update/{Id:int}"
|
||||||
|
|
||||||
|
@using MoonCore.Helpers
|
||||||
|
@using Moonlight.Shared.Http.Requests.Admin.ApiKeys
|
||||||
|
@using Moonlight.Shared.Http.Responses.Admin.ApiKeys
|
||||||
|
|
||||||
|
@inject HttpApiClient ApiClient
|
||||||
|
@inject NavigationManager Navigation
|
||||||
|
@inject ToastService ToastService
|
||||||
|
|
||||||
|
<LazyLoader Load="Load">
|
||||||
|
<PageHeader Title="Update API Key">
|
||||||
|
<a href="/admin/api" class="btn btn-secondary">
|
||||||
|
<i class="icon-chevron-left mr-1"></i>
|
||||||
|
Back
|
||||||
|
</a>
|
||||||
|
<WButton OnClick="_ => Form.Submit()" CssClasses="btn btn-primary">
|
||||||
|
<i class="icon-check mr-1"></i>
|
||||||
|
Update
|
||||||
|
</WButton>
|
||||||
|
</PageHeader>
|
||||||
|
|
||||||
|
<div class="mt-5">
|
||||||
|
<HandleForm @ref="Form" Model="Request" OnValidSubmit="OnSubmit">
|
||||||
|
<div class="grid grid-cols-1 gap-x-6 gap-y-8 sm:grid-cols-6">
|
||||||
|
<div class="sm:col-span-2">
|
||||||
|
<label class="block text-sm font-medium leading-6 text-white">Description</label>
|
||||||
|
<div class="mt-2">
|
||||||
|
<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>
|
||||||
|
</LazyLoader>
|
||||||
|
|
||||||
|
@code
|
||||||
|
{
|
||||||
|
[Parameter] public int Id { get; set; }
|
||||||
|
|
||||||
|
private HandleForm Form;
|
||||||
|
private UpdateApiKeyRequest Request;
|
||||||
|
|
||||||
|
private async Task Load(LazyLoader _)
|
||||||
|
{
|
||||||
|
var detail = await ApiClient.GetJson<ApiKeyDetailResponse>($"api/admin/apikeys/{Id}");
|
||||||
|
Request = Mapper.Map<UpdateApiKeyRequest>(detail);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task OnSubmit()
|
||||||
|
{
|
||||||
|
await ApiClient.Patch($"api/admin/apikeys/{Id}", Request);
|
||||||
|
|
||||||
|
await ToastService.Success("Successfully updated api key");
|
||||||
|
Navigation.NavigateTo("/admin/api");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -22,25 +22,25 @@
|
|||||||
<HandleForm @ref="Form" Model="Request" OnValidSubmit="OnSubmit">
|
<HandleForm @ref="Form" Model="Request" OnValidSubmit="OnSubmit">
|
||||||
<div class="grid grid-cols-1 gap-x-6 gap-y-8 sm:grid-cols-6">
|
<div class="grid grid-cols-1 gap-x-6 gap-y-8 sm:grid-cols-6">
|
||||||
<div class="sm:col-span-2">
|
<div class="sm:col-span-2">
|
||||||
<label class="block text-sm font-medium leading-6 text-white">Name</label>
|
<label class="block text-sm font-medium leading-6 text-white">Username</label>
|
||||||
<div class="mt-2">
|
<div class="mt-2">
|
||||||
<input @bind="Request.Username" type="text" autocomplete="off" class="form-input w-full">
|
<input @bind="Request.Username" type="text" autocomplete="off" class="form-input w-full">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="sm:col-span-2">
|
<div class="sm:col-span-2">
|
||||||
<label class="block text-sm font-medium leading-6 text-white">Version</label>
|
<label class="block text-sm font-medium leading-6 text-white">Email</label>
|
||||||
<div class="mt-2">
|
<div class="mt-2">
|
||||||
<input @bind="Request.Email" type="email" autocomplete="off" class="form-input w-full">
|
<input @bind="Request.Email" type="email" autocomplete="off" class="form-input w-full">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="sm:col-span-2">
|
<div class="sm:col-span-2">
|
||||||
<label class="block text-sm font-medium leading-6 text-white">Author</label>
|
<label class="block text-sm font-medium leading-6 text-white">Password</label>
|
||||||
<div class="mt-2">
|
<div class="mt-2">
|
||||||
<input @bind="Request.Password" type="password" autocomplete="off" class="form-input w-full">
|
<input @bind="Request.Password" type="password" autocomplete="off" class="form-input w-full">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="sm:col-span-2">
|
<div class="sm:col-span-2">
|
||||||
<label class="block text-sm font-medium leading-6 text-white">Donate Url</label>
|
<label class="block text-sm font-medium leading-6 text-white">Permissions</label>
|
||||||
<div class="mt-2">
|
<div class="mt-2">
|
||||||
<input @bind="Request.PermissionsJson" type="text" autocomplete="off" class="form-input w-full">
|
<input @bind="Request.PermissionsJson" type="text" autocomplete="off" class="form-input w-full">
|
||||||
</div>
|
</div>
|
||||||
@@ -61,9 +61,9 @@
|
|||||||
|
|
||||||
private async Task OnSubmit()
|
private async Task OnSubmit()
|
||||||
{
|
{
|
||||||
await ApiClient.Post("api/users", Request);
|
await ApiClient.Post("api/admin/users", Request);
|
||||||
|
|
||||||
await ToastService.Success("Successfully created User");
|
await ToastService.Success("Successfully created user");
|
||||||
Navigation.NavigateTo("/admin/users");
|
Navigation.NavigateTo("/admin/users");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -9,9 +9,16 @@
|
|||||||
@inject AlertService AlertService
|
@inject AlertService AlertService
|
||||||
@inject ToastService ToastService
|
@inject ToastService ToastService
|
||||||
|
|
||||||
<PageHeader Title="Users" />
|
<div class="mb-5">
|
||||||
|
<PageHeader Title="Users">
|
||||||
|
<a href="/admin/api/create" class="btn btn-primary">
|
||||||
|
Create
|
||||||
|
</a>
|
||||||
|
</PageHeader>
|
||||||
|
</div>
|
||||||
|
|
||||||
<DataTable @ref="Table" TItem="UserDetailResponse" PageSize="15" LoadItemsPaginatedAsync="LoadData">
|
<DataTable @ref="Table" TItem="UserDetailResponse" PageSize="15" LoadItemsPaginatedAsync="LoadData">
|
||||||
|
<Configuration>
|
||||||
<DataTableColumn TItem="UserDetailResponse" Field="@(x => x.Id)" Name="Id" />
|
<DataTableColumn TItem="UserDetailResponse" Field="@(x => x.Id)" Name="Id" />
|
||||||
<DataTableColumn TItem="UserDetailResponse" Field="@(x => x.Username)" Name="Username" />
|
<DataTableColumn TItem="UserDetailResponse" Field="@(x => x.Username)" Name="Username" />
|
||||||
<DataTableColumn TItem="UserDetailResponse" Field="@(x => x.Email)" Name="Email" />
|
<DataTableColumn TItem="UserDetailResponse" Field="@(x => x.Email)" Name="Email" />
|
||||||
@@ -29,6 +36,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</ColumnTemplate>
|
</ColumnTemplate>
|
||||||
</DataTableColumn>
|
</DataTableColumn>
|
||||||
|
</Configuration>
|
||||||
</DataTable>
|
</DataTable>
|
||||||
|
|
||||||
@code
|
@code
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
@page "/users/update/{Id:int}"
|
@page "/admin/users/update/{Id:int}"
|
||||||
|
|
||||||
@using MoonCore.Helpers
|
@using MoonCore.Helpers
|
||||||
@using Moonlight.Shared.Http.Requests.Admin.Users
|
@using Moonlight.Shared.Http.Requests.Admin.Users
|
||||||
@@ -24,19 +24,19 @@
|
|||||||
<HandleForm @ref="Form" Model="Request" OnValidSubmit="OnSubmit">
|
<HandleForm @ref="Form" Model="Request" OnValidSubmit="OnSubmit">
|
||||||
<div class="grid grid-cols-1 gap-x-6 gap-y-8 sm:grid-cols-6">
|
<div class="grid grid-cols-1 gap-x-6 gap-y-8 sm:grid-cols-6">
|
||||||
<div class="sm:col-span-2">
|
<div class="sm:col-span-2">
|
||||||
<label class="block text-sm font-medium leading-6 text-white">Name</label>
|
<label class="block text-sm font-medium leading-6 text-white">Username</label>
|
||||||
<div class="mt-2">
|
<div class="mt-2">
|
||||||
<input @bind="Request.Username" type="text" autocomplete="off" class="form-input w-full">
|
<input @bind="Request.Username" type="text" autocomplete="off" class="form-input w-full">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="sm:col-span-2">
|
<div class="sm:col-span-2">
|
||||||
<label class="block text-sm font-medium leading-6 text-white">Version</label>
|
<label class="block text-sm font-medium leading-6 text-white">Email</label>
|
||||||
<div class="mt-2">
|
<div class="mt-2">
|
||||||
<input @bind="Request.Email" type="email" autocomplete="off" class="form-input w-full">
|
<input @bind="Request.Email" type="email" autocomplete="off" class="form-input w-full">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="sm:col-span-2">
|
<div class="sm:col-span-2">
|
||||||
<label class="block text-sm font-medium leading-6 text-white">Author</label>
|
<label class="block text-sm font-medium leading-6 text-white">Password</label>
|
||||||
<div class="mt-2">
|
<div class="mt-2">
|
||||||
<input @bind="Request.Password" type="password" autocomplete="off" class="form-input w-full">
|
<input @bind="Request.Password" type="password" autocomplete="off" class="form-input w-full">
|
||||||
</div>
|
</div>
|
||||||
@@ -55,7 +55,7 @@
|
|||||||
|
|
||||||
private async Task Load(LazyLoader _)
|
private async Task Load(LazyLoader _)
|
||||||
{
|
{
|
||||||
var detail = await ApiClient.GetJson<UserDetailResponse>($"api/users/{Id}");
|
var detail = await ApiClient.GetJson<UserDetailResponse>($"api/admin/users/{Id}");
|
||||||
Request = Mapper.Map<UpdateUserRequest>(detail);
|
Request = Mapper.Map<UpdateUserRequest>(detail);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,7 +63,7 @@
|
|||||||
{
|
{
|
||||||
await ApiClient.Patch($"api/admin/users/{Id}", Request);
|
await ApiClient.Patch($"api/admin/users/{Id}", Request);
|
||||||
|
|
||||||
await ToastService.Success("Successfully updated User");
|
await ToastService.Success("Successfully updated user");
|
||||||
Navigation.NavigateTo("/admin/users");
|
Navigation.NavigateTo("/admin/users");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -11,5 +11,5 @@ public class CreateApiKeyRequest
|
|||||||
public string PermissionsJson { get; set; } = "[]";
|
public string PermissionsJson { get; set; } = "[]";
|
||||||
|
|
||||||
[Required(ErrorMessage = "You need to specify an expire date")]
|
[Required(ErrorMessage = "You need to specify an expire date")]
|
||||||
public DateTime ExpiresAt { get; set; }
|
public DateTime ExpiresAt { get; set; } = DateTime.Now.AddDays(30);
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user