Files
rr3-server/RR3CommunityServer/Pages/Admin.cshtml.cs
Daniel Elliott e03c1d9856 Add admin panel authentication and login system
Features:
- Login page with username/email + password
- Registration page for new accounts
- Logout functionality
- Cookie-based authentication (30-day sessions)
- Auto-redirect to login for unauthorized access
- User dropdown in navbar with logout link

Security:
- All admin pages now require authentication
- [Authorize] attribute on all admin PageModels
- Redirect to /Login if not authenticated
- Auto-login after registration

UI:
- Beautiful gradient login/register pages
- Consistent styling with admin panel
- User info displayed in navbar
- Logout link in dropdown menu

Starting resources for new users:
- 100,000 Gold
- 500,000 Cash
- Level 1
- Full admin panel access

Ready for production deployment!
2026-02-19 15:06:08 -08:00

61 lines
2.1 KiB
C#

using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.AspNetCore.Authorization;
using Microsoft.EntityFrameworkCore;
using RR3CommunityServer.Data;
using static RR3CommunityServer.Data.RR3DbContext;
namespace RR3CommunityServer.Pages;
[Authorize]
public class AdminModel : PageModel
{
private readonly RR3DbContext _context;
public AdminModel(RR3DbContext context)
{
_context = context;
}
public int TotalUsers { get; set; }
public int ActiveSessions { get; set; }
public int TotalDevices { get; set; }
public int TotalCatalogItems { get; set; }
public string Uptime { get; set; } = "0:00:00";
public string ServerUrl { get; set; } = string.Empty;
public string Platform { get; set; } = string.Empty;
public string DotNetVersion { get; set; } = string.Empty;
public List<User> RecentUsers { get; set; } = new();
public List<Session> RecentSessions { get; set; } = new();
public async Task OnGetAsync()
{
// Get statistics
TotalUsers = await _context.Users.CountAsync();
TotalDevices = await _context.Devices.CountAsync();
TotalCatalogItems = await _context.CatalogItems.CountAsync();
ActiveSessions = await _context.Sessions
.Where(s => s.ExpiresAt > DateTime.UtcNow)
.CountAsync();
// Get recent activity
RecentUsers = await _context.Users
.OrderByDescending(u => u.CreatedAt)
.Take(5)
.ToListAsync();
RecentSessions = await _context.Sessions
.Where(s => s.ExpiresAt > DateTime.UtcNow)
.OrderByDescending(s => s.CreatedAt)
.Take(5)
.ToListAsync();
// Server info
var uptime = DateTime.UtcNow - System.Diagnostics.Process.GetCurrentProcess().StartTime.ToUniversalTime();
Uptime = $"{uptime.Days}d {uptime.Hours}h {uptime.Minutes}m";
ServerUrl = $"{Request.Scheme}://{Request.Host}";
Platform = Environment.OSVersion.Platform.ToString();
DotNetVersion = Environment.Version.ToString();
}
}