Pageing on CDN Assets Page, and Player management
This commit is contained in:
@@ -169,6 +169,27 @@ MINIO_USE_SSL=true</pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Browse Pagination -->
|
||||
@if (Model.BrowseTotalPages > 1)
|
||||
{
|
||||
<div class="p-4 border-t border-gray-700 flex items-center justify-between">
|
||||
<p class="text-sm text-gray-400">
|
||||
Showing @((Model.BrowsePage - 1) * Model.BrowsePageSize + 1)-@Math.Min(Model.BrowsePage * Model.BrowsePageSize, Model.AllFiles.Count) of @Model.AllFiles.Count files
|
||||
</p>
|
||||
<div class="flex items-center gap-2">
|
||||
@if (Model.BrowsePage > 1)
|
||||
{
|
||||
<a href="@Model.GetBrowsePageUrl(Model.BrowsePage - 1)" class="btn btn-secondary">← Prev</a>
|
||||
}
|
||||
<span class="text-gray-400 px-2">@Model.BrowsePage / @Model.BrowseTotalPages</span>
|
||||
@if (Model.BrowsePage < Model.BrowseTotalPages)
|
||||
{
|
||||
<a href="@Model.GetBrowsePageUrl(Model.BrowsePage + 1)" class="btn btn-secondary">Next →</a>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
else if (!Model.Subfolders.Any())
|
||||
{
|
||||
|
||||
@@ -27,7 +27,16 @@ public class IndexModel : AdminPageModel
|
||||
public string? Prefix { get; set; }
|
||||
|
||||
public bool CdnConfigured => _cdnService.IsConfigured;
|
||||
public List<CdnFile> Files { get; set; } = new();
|
||||
// Browse tab pagination
|
||||
[FromQuery(Name = "bpage")]
|
||||
public int BrowsePage { get; set; } = 1;
|
||||
public int BrowsePageSize { get; set; } = 100;
|
||||
public int BrowseTotalPages => (int)Math.Ceiling(AllFiles.Count / (double)BrowsePageSize);
|
||||
public List<CdnFile> AllFiles { get; set; } = new();
|
||||
public List<CdnFile> Files => AllFiles
|
||||
.Skip((BrowsePage - 1) * BrowsePageSize)
|
||||
.Take(BrowsePageSize)
|
||||
.ToList();
|
||||
public List<string> Subfolders { get; set; } = new();
|
||||
public List<string> AvailableFolders { get; set; } = new()
|
||||
{
|
||||
@@ -67,6 +76,13 @@ public class IndexModel : AdminPageModel
|
||||
public string? Message { get; set; }
|
||||
public bool IsError { get; set; }
|
||||
|
||||
public string GetBrowsePageUrl(int page)
|
||||
{
|
||||
var parts = new List<string> { $"tab=browse", $"bpage={page}" };
|
||||
if (!string.IsNullOrEmpty(Prefix)) parts.Add($"prefix={Uri.EscapeDataString(Prefix)}");
|
||||
return "/admin/assets?" + string.Join("&", parts);
|
||||
}
|
||||
|
||||
public string GetTrackedPageUrl(int page)
|
||||
{
|
||||
var parts = new List<string> { $"tab=tracked", $"tpage={page}" };
|
||||
@@ -91,13 +107,15 @@ public class IndexModel : AdminPageModel
|
||||
|
||||
if (Tab == "browse" && CdnConfigured)
|
||||
{
|
||||
if (BrowsePage < 1) BrowsePage = 1;
|
||||
|
||||
// Normalize prefix
|
||||
Prefix = Prefix?.TrimEnd('/');
|
||||
if (!string.IsNullOrEmpty(Prefix))
|
||||
Prefix += "/";
|
||||
|
||||
// List files from MinIO
|
||||
var allItems = await _cdnService.ListFilesAsync(Prefix ?? "", 200);
|
||||
// List files from MinIO (increased limit)
|
||||
var allItems = await _cdnService.ListFilesAsync(Prefix ?? "", 100000);
|
||||
|
||||
// Separate files and folders
|
||||
Subfolders = allItems
|
||||
@@ -106,7 +124,7 @@ public class IndexModel : AdminPageModel
|
||||
.OrderBy(f => f)
|
||||
.ToList();
|
||||
|
||||
Files = allItems
|
||||
AllFiles = allItems
|
||||
.Where(f => !f.IsDirectory)
|
||||
.OrderBy(f => f.Name)
|
||||
.ToList();
|
||||
|
||||
@@ -174,6 +174,59 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Resistances -->
|
||||
<div class="card">
|
||||
<div class="p-4 border-b border-gray-700">
|
||||
<h2 class="text-lg font-semibold text-white">Damage Resistances</h2>
|
||||
<p class="text-sm text-gray-400 mt-1">Negative = weakness (takes more damage), Positive = resistance, 1.0 = immune</p>
|
||||
</div>
|
||||
<div class="p-6">
|
||||
<div class="grid grid-cols-2 md:grid-cols-4 gap-4">
|
||||
@foreach (var dt in Enum.GetValues<DamageType>())
|
||||
{
|
||||
var currentValue = Model.GetResistance(dt.ToString().ToLower());
|
||||
var bgColor = currentValue < 0 ? "bg-red-900/30 border-red-700" :
|
||||
currentValue > 0 ? "bg-green-900/30 border-green-700" :
|
||||
"bg-gray-800 border-gray-700";
|
||||
<div class="@bgColor border rounded-lg p-3">
|
||||
<label class="label text-sm mb-1">@dt</label>
|
||||
<div class="flex items-center gap-2">
|
||||
<input type="range"
|
||||
name="resistance_@dt.ToString().ToLower()"
|
||||
value="@currentValue"
|
||||
min="-1" max="1" step="0.1"
|
||||
class="flex-1"
|
||||
oninput="this.nextElementSibling.value = this.value; updateResistColor(this.parentElement.parentElement, this.value)" />
|
||||
<input type="number"
|
||||
value="@currentValue"
|
||||
min="-1" max="1" step="0.1"
|
||||
class="input w-20 text-center text-sm"
|
||||
oninput="this.previousElementSibling.value = this.value; updateResistColor(this.parentElement.parentElement, this.value)" />
|
||||
</div>
|
||||
<p class="text-xs text-gray-500 mt-1">
|
||||
@if (currentValue < 0)
|
||||
{
|
||||
<span class="text-red-400">+@((-currentValue * 100).ToString("0"))% damage taken</span>
|
||||
}
|
||||
else if (currentValue > 0 && currentValue < 1)
|
||||
{
|
||||
<span class="text-green-400">-@((currentValue * 100).ToString("0"))% damage taken</span>
|
||||
}
|
||||
else if (currentValue >= 1)
|
||||
{
|
||||
<span class="text-blue-400">Immune</span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span>Normal damage</span>
|
||||
}
|
||||
</p>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Visual -->
|
||||
<div class="card">
|
||||
<div class="p-4 border-b border-gray-700">
|
||||
|
||||
@@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Server.Data;
|
||||
using Server.Data.Entities;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace VoidScavengers.Services.Admin.Pages.Mobs;
|
||||
|
||||
@@ -23,6 +24,19 @@ public class EditModel : AdminPageModel
|
||||
public bool IsNew => Mob.Id == 0;
|
||||
public string? Message { get; set; }
|
||||
public bool IsError { get; set; }
|
||||
|
||||
// Helper to get resistance value for a damage type
|
||||
public float GetResistance(string damageType)
|
||||
{
|
||||
try
|
||||
{
|
||||
var resistances = JsonSerializer.Deserialize<Dictionary<string, float>>(Mob.ResistancesJson ?? "{}");
|
||||
if (resistances != null && resistances.TryGetValue(damageType, out var value))
|
||||
return value;
|
||||
}
|
||||
catch { }
|
||||
return 0f;
|
||||
}
|
||||
|
||||
public async Task OnGetAsync(int? id)
|
||||
{
|
||||
@@ -79,6 +93,18 @@ public class EditModel : AdminPageModel
|
||||
// Ensure nullable strings are never null
|
||||
Mob.Description ??= "";
|
||||
Mob.TintColor ??= "#ffffff";
|
||||
|
||||
// Parse resistances from form
|
||||
var resistances = new Dictionary<string, float>();
|
||||
foreach (var key in Request.Form.Keys.Where(k => k.StartsWith("resistance_")))
|
||||
{
|
||||
var damageType = key.Replace("resistance_", "");
|
||||
if (float.TryParse(Request.Form[key], out var value) && value != 0)
|
||||
{
|
||||
resistances[damageType] = value;
|
||||
}
|
||||
}
|
||||
Mob.ResistancesJson = JsonSerializer.Serialize(resistances);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(Mob.Name))
|
||||
{
|
||||
@@ -171,6 +197,7 @@ public class EditModel : AdminPageModel
|
||||
existing.Scale = Mob.Scale;
|
||||
existing.AnimationSpeed = Mob.AnimationSpeed;
|
||||
existing.SpriteConfigJson = Mob.SpriteConfigJson;
|
||||
existing.ResistancesJson = Mob.ResistancesJson;
|
||||
existing.IsEnabled = Mob.IsEnabled;
|
||||
|
||||
await _db.SaveChangesAsync();
|
||||
|
||||
@@ -0,0 +1,222 @@
|
||||
@page "/admin/players/edit"
|
||||
@model Players.EditModel
|
||||
@using Server.Data
|
||||
@{
|
||||
ViewData["Title"] = Model.IsNew ? "New Account" : $"Edit: {Model.Account.Username}";
|
||||
}
|
||||
|
||||
<div class="space-y-6">
|
||||
<!-- Header -->
|
||||
<div class="flex items-center justify-between">
|
||||
<div>
|
||||
<a href="/admin/players" class="text-gray-400 hover:text-white text-sm">← Back to Players</a>
|
||||
<h1 class="text-3xl font-bold text-white mt-2">@(Model.IsNew ? "New Account" : Model.Account.Username)</h1>
|
||||
@if (!Model.IsNew)
|
||||
{
|
||||
<p class="text-gray-400 mt-1">Account ID: @Model.Account.Id • Created: @Model.Account.CreatedAt.ToString("yyyy-MM-dd HH:mm")</p>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if (!string.IsNullOrEmpty(Model.Message))
|
||||
{
|
||||
<div class="p-4 rounded-lg @(Model.IsError ? "bg-red-900/50 border border-red-700 text-red-300" : "bg-green-900/50 border border-green-700 text-green-300")">
|
||||
@Model.Message
|
||||
</div>
|
||||
}
|
||||
|
||||
<div class="grid grid-cols-1 lg:grid-cols-2 gap-6">
|
||||
<!-- Account Info -->
|
||||
<div class="card p-6">
|
||||
<h2 class="text-lg font-semibold text-white mb-4">Account Information</h2>
|
||||
|
||||
<div class="space-y-4">
|
||||
<div>
|
||||
<label class="label">Username</label>
|
||||
<input type="text" value="@Model.Account.Username" class="input bg-gray-800" readonly />
|
||||
<p class="text-xs text-gray-500 mt-1">Username cannot be changed</p>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="label">Email</label>
|
||||
<input type="text" value="@(Model.Account.Email ?? "Not set")" class="input bg-gray-800" readonly />
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="label">Account Created</label>
|
||||
<input type="text" value="@Model.Account.CreatedAt.ToString("yyyy-MM-dd HH:mm:ss UTC")" class="input bg-gray-800" readonly />
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="label">Last Updated</label>
|
||||
<input type="text" value="@Model.Account.UpdatedAt.ToString("yyyy-MM-dd HH:mm:ss UTC")" class="input bg-gray-800" readonly />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Role Management -->
|
||||
<div class="card p-6">
|
||||
<h2 class="text-lg font-semibold text-white mb-4">Role Management</h2>
|
||||
|
||||
<form method="post" asp-page-handler="SetRole" class="space-y-4">
|
||||
@Html.AntiForgeryToken()
|
||||
<input type="hidden" name="accountId" value="@Model.Account.Id" />
|
||||
|
||||
<div>
|
||||
<label class="label">Current Role</label>
|
||||
@{
|
||||
var roleColor = Model.Account.Role switch
|
||||
{
|
||||
AccountRole.SuperAdmin => "bg-red-600",
|
||||
AccountRole.Admin => "bg-orange-600",
|
||||
AccountRole.Moderator => "bg-yellow-600",
|
||||
AccountRole.Vip => "bg-purple-600",
|
||||
_ => "bg-gray-600"
|
||||
};
|
||||
}
|
||||
<span class="inline-block px-3 py-1 text-sm rounded @roleColor text-white">@Model.Account.Role</span>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="label">Change Role To</label>
|
||||
<select name="newRole" class="input">
|
||||
@foreach (var r in Enum.GetValues<AccountRole>())
|
||||
{
|
||||
<option value="@r" selected="@(Model.Account.Role == r)">@r</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-primary w-full">Update Role</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<!-- Ban Management -->
|
||||
<div class="card p-6">
|
||||
<h2 class="text-lg font-semibold text-white mb-4">Ban Management</h2>
|
||||
|
||||
@{
|
||||
var isBanned = Model.Account.IsBanned || (Model.Account.BannedUntil.HasValue && Model.Account.BannedUntil > DateTime.UtcNow);
|
||||
}
|
||||
|
||||
<div class="mb-4">
|
||||
<label class="label">Current Status</label>
|
||||
@if (isBanned)
|
||||
{
|
||||
<div class="p-3 bg-red-900/30 border border-red-700 rounded">
|
||||
<span class="text-red-400 font-medium">BANNED</span>
|
||||
@if (Model.Account.IsBanned)
|
||||
{
|
||||
<span class="text-red-300 text-sm ml-2">(Permanent)</span>
|
||||
}
|
||||
else if (Model.Account.BannedUntil.HasValue)
|
||||
{
|
||||
<span class="text-red-300 text-sm ml-2">(Until @Model.Account.BannedUntil.Value.ToString("yyyy-MM-dd HH:mm UTC"))</span>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="p-3 bg-green-900/30 border border-green-700 rounded">
|
||||
<span class="text-green-400 font-medium">ACTIVE</span>
|
||||
<span class="text-green-300 text-sm ml-2">Account in good standing</span>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
@if (isBanned)
|
||||
{
|
||||
<form method="post" asp-page-handler="Unban">
|
||||
@Html.AntiForgeryToken()
|
||||
<input type="hidden" name="accountId" value="@Model.Account.Id" />
|
||||
<button type="submit" class="btn bg-green-700 hover:bg-green-600 text-white w-full">
|
||||
Remove Ban
|
||||
</button>
|
||||
</form>
|
||||
}
|
||||
else
|
||||
{
|
||||
<form method="post" asp-page-handler="Ban" class="space-y-4">
|
||||
@Html.AntiForgeryToken()
|
||||
<input type="hidden" name="accountId" value="@Model.Account.Id" />
|
||||
|
||||
<div>
|
||||
<label class="label">Ban Type</label>
|
||||
<select name="banType" class="input" id="banType" onchange="toggleBanDate()">
|
||||
<option value="permanent">Permanent Ban</option>
|
||||
<option value="temporary">Temporary Ban</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div id="banDateContainer" style="display: none;">
|
||||
<label class="label">Ban Until</label>
|
||||
<input type="datetime-local" name="bannedUntil" class="input" />
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn bg-red-700 hover:bg-red-600 text-white w-full">
|
||||
Ban Account
|
||||
</button>
|
||||
</form>
|
||||
}
|
||||
</div>
|
||||
|
||||
<!-- Password Reset -->
|
||||
<div class="card p-6">
|
||||
<h2 class="text-lg font-semibold text-white mb-4">Password Reset</h2>
|
||||
|
||||
<form method="post" asp-page-handler="ResetPassword" class="space-y-4">
|
||||
@Html.AntiForgeryToken()
|
||||
<input type="hidden" name="accountId" value="@Model.Account.Id" />
|
||||
|
||||
<div>
|
||||
<label class="label">New Password</label>
|
||||
<input type="password" name="newPassword" class="input" required minlength="6" placeholder="Enter new password..." />
|
||||
<p class="text-xs text-gray-500 mt-1">Minimum 6 characters</p>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="label">Confirm Password</label>
|
||||
<input type="password" name="confirmPassword" class="input" required minlength="6" placeholder="Confirm new password..." />
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-primary w-full" onclick="return confirm('Reset password for this account?')">
|
||||
Reset Password
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Characters Section -->
|
||||
@if (Model.Characters.Any())
|
||||
{
|
||||
<div class="card p-6">
|
||||
<h2 class="text-lg font-semibold text-white mb-4">Characters (@Model.Characters.Count)</h2>
|
||||
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
|
||||
@foreach (var character in Model.Characters)
|
||||
{
|
||||
<div class="bg-gray-800 rounded-lg p-4">
|
||||
<div class="flex items-center justify-between mb-2">
|
||||
<span class="text-white font-medium">@character.Name</span>
|
||||
<span class="text-xs text-gray-400">Lv @character.Level</span>
|
||||
</div>
|
||||
<div class="text-sm text-gray-400">
|
||||
<p>Gold: @character.Gold.ToString("N0")</p>
|
||||
<p>Created: @character.CreatedAt.ToString("yyyy-MM-dd")</p>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
@section Scripts {
|
||||
<script>
|
||||
function toggleBanDate() {
|
||||
const banType = document.getElementById('banType').value;
|
||||
const dateContainer = document.getElementById('banDateContainer');
|
||||
dateContainer.style.display = banType === 'temporary' ? 'block' : 'none';
|
||||
}
|
||||
</script>
|
||||
}
|
||||
@@ -0,0 +1,186 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Server.Data;
|
||||
using Server.Data.Entities;
|
||||
using Server.Services.Auth;
|
||||
|
||||
namespace VoidScavengers.Services.Admin.Pages.Players;
|
||||
|
||||
public class EditModel : AdminPageModel
|
||||
{
|
||||
private readonly GameDbContext _db;
|
||||
private readonly IPasswordHasher _passwordHasher;
|
||||
|
||||
public EditModel(GameDbContext db, IPasswordHasher passwordHasher)
|
||||
{
|
||||
_db = db;
|
||||
_passwordHasher = passwordHasher;
|
||||
}
|
||||
|
||||
public Account Account { get; set; } = new();
|
||||
public List<DungeonCharacter> Characters { get; set; } = new();
|
||||
|
||||
public bool IsNew => Account.Id == 0;
|
||||
public string? Message { get; set; }
|
||||
public bool IsError { get; set; }
|
||||
|
||||
public async Task<IActionResult> OnGetAsync(ulong? id)
|
||||
{
|
||||
if (!id.HasValue)
|
||||
{
|
||||
return RedirectToPage("/Players/Index");
|
||||
}
|
||||
|
||||
var account = await _db.Set<Account>().FirstOrDefaultAsync(a => a.Id == id.Value);
|
||||
if (account == null)
|
||||
{
|
||||
return RedirectToPage("/Players/Index");
|
||||
}
|
||||
|
||||
Account = account;
|
||||
|
||||
// Load characters
|
||||
Characters = await _db.DungeonCharacters
|
||||
.Where(c => c.AccountId == id.Value && !c.IsDeleted)
|
||||
.OrderByDescending(c => c.Level)
|
||||
.ToListAsync();
|
||||
|
||||
return Page();
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostSetRoleAsync(ulong accountId, AccountRole newRole)
|
||||
{
|
||||
var account = await _db.Set<Account>().FirstOrDefaultAsync(a => a.Id == accountId);
|
||||
if (account == null)
|
||||
{
|
||||
Message = "Account not found.";
|
||||
IsError = true;
|
||||
return RedirectToPage("/Players/Index");
|
||||
}
|
||||
|
||||
var oldRole = account.Role;
|
||||
account.Role = newRole;
|
||||
await _db.SaveChangesAsync();
|
||||
|
||||
Account = account;
|
||||
Characters = await _db.DungeonCharacters
|
||||
.Where(c => c.AccountId == accountId && !c.IsDeleted)
|
||||
.OrderByDescending(c => c.Level)
|
||||
.ToListAsync();
|
||||
|
||||
Message = $"Role changed from {oldRole} to {newRole}.";
|
||||
return Page();
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostBanAsync(ulong accountId, string banType, DateTime? bannedUntil)
|
||||
{
|
||||
var account = await _db.Set<Account>().FirstOrDefaultAsync(a => a.Id == accountId);
|
||||
if (account == null)
|
||||
{
|
||||
Message = "Account not found.";
|
||||
IsError = true;
|
||||
return RedirectToPage("/Players/Index");
|
||||
}
|
||||
|
||||
if (banType == "permanent")
|
||||
{
|
||||
account.IsBanned = true;
|
||||
account.BannedUntil = null;
|
||||
Message = "Account permanently banned.";
|
||||
}
|
||||
else if (banType == "temporary" && bannedUntil.HasValue)
|
||||
{
|
||||
account.IsBanned = false;
|
||||
account.BannedUntil = bannedUntil.Value.ToUniversalTime();
|
||||
Message = $"Account banned until {account.BannedUntil.Value:yyyy-MM-dd HH:mm} UTC.";
|
||||
}
|
||||
else
|
||||
{
|
||||
Message = "Invalid ban parameters.";
|
||||
IsError = true;
|
||||
}
|
||||
|
||||
await _db.SaveChangesAsync();
|
||||
|
||||
Account = account;
|
||||
Characters = await _db.DungeonCharacters
|
||||
.Where(c => c.AccountId == accountId && !c.IsDeleted)
|
||||
.OrderByDescending(c => c.Level)
|
||||
.ToListAsync();
|
||||
|
||||
return Page();
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostUnbanAsync(ulong accountId)
|
||||
{
|
||||
var account = await _db.Set<Account>().FirstOrDefaultAsync(a => a.Id == accountId);
|
||||
if (account == null)
|
||||
{
|
||||
Message = "Account not found.";
|
||||
IsError = true;
|
||||
return RedirectToPage("/Players/Index");
|
||||
}
|
||||
|
||||
account.IsBanned = false;
|
||||
account.BannedUntil = null;
|
||||
await _db.SaveChangesAsync();
|
||||
|
||||
Account = account;
|
||||
Characters = await _db.DungeonCharacters
|
||||
.Where(c => c.AccountId == accountId && !c.IsDeleted)
|
||||
.OrderByDescending(c => c.Level)
|
||||
.ToListAsync();
|
||||
|
||||
Message = "Ban removed. Account is now active.";
|
||||
return Page();
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostResetPasswordAsync(ulong accountId, string newPassword, string confirmPassword)
|
||||
{
|
||||
var account = await _db.Set<Account>().FirstOrDefaultAsync(a => a.Id == accountId);
|
||||
if (account == null)
|
||||
{
|
||||
Message = "Account not found.";
|
||||
IsError = true;
|
||||
return RedirectToPage("/Players/Index");
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(newPassword) || newPassword.Length < 6)
|
||||
{
|
||||
Account = account;
|
||||
Characters = await _db.DungeonCharacters
|
||||
.Where(c => c.AccountId == accountId && !c.IsDeleted)
|
||||
.OrderByDescending(c => c.Level)
|
||||
.ToListAsync();
|
||||
Message = "Password must be at least 6 characters.";
|
||||
IsError = true;
|
||||
return Page();
|
||||
}
|
||||
|
||||
if (newPassword != confirmPassword)
|
||||
{
|
||||
Account = account;
|
||||
Characters = await _db.DungeonCharacters
|
||||
.Where(c => c.AccountId == accountId && !c.IsDeleted)
|
||||
.OrderByDescending(c => c.Level)
|
||||
.ToListAsync();
|
||||
Message = "Passwords do not match.";
|
||||
IsError = true;
|
||||
return Page();
|
||||
}
|
||||
|
||||
_passwordHasher.Hash(newPassword, out var hash, out var salt);
|
||||
account.PasswordHash = hash;
|
||||
account.PasswordSalt = salt;
|
||||
await _db.SaveChangesAsync();
|
||||
|
||||
Account = account;
|
||||
Characters = await _db.DungeonCharacters
|
||||
.Where(c => c.AccountId == accountId && !c.IsDeleted)
|
||||
.OrderByDescending(c => c.Level)
|
||||
.ToListAsync();
|
||||
|
||||
Message = "Password has been reset.";
|
||||
return Page();
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,167 @@
|
||||
@page "/admin/players"
|
||||
@model Players.IndexModel
|
||||
@using Server.Data
|
||||
@{
|
||||
ViewData["Title"] = "Players";
|
||||
}
|
||||
|
||||
<div class="space-y-6">
|
||||
<div>
|
||||
<h1 class="text-3xl font-bold text-white">Players</h1>
|
||||
<p class="text-gray-400 mt-1">Manage player accounts (@Model.PlayerCount total)</p>
|
||||
<!-- Header -->
|
||||
<div class="flex items-center justify-between">
|
||||
<div>
|
||||
<h1 class="text-3xl font-bold text-white">Players</h1>
|
||||
<p class="text-gray-400 mt-1">Manage player accounts</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card p-8 text-center">
|
||||
<p class="text-gray-400">Player management coming soon...</p>
|
||||
|
||||
<!-- Filters -->
|
||||
<div class="card p-4">
|
||||
<form method="get" class="flex flex-wrap items-end gap-4">
|
||||
<div class="flex-1 min-w-[200px]">
|
||||
<label class="label">Search</label>
|
||||
<input type="text" name="search" value="@Model.Search" class="input" placeholder="Username or email..." />
|
||||
</div>
|
||||
<div class="w-40">
|
||||
<label class="label">Role</label>
|
||||
<select name="role" class="input">
|
||||
<option value="">All Roles</option>
|
||||
@foreach (var r in Enum.GetValues<AccountRole>())
|
||||
{
|
||||
<option value="@r" selected="@(Model.RoleFilter == r)">@r</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
<div class="w-40">
|
||||
<label class="label">Status</label>
|
||||
<select name="status" class="input">
|
||||
<option value="">All</option>
|
||||
<option value="active" selected="@(Model.StatusFilter == "active")">Active</option>
|
||||
<option value="banned" selected="@(Model.StatusFilter == "banned")">Banned</option>
|
||||
</select>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-secondary">Filter</button>
|
||||
<a href="/admin/players" class="btn btn-secondary">Clear</a>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<!-- Stats -->
|
||||
<div class="grid grid-cols-2 md:grid-cols-4 gap-4">
|
||||
<div class="card p-4">
|
||||
<p class="text-2xl font-bold text-white">@Model.TotalCount</p>
|
||||
<p class="text-sm text-gray-400">Total Accounts</p>
|
||||
</div>
|
||||
<div class="card p-4">
|
||||
<p class="text-2xl font-bold text-green-400">@Model.ActiveCount</p>
|
||||
<p class="text-sm text-gray-400">Active</p>
|
||||
</div>
|
||||
<div class="card p-4">
|
||||
<p class="text-2xl font-bold text-red-400">@Model.BannedCount</p>
|
||||
<p class="text-sm text-gray-400">Banned</p>
|
||||
</div>
|
||||
<div class="card p-4">
|
||||
<p class="text-2xl font-bold text-indigo-400">@Model.AdminCount</p>
|
||||
<p class="text-sm text-gray-400">Admins</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Players Table -->
|
||||
<div class="card overflow-hidden">
|
||||
<table class="w-full">
|
||||
<thead class="bg-gray-800">
|
||||
<tr>
|
||||
<th class="px-4 py-3 text-left text-xs font-medium text-gray-400 uppercase">ID</th>
|
||||
<th class="px-4 py-3 text-left text-xs font-medium text-gray-400 uppercase">Username</th>
|
||||
<th class="px-4 py-3 text-left text-xs font-medium text-gray-400 uppercase">Email</th>
|
||||
<th class="px-4 py-3 text-left text-xs font-medium text-gray-400 uppercase">Role</th>
|
||||
<th class="px-4 py-3 text-left text-xs font-medium text-gray-400 uppercase">Status</th>
|
||||
<th class="px-4 py-3 text-left text-xs font-medium text-gray-400 uppercase">Created</th>
|
||||
<th class="px-4 py-3 text-right text-xs font-medium text-gray-400 uppercase">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="divide-y divide-gray-700">
|
||||
@foreach (var account in Model.Accounts)
|
||||
{
|
||||
var isBanned = account.IsBanned || (account.BannedUntil.HasValue && account.BannedUntil > DateTime.UtcNow);
|
||||
<tr class="hover:bg-gray-800/50">
|
||||
<td class="px-4 py-3 text-sm text-gray-400">@account.Id</td>
|
||||
<td class="px-4 py-3">
|
||||
<span class="text-white font-medium">@account.Username</span>
|
||||
</td>
|
||||
<td class="px-4 py-3 text-sm text-gray-400">@(account.Email ?? "-")</td>
|
||||
<td class="px-4 py-3">
|
||||
@{
|
||||
var roleColor = account.Role switch
|
||||
{
|
||||
AccountRole.SuperAdmin => "bg-red-600",
|
||||
AccountRole.Admin => "bg-orange-600",
|
||||
AccountRole.Moderator => "bg-yellow-600",
|
||||
AccountRole.Vip => "bg-purple-600",
|
||||
_ => "bg-gray-600"
|
||||
};
|
||||
}
|
||||
<span class="px-2 py-1 text-xs rounded @roleColor text-white">@account.Role</span>
|
||||
</td>
|
||||
<td class="px-4 py-3">
|
||||
@if (isBanned)
|
||||
{
|
||||
<span class="px-2 py-1 text-xs rounded bg-red-900 text-red-300">
|
||||
@if (account.BannedUntil.HasValue && account.BannedUntil > DateTime.UtcNow)
|
||||
{
|
||||
<text>Until @account.BannedUntil.Value.ToString("MMM d")</text>
|
||||
}
|
||||
else
|
||||
{
|
||||
<text>Permanent</text>
|
||||
}
|
||||
</span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span class="px-2 py-1 text-xs rounded bg-green-900 text-green-300">Active</span>
|
||||
}
|
||||
</td>
|
||||
<td class="px-4 py-3 text-sm text-gray-400">@account.CreatedAt.ToString("yyyy-MM-dd")</td>
|
||||
<td class="px-4 py-3 text-right">
|
||||
<a href="/admin/players/edit?id=@account.Id" class="btn btn-secondary text-xs px-2 py-1">Edit</a>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
|
||||
@if (!Model.Accounts.Any())
|
||||
{
|
||||
<tr>
|
||||
<td colspan="7" class="px-4 py-8 text-center text-gray-400">No accounts found.</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<!-- Pagination -->
|
||||
@if (Model.TotalPages > 1)
|
||||
{
|
||||
<div class="flex items-center justify-between">
|
||||
<p class="text-sm text-gray-400">
|
||||
Showing @((Model.CurrentPage - 1) * Model.PageSize + 1)-@Math.Min(Model.CurrentPage * Model.PageSize, Model.TotalCount) of @Model.TotalCount
|
||||
</p>
|
||||
<div class="flex items-center gap-2">
|
||||
@if (Model.CurrentPage > 1)
|
||||
{
|
||||
<a href="@Model.GetPageUrl(Model.CurrentPage - 1)" class="btn btn-secondary">← Prev</a>
|
||||
}
|
||||
<span class="text-gray-400 px-2">@Model.CurrentPage / @Model.TotalPages</span>
|
||||
@if (Model.CurrentPage < Model.TotalPages)
|
||||
{
|
||||
<a href="@Model.GetPageUrl(Model.CurrentPage + 1)" class="btn btn-secondary">Next →</a>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
@if (!string.IsNullOrEmpty(Model.Message))
|
||||
{
|
||||
<div class="fixed bottom-4 right-4 p-4 rounded-lg @(Model.IsError ? "bg-red-900 border border-red-700" : "bg-green-900 border border-green-700") text-white shadow-lg z-50">
|
||||
@Model.Message
|
||||
</div>
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Server.Data;
|
||||
|
||||
@@ -12,10 +13,69 @@ public class IndexModel : AdminPageModel
|
||||
_db = db;
|
||||
}
|
||||
|
||||
public int PlayerCount { get; set; }
|
||||
public List<Account> Accounts { get; set; } = new();
|
||||
|
||||
[FromQuery(Name = "search")]
|
||||
public string? Search { get; set; }
|
||||
|
||||
[FromQuery(Name = "role")]
|
||||
public AccountRole? RoleFilter { get; set; }
|
||||
|
||||
[FromQuery(Name = "status")]
|
||||
public string? StatusFilter { get; set; }
|
||||
|
||||
[FromQuery(Name = "page")]
|
||||
public int CurrentPage { get; set; } = 1;
|
||||
|
||||
public int PageSize { get; set; } = 25;
|
||||
public int TotalCount { get; set; }
|
||||
public int TotalPages => (int)Math.Ceiling(TotalCount / (double)PageSize);
|
||||
|
||||
// Stats
|
||||
public int ActiveCount { get; set; }
|
||||
public int BannedCount { get; set; }
|
||||
public int AdminCount { get; set; }
|
||||
|
||||
public string? Message { get; set; }
|
||||
public bool IsError { get; set; }
|
||||
|
||||
public string GetPageUrl(int page)
|
||||
{
|
||||
var parts = new List<string> { $"page={page}" };
|
||||
if (!string.IsNullOrEmpty(Search)) parts.Add($"search={Uri.EscapeDataString(Search)}");
|
||||
if (RoleFilter.HasValue) parts.Add($"role={RoleFilter}");
|
||||
if (!string.IsNullOrEmpty(StatusFilter)) parts.Add($"status={StatusFilter}");
|
||||
return "/admin/players?" + string.Join("&", parts);
|
||||
}
|
||||
|
||||
public async Task OnGetAsync()
|
||||
{
|
||||
PlayerCount = await _db.Accounts.CountAsync();
|
||||
if (CurrentPage < 1) CurrentPage = 1;
|
||||
|
||||
// Stats
|
||||
ActiveCount = await _db.Set<Account>().CountAsync(a => !a.IsBanned && (a.BannedUntil == null || a.BannedUntil <= DateTime.UtcNow));
|
||||
BannedCount = await _db.Set<Account>().CountAsync(a => a.IsBanned || (a.BannedUntil != null && a.BannedUntil > DateTime.UtcNow));
|
||||
AdminCount = await _db.Set<Account>().CountAsync(a => a.Role >= AccountRole.Admin);
|
||||
|
||||
var query = _db.Set<Account>().AsQueryable();
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(Search))
|
||||
query = query.Where(a => a.Username.Contains(Search) || (a.Email != null && a.Email.Contains(Search)));
|
||||
|
||||
if (RoleFilter.HasValue)
|
||||
query = query.Where(a => a.Role == RoleFilter.Value);
|
||||
|
||||
if (StatusFilter == "banned")
|
||||
query = query.Where(a => a.IsBanned || (a.BannedUntil != null && a.BannedUntil > DateTime.UtcNow));
|
||||
else if (StatusFilter == "active")
|
||||
query = query.Where(a => !a.IsBanned && (a.BannedUntil == null || a.BannedUntil <= DateTime.UtcNow));
|
||||
|
||||
TotalCount = await query.CountAsync();
|
||||
|
||||
Accounts = await query
|
||||
.OrderByDescending(a => a.CreatedAt)
|
||||
.Skip((CurrentPage - 1) * PageSize)
|
||||
.Take(PageSize)
|
||||
.ToListAsync();
|
||||
}
|
||||
}
|
||||
|
||||
+5
-4
@@ -7,16 +7,17 @@
|
||||
},
|
||||
"AllowedHosts": "*",
|
||||
"Database": {
|
||||
"ConnectionString": "Server=a2nlmysql45plsk.secureserver.net;Port=3306;Database=Theraborn;User ID=tbadmin;Password=8N10ml9x?;Pooling=true;Minimum Pool Size=0;Maximum Pool Size=50;",
|
||||
"ConnectionString": "",//Server=a2nlmysql45plsk.secureserver.net;Port=3306;Database=Theraborn;User ID=tbadmin;Password=8N10ml9x?;Pooling=true;Minimum Pool Size=0;Maximum Pool Size=50;",
|
||||
"CommandTimeoutSeconds": 30,
|
||||
"MaxRetryCount": 3,
|
||||
"RetryBaseDelayMs": 100
|
||||
},
|
||||
"MinIO": {
|
||||
"Endpoint": "assets.aeternalisgames.com",
|
||||
"AccessKey": "STTQyhxgIWf4NvqQG06f",
|
||||
"SecretKey": "uN4ui336iVJcwBjT3mEv",
|
||||
"AccessKey": "",
|
||||
"SecretKey": "",
|
||||
"BucketName": "downloads",
|
||||
"UseSSL": true
|
||||
"UseSSL": true,
|
||||
"AnonymousAccess": true
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user