Base template solution with tests, authentication, support for admin accounts, prepared tests for auth, basic error handling system used in auth.

This commit is contained in:
Matěj Kubíček
2026-04-18 17:37:38 +02:00
parent 5a2e76fefd
commit f50bec167f
101 changed files with 83814 additions and 0 deletions
+58
View File
@@ -0,0 +1,58 @@
using dotenv.net;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.EntityFrameworkCore;
using TemplateWeb.Data;
using TemplateWeb.Interfaces;
using TemplateWeb.Services;
namespace TemplateWeb;
public class Program
{
public static void Main(string[] args)
{
DotEnv.Load();
var builder = WebApplication.CreateBuilder(args);
// gets the connection string from .env
var connectionString = builder.Configuration["DEFAULT_CONNECTION"] ?? throw new InvalidOperationException("Connection string 'DEFAULT_CONNECTION' not found.");
builder.Services.AddDbContext<AppDbContext>(options =>
options.UseNpgsql(connectionString));
builder.Services.AddControllersWithViews();
builder.Services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
.AddCookie(options =>
{
options.LoginPath = "/Auth/Login";
options.AccessDeniedPath = "/Auth/AccessDenied";
options.ExpireTimeSpan = TimeSpan.FromHours(2);
});
builder.Services.AddAuthorization();
builder.Services.AddScoped<IAuthService, AuthService>();
builder.Services.AddHttpContextAccessor();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Home/Error");
}
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.MapStaticAssets();
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}")
.WithStaticAssets();
app.Run();
}
}