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!
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.AspNetCore.Authentication.Cookies;
|
||||
using RR3CommunityServer.Data;
|
||||
using RR3CommunityServer.Services;
|
||||
using RR3CommunityServer.Middleware;
|
||||
@@ -8,6 +9,20 @@ var builder = WebApplication.CreateBuilder(args);
|
||||
// Add services to the container
|
||||
builder.Services.AddControllers();
|
||||
builder.Services.AddRazorPages(); // Add Razor Pages support
|
||||
|
||||
// Add cookie authentication
|
||||
builder.Services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
|
||||
.AddCookie(options =>
|
||||
{
|
||||
options.LoginPath = "/Login";
|
||||
options.LogoutPath = "/Logout";
|
||||
options.AccessDeniedPath = "/Login";
|
||||
options.ExpireTimeSpan = TimeSpan.FromDays(30);
|
||||
options.SlidingExpiration = true;
|
||||
});
|
||||
|
||||
builder.Services.AddAuthorization();
|
||||
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddSwaggerGen();
|
||||
|
||||
@@ -53,16 +68,19 @@ using (var scope = app.Services.CreateScope())
|
||||
app.UseHttpsRedirection();
|
||||
app.UseCors();
|
||||
|
||||
// Authentication & Authorization
|
||||
app.UseAuthentication();
|
||||
app.UseAuthorization();
|
||||
|
||||
// Custom middleware
|
||||
app.UseMiddleware<SynergyHeadersMiddleware>();
|
||||
app.UseMiddleware<SessionValidationMiddleware>();
|
||||
|
||||
app.UseAuthorization();
|
||||
app.MapControllers();
|
||||
app.MapRazorPages(); // Add Razor Pages routing
|
||||
|
||||
// Redirect root to admin panel
|
||||
app.MapGet("/", () => Results.Redirect("/admin"));
|
||||
// Redirect root to login page
|
||||
app.MapGet("/", () => Results.Redirect("/Login"));
|
||||
|
||||
Console.WriteLine("╔══════════════════════════════════════════════════════════╗");
|
||||
Console.WriteLine("║ Real Racing 3 Community Server - RUNNING ║");
|
||||
|
||||
Reference in New Issue
Block a user