mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-08-02 18:18:39 +00:00
Add users page to admin panel
This commit is contained in:
parent
bf3f04f277
commit
ddd3863708
4 changed files with 103 additions and 27 deletions
|
@ -8,6 +8,12 @@
|
|||
Model.Title = "Admin Panel";
|
||||
}
|
||||
|
||||
<a href="/admin/users">
|
||||
<div class="ui blue button">
|
||||
View Users
|
||||
</div>
|
||||
</a>
|
||||
|
||||
<h2>Commands</h2>
|
||||
<div class="ui grid">
|
||||
@foreach (ICommand command in MaintenanceHelper.Commands)
|
||||
|
|
|
@ -7,37 +7,35 @@ using LBPUnion.ProjectLighthouse.Pages.Layouts;
|
|||
using LBPUnion.ProjectLighthouse.Types;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace LBPUnion.ProjectLighthouse.Pages.Admin
|
||||
namespace LBPUnion.ProjectLighthouse.Pages.Admin;
|
||||
|
||||
public class AdminPanelPage : BaseLayout
|
||||
{
|
||||
public class AdminPanelPage : BaseLayout
|
||||
public List<ICommand> Commands = MaintenanceHelper.Commands;
|
||||
public AdminPanelPage(Database database) : base(database)
|
||||
{}
|
||||
|
||||
public async Task<IActionResult> OnGet([FromQuery] string? args, [FromQuery] string? command, [FromQuery] string? maintenanceJob)
|
||||
{
|
||||
User? user = this.Database.UserFromWebRequest(this.Request);
|
||||
if (user == null) return this.Redirect("~/login");
|
||||
if (!user.IsAdmin) return this.NotFound();
|
||||
|
||||
public List<ICommand> Commands = MaintenanceHelper.Commands;
|
||||
public AdminPanelPage(Database database) : base(database)
|
||||
{}
|
||||
|
||||
public async Task<IActionResult> OnGet([FromQuery] string? args, [FromQuery] string? command, [FromQuery] string? maintenanceJob)
|
||||
if (!string.IsNullOrEmpty(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 MaintenanceHelper.RunCommand(split);
|
||||
return this.Redirect("~/admin");
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(maintenanceJob))
|
||||
{
|
||||
await MaintenanceHelper.RunMaintenanceJob(maintenanceJob);
|
||||
return this.Redirect("~/admin");
|
||||
}
|
||||
|
||||
return this.Page();
|
||||
args ??= "";
|
||||
args = command + " " + args;
|
||||
string[] split = args.Split(" ");
|
||||
await MaintenanceHelper.RunCommand(split);
|
||||
return this.Redirect("~/admin");
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(maintenanceJob))
|
||||
{
|
||||
await MaintenanceHelper.RunMaintenanceJob(maintenanceJob);
|
||||
return this.Redirect("~/admin");
|
||||
}
|
||||
|
||||
return this.Page();
|
||||
}
|
||||
}
|
40
ProjectLighthouse/Pages/Admin/AdminPanelUsersPage.cshtml
Normal file
40
ProjectLighthouse/Pages/Admin/AdminPanelUsersPage.cshtml
Normal file
|
@ -0,0 +1,40 @@
|
|||
@page "/admin/users"
|
||||
@using LBPUnion.ProjectLighthouse.Types
|
||||
@model LBPUnion.ProjectLighthouse.Pages.Admin.AdminPanelUsersPage
|
||||
|
||||
@{
|
||||
Layout = "Layouts/BaseLayout";
|
||||
Model.Title = "Users";
|
||||
}
|
||||
|
||||
<p>There are currently @Model.UserCount users registered to your instance.</p>
|
||||
<p><b>Note:</b> Users are ordered by most-recent-first.</p>
|
||||
|
||||
<div class="ui grid">
|
||||
@foreach (User user in Model.Users)
|
||||
{
|
||||
string color = "blue";
|
||||
string subtitle = "User";
|
||||
if (user.IsAdmin)
|
||||
{
|
||||
color = "yellow";
|
||||
subtitle = "Admin";
|
||||
}
|
||||
if (user.Banned)
|
||||
{
|
||||
color = "red";
|
||||
subtitle = $"Banned user! Reason: {user.BannedReason}";
|
||||
}
|
||||
|
||||
subtitle += $" (id: {user.UserId})";
|
||||
|
||||
<div class="eight wide column">
|
||||
<div class="ui @color segment">
|
||||
<h2>
|
||||
<a href="/user/@user.UserId">@user.Username</a>
|
||||
</h2>
|
||||
<h3>@subtitle</h3>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
32
ProjectLighthouse/Pages/Admin/AdminPanelUsersPage.cshtml.cs
Normal file
32
ProjectLighthouse/Pages/Admin/AdminPanelUsersPage.cshtml.cs
Normal file
|
@ -0,0 +1,32 @@
|
|||
#nullable enable
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using LBPUnion.ProjectLighthouse.Pages.Layouts;
|
||||
using LBPUnion.ProjectLighthouse.Types;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace LBPUnion.ProjectLighthouse.Pages.Admin;
|
||||
|
||||
public class AdminPanelUsersPage : BaseLayout
|
||||
{
|
||||
public AdminPanelUsersPage(Database database) : base(database)
|
||||
{}
|
||||
|
||||
public int UserCount;
|
||||
|
||||
public List<User> Users;
|
||||
|
||||
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.Users = await this.Database.Users.OrderByDescending(u => u.UserId).ToListAsync();
|
||||
this.UserCount = this.Users.Count;
|
||||
|
||||
return this.Page();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue