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!
87 lines
2.3 KiB
C#
87 lines
2.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 CatalogModel : PageModel
|
|
{
|
|
private readonly RR3DbContext _context;
|
|
|
|
public CatalogModel(RR3DbContext context)
|
|
{
|
|
_context = context;
|
|
}
|
|
|
|
public List<CatalogItem> CatalogItems { get; set; } = new();
|
|
|
|
public async Task OnGetAsync()
|
|
{
|
|
CatalogItems = await _context.CatalogItems
|
|
.OrderBy(c => c.Type)
|
|
.ThenBy(c => c.Name)
|
|
.ToListAsync();
|
|
}
|
|
|
|
public async Task<IActionResult> OnPostAddAsync(string sku, string name, string type, decimal price, bool available)
|
|
{
|
|
var item = new CatalogItem
|
|
{
|
|
Sku = sku,
|
|
Name = name,
|
|
Type = type,
|
|
Price = price,
|
|
Available = available
|
|
};
|
|
|
|
_context.CatalogItems.Add(item);
|
|
await _context.SaveChangesAsync();
|
|
|
|
return RedirectToPage();
|
|
}
|
|
|
|
public async Task<IActionResult> OnPostUpdateAsync(int itemId, string sku, string name, string type, decimal price, bool available)
|
|
{
|
|
var item = await _context.CatalogItems.FindAsync(itemId);
|
|
if (item != null)
|
|
{
|
|
item.Sku = sku;
|
|
item.Name = name;
|
|
item.Type = type;
|
|
item.Price = price;
|
|
item.Available = available;
|
|
await _context.SaveChangesAsync();
|
|
}
|
|
|
|
return RedirectToPage();
|
|
}
|
|
|
|
public async Task<IActionResult> OnPostToggleAvailabilityAsync(int itemId)
|
|
{
|
|
var item = await _context.CatalogItems.FindAsync(itemId);
|
|
if (item != null)
|
|
{
|
|
item.Available = !item.Available;
|
|
await _context.SaveChangesAsync();
|
|
}
|
|
|
|
return RedirectToPage();
|
|
}
|
|
|
|
public async Task<IActionResult> OnPostDeleteAsync(int itemId)
|
|
{
|
|
var item = await _context.CatalogItems.FindAsync(itemId);
|
|
if (item != null)
|
|
{
|
|
_context.CatalogItems.Remove(item);
|
|
await _context.SaveChangesAsync();
|
|
}
|
|
|
|
return RedirectToPage();
|
|
}
|
|
}
|