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!
51 lines
1.3 KiB
C#
51 lines
1.3 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
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 UsersModel : PageModel
|
|
{
|
|
private readonly RR3DbContext _context;
|
|
|
|
public UsersModel(RR3DbContext context)
|
|
{
|
|
_context = context;
|
|
}
|
|
|
|
public List<User> Users { get; set; } = new();
|
|
public string? SearchQuery { get; set; }
|
|
|
|
public async Task OnGetAsync(string? search)
|
|
{
|
|
SearchQuery = search;
|
|
|
|
var query = _context.Users.AsQueryable();
|
|
|
|
if (!string.IsNullOrEmpty(search))
|
|
{
|
|
query = query.Where(u => u.SynergyId.Contains(search) || u.DeviceId.Contains(search));
|
|
}
|
|
|
|
Users = await query
|
|
.OrderByDescending(u => u.CreatedAt)
|
|
.ToListAsync();
|
|
}
|
|
|
|
public async Task<IActionResult> OnPostDeleteAsync(int userId)
|
|
{
|
|
var user = await _context.Users.FindAsync(userId);
|
|
if (user != null)
|
|
{
|
|
_context.Users.Remove(user);
|
|
await _context.SaveChangesAsync();
|
|
}
|
|
|
|
return RedirectToPage();
|
|
}
|
|
}
|