mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-05-18 07:32:27 +00:00
* Added user invite system * Added user invite system * Revert recent migrations and try again * stopped implicitly assigning token variables * Added correct context to migrations * Apply suggestions from code review Some grammar changes, etc. Co-authored-by: Jayden <jvyden@jvyden.xyz> * Updated the API key page * Removed enabled field from APIKey * Removed reference to APIKey.Enabled * Add creation guide text * Fix this.Forbid() usage Causes an exception on my machine for some reason, always has. * Fix more forbid usages * Return 404 if trying to generate token when private registration is disabled * Capture authentication schema more cleanly Co-authored-by: Jayden <jvyden@jvyden.xyz>
43 lines
1.5 KiB
C#
43 lines
1.5 KiB
C#
using LBPUnion.ProjectLighthouse.Servers.Website.Pages.Layouts;
|
|
using LBPUnion.ProjectLighthouse.PlayerData;
|
|
using LBPUnion.ProjectLighthouse.PlayerData.Profiles;
|
|
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();
|
|
}
|
|
|
|
}
|
|
}
|