Major refactor and reorganization of types (#652)

* Start of reorganization and cleanup

* Remove duplicate title id

* Refactor types

* Fix Release building

* Move classes in /Types to a Types namespace

* Fix compilation error (RoomVisualizerPage strikes again)

* Fix bugs created from auto merge

* Fix auto-merge compilation error

* Changes from review/fix failed merge
This commit is contained in:
Josh 2023-02-13 22:02:58 -06:00 committed by GitHub
parent c8120b3388
commit f1c5ad4002
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
316 changed files with 1623 additions and 1518 deletions

View file

@ -0,0 +1,42 @@
using LBPUnion.ProjectLighthouse.Servers.Website.Pages.Layouts;
using LBPUnion.ProjectLighthouse.Types.Entities.Profile;
using LBPUnion.ProjectLighthouse.Types.Entities.Token;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
namespace LBPUnion.ProjectLighthouse.Servers.Website.Pages.Admin;
public class AdminApiKeyPageModel : BaseLayout
{
public List<ApiKey> ApiKeys = new();
public int KeyCount;
public AdminApiKeyPageModel(Database database) : base(database)
{ }
public async Task<IActionResult> OnGet()
{
User? user = this.Database.UserFromWebRequest(this.Request);
if (user == null) return this.Redirect("~/login");
if (!user.IsAdmin) return this.NotFound();
this.ApiKeys = await this.Database.APIKeys.OrderByDescending(k => k.Id).ToListAsync();
this.KeyCount = this.ApiKeys.Count;
return this.Page();
}
public async Task<IActionResult> OnPost(string keyId)
{
User? user = this.Database.UserFromWebRequest(this.Request);
if (user == null || !user.IsAdmin) return this.NotFound();
ApiKey? apiKey = await this.Database.APIKeys.FirstOrDefaultAsync(k => k.Id == int.Parse(keyId));
if (apiKey == null) return this.NotFound();
this.Database.APIKeys.Remove(apiKey);
await this.Database.SaveChangesAsync();
return this.Page();
}
}