2026-07-23 11:12:10 +02:00
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
using radiuscontroller.Components;
|
|
|
|
|
using radiuscontroller.Data;
|
|
|
|
|
using radiuscontroller.Services;
|
|
|
|
|
|
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
|
|
|
|
|
|
// Add database context
|
|
|
|
|
var connectionString = builder.Configuration.GetConnectionString("DefaultConnection")
|
|
|
|
|
?? "Host=localhost;Port=5432;Database=radius;Username=radius;Password=radpass";
|
|
|
|
|
|
|
|
|
|
builder.Services.AddDbContext<RadiusDbContext>(options =>
|
|
|
|
|
options.UseNpgsql(connectionString));
|
|
|
|
|
|
|
|
|
|
// Add services
|
|
|
|
|
builder.Services.AddScoped<IRadiusService, RadiusService>();
|
|
|
|
|
builder.Services.AddScoped<AdminAuthService>();
|
2026-07-24 15:50:28 +02:00
|
|
|
builder.Services.AddHostedService<AccountEnforcementService>();
|
2026-07-23 11:12:10 +02:00
|
|
|
|
|
|
|
|
// Add Razor components
|
|
|
|
|
builder.Services.AddRazorComponents()
|
|
|
|
|
.AddInteractiveServerComponents();
|
|
|
|
|
|
|
|
|
|
var app = builder.Build();
|
|
|
|
|
|
|
|
|
|
// Auto-seed admin user and default settings if DB available
|
|
|
|
|
using (var scope = app.Services.CreateScope())
|
|
|
|
|
{
|
|
|
|
|
var radiusService = scope.ServiceProvider.GetRequiredService<IRadiusService>();
|
|
|
|
|
await radiusService.EnsureDatabaseCreatedAndSeededAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Configure HTTP request pipeline
|
|
|
|
|
if (!app.Environment.IsDevelopment())
|
|
|
|
|
{
|
|
|
|
|
app.UseExceptionHandler("/Error", createScopeForErrors: true);
|
|
|
|
|
app.UseHsts();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
app.UseHttpsRedirection();
|
|
|
|
|
app.UseAntiforgery();
|
|
|
|
|
|
|
|
|
|
app.MapStaticAssets();
|
|
|
|
|
app.MapRazorComponents<App>()
|
|
|
|
|
.AddInteractiveServerRenderMode();
|
|
|
|
|
|
|
|
|
|
app.Run();
|