mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-08-02 10:08:39 +00:00
Add admin panel page
This commit is contained in:
parent
cc2be73bb0
commit
f83325dc66
4 changed files with 72 additions and 3 deletions
|
@ -9,11 +9,11 @@ namespace LBPUnion.ProjectLighthouse.Helpers
|
|||
{
|
||||
public static class CommandHelper
|
||||
{
|
||||
private static List<ICommand> commands;
|
||||
public static List<ICommand> Commands { get; }
|
||||
|
||||
static CommandHelper()
|
||||
{
|
||||
commands = Assembly.GetExecutingAssembly()
|
||||
Commands = Assembly.GetExecutingAssembly()
|
||||
.GetTypes()
|
||||
.Where(t => t.GetInterfaces().Contains(typeof(ICommand)) && t.GetConstructor(Type.EmptyTypes) != null)
|
||||
.Select(t => Activator.CreateInstance(t) as ICommand)
|
||||
|
@ -34,7 +34,7 @@ namespace LBPUnion.ProjectLighthouse.Helpers
|
|||
string baseCmd = args[0];
|
||||
args = args.Skip(1).ToArray();
|
||||
|
||||
IEnumerable<ICommand> suitableCommands = commands.Where
|
||||
IEnumerable<ICommand> suitableCommands = Commands.Where
|
||||
(command => command.Aliases().Any(a => a.ToLower() == baseCmd.ToLower()))
|
||||
.Where(command => args.Length >= command.RequiredArgs());
|
||||
foreach (ICommand command in suitableCommands)
|
||||
|
|
27
ProjectLighthouse/Pages/AdminPanelPage.cshtml
Normal file
27
ProjectLighthouse/Pages/AdminPanelPage.cshtml
Normal file
|
@ -0,0 +1,27 @@
|
|||
@page "/admin"
|
||||
@using LBPUnion.ProjectLighthouse.CommandLine
|
||||
@model LBPUnion.ProjectLighthouse.Pages.AdminPanelPage
|
||||
|
||||
@{
|
||||
Layout = "Layouts/BaseLayout";
|
||||
}
|
||||
|
||||
<h1>Admin Panel</h1>
|
||||
|
||||
<div class="ui grid">
|
||||
@foreach (ICommand command in Model!.Commands)
|
||||
{
|
||||
<div class="four wide column">
|
||||
<div class="ui black segment">
|
||||
<h3>@command.Name()</h3>
|
||||
<form>
|
||||
<div class="ui input" style="width: 100%;">
|
||||
<input type="text" name="args" placeholder="Arguments">
|
||||
</div><br><br>
|
||||
<input type="text" name="command" style="display: none;" value="@command.FirstAlias">
|
||||
<input type="submit" value="Execute Command" class="ui green button" style="width: 100%;">
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
37
ProjectLighthouse/Pages/AdminPanelPage.cshtml.cs
Normal file
37
ProjectLighthouse/Pages/AdminPanelPage.cshtml.cs
Normal file
|
@ -0,0 +1,37 @@
|
|||
#nullable enable
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using LBPUnion.ProjectLighthouse.CommandLine;
|
||||
using LBPUnion.ProjectLighthouse.Helpers;
|
||||
using LBPUnion.ProjectLighthouse.Pages.Layouts;
|
||||
using LBPUnion.ProjectLighthouse.Types;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace LBPUnion.ProjectLighthouse.Pages
|
||||
{
|
||||
public class AdminPanelPage : BaseLayout
|
||||
{
|
||||
public AdminPanelPage(Database database) : base(database)
|
||||
{}
|
||||
|
||||
public List<ICommand> Commands = CommandHelper.Commands;
|
||||
|
||||
public async Task<IActionResult> OnGet([FromQuery] string? args, [FromQuery] string? command)
|
||||
{
|
||||
User? user = this.Database.UserFromWebRequest(this.Request);
|
||||
if (user == null) return this.Redirect("~/login");
|
||||
if (!user.IsAdmin) return this.NotFound();
|
||||
|
||||
if (!string.IsNullOrEmpty(command))
|
||||
{
|
||||
args ??= "";
|
||||
args = command + " " + args;
|
||||
string[] split = args.Split(" ");
|
||||
await CommandHelper.RunCommand(split);
|
||||
return this.Redirect("~/admin");
|
||||
}
|
||||
|
||||
return this.Page();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -16,6 +16,11 @@
|
|||
Model.NavigationItems.Add(new PageNavigationItem("Authentication", "/authentication", "key"));
|
||||
}
|
||||
Model.NavigationItemsRight.Add(new PageNavigationItem("Profile", "/user/" + Model.User.UserId, "user alternate"));
|
||||
|
||||
@if (Model.User.IsAdmin)
|
||||
{
|
||||
Model.NavigationItemsRight.Add(new PageNavigationItem("Admin Panel", "/admin", "cogs"));
|
||||
}
|
||||
Model.NavigationItemsRight.Add(new PageNavigationItem("Log out", "/logout", "user alternate slash")); // should always be last
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue