ProjectLighthouse/ProjectLighthouse.Servers.Website/Pages/Admin/AdminPanelPage.cshtml.cs
Zaprit ce0fe9edee
Added user invite system (#351)
* 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>
2022-07-24 02:43:00 +00:00

59 lines
No EOL
2.3 KiB
C#

#nullable enable
using LBPUnion.ProjectLighthouse.Administration;
using LBPUnion.ProjectLighthouse.Administration.Maintenance;
using LBPUnion.ProjectLighthouse.Extensions;
using LBPUnion.ProjectLighthouse.Helpers;
using LBPUnion.ProjectLighthouse.Logging;
using LBPUnion.ProjectLighthouse.PlayerData.Profiles;
using LBPUnion.ProjectLighthouse.Servers.Website.Pages.Layouts;
using LBPUnion.ProjectLighthouse.Types;
using Microsoft.AspNetCore.Mvc;
namespace LBPUnion.ProjectLighthouse.Servers.Website.Pages.Admin;
public class AdminPanelPage : BaseLayout
{
public List<ICommand> Commands = MaintenanceHelper.Commands;
public AdminPanelPage(Database database) : base(database)
{ }
public List<AdminPanelStatistic> Statistics = new();
public string? Log;
public async Task<IActionResult> OnGet([FromQuery] string? args, [FromQuery] string? command, [FromQuery] string? maintenanceJob, [FromQuery] string? log)
{
User? user = this.Database.UserFromWebRequest(this.Request);
if (user == null) return this.Redirect("~/login");
if (!user.IsAdmin) return this.NotFound();
this.Statistics.Add(new AdminPanelStatistic("Users", await StatisticsHelper.UserCount(), "users"));
this.Statistics.Add(new AdminPanelStatistic("Slots", await StatisticsHelper.SlotCount()));
this.Statistics.Add(new AdminPanelStatistic("Photos", await StatisticsHelper.PhotoCount()));
this.Statistics.Add(new AdminPanelStatistic("Reports", await StatisticsHelper.ReportCount(), "reports/0"));
this.Statistics.Add(new AdminPanelStatistic("API Keys", await StatisticsHelper.APIKeyCount(), "keys"));
if (!string.IsNullOrEmpty(command))
{
args ??= "";
args = command + " " + args;
string[] split = args.Split(" ");
List<LogLine> runCommand = await MaintenanceHelper.RunCommand(split);
return this.Redirect($"~/admin?log={CryptoHelper.ToBase64(runCommand.ToLogString())}");
}
if (!string.IsNullOrEmpty(maintenanceJob))
{
await MaintenanceHelper.RunMaintenanceJob(maintenanceJob);
return this.Redirect("~/admin");
}
if (!string.IsNullOrEmpty(log))
{
this.Log = CryptoHelper.FromBase64(log);
}
return this.Page();
}
}