| [08aefc6] | 1 | using Microsoft.EntityFrameworkCore;
|
|---|
| [fa0fbaf] | 2 | using Npgsql;
|
|---|
| 3 | using Npgsql.NameTranslation;
|
|---|
| 4 | using KernelRecordsMVC.Domain.Enums;
|
|---|
| 5 | using KernelRecordsMVC.Infrastructure.Data;
|
|---|
| [08aefc6] | 6 |
|
|---|
| 7 | var builder = WebApplication.CreateBuilder(args);
|
|---|
| 8 |
|
|---|
| [fa0fbaf] | 9 | // ==========================================
|
|---|
| 10 | // AUTHENTICATION
|
|---|
| 11 | // ==========================================
|
|---|
| 12 |
|
|---|
| 13 | builder.Services
|
|---|
| 14 | .AddAuthentication("Cookies")
|
|---|
| 15 | .AddCookie("Cookies", options =>
|
|---|
| 16 | {
|
|---|
| 17 | options.LoginPath = "/Account/Login";
|
|---|
| 18 | options.AccessDeniedPath = "/Account/Login";
|
|---|
| 19 | options.ExpireTimeSpan = TimeSpan.FromHours(8);
|
|---|
| 20 | options.SlidingExpiration = true;
|
|---|
| 21 | });
|
|---|
| 22 |
|
|---|
| 23 | builder.Services.AddAuthorization();
|
|---|
| 24 |
|
|---|
| [08aefc6] | 25 | builder.Services.AddControllersWithViews();
|
|---|
| 26 |
|
|---|
| [fa0fbaf] | 27 | // ==========================================
|
|---|
| 28 | // DATABASE
|
|---|
| 29 | // ==========================================
|
|---|
| 30 |
|
|---|
| 31 | var dataSourceBuilder = new NpgsqlDataSourceBuilder(
|
|---|
| 32 | builder.Configuration.GetConnectionString("KernelRecords"));
|
|---|
| 33 |
|
|---|
| 34 | var nameTranslator = new NpgsqlNullNameTranslator();
|
|---|
| 35 |
|
|---|
| 36 | dataSourceBuilder.MapEnum<AdminType>(
|
|---|
| 37 | "project.admin_type",
|
|---|
| 38 | nameTranslator);
|
|---|
| 39 |
|
|---|
| 40 | dataSourceBuilder.MapEnum<ProductFormat>(
|
|---|
| 41 | "project.product_format",
|
|---|
| 42 | nameTranslator);
|
|---|
| 43 |
|
|---|
| 44 | dataSourceBuilder.MapEnum<PaymentMethodType>(
|
|---|
| 45 | "project.payment_method_type",
|
|---|
| 46 | nameTranslator);
|
|---|
| 47 |
|
|---|
| 48 | dataSourceBuilder.MapEnum<OrderStatusType>(
|
|---|
| 49 | "project.order_status_type",
|
|---|
| 50 | nameTranslator);
|
|---|
| 51 |
|
|---|
| 52 | dataSourceBuilder.MapEnum<ModificationType>(
|
|---|
| 53 | "project.modification_type",
|
|---|
| 54 | nameTranslator);
|
|---|
| 55 |
|
|---|
| 56 | dataSourceBuilder.MapEnum<ArtistReleaseType>(
|
|---|
| 57 | "project.artist_release_type",
|
|---|
| 58 | nameTranslator);
|
|---|
| 59 |
|
|---|
| 60 | var dataSource = dataSourceBuilder.Build();
|
|---|
| 61 |
|
|---|
| [08aefc6] | 62 | builder.Services.AddDbContext<KernelRecordsContext>(options =>
|
|---|
| [fa0fbaf] | 63 | options.UseNpgsql(dataSource));
|
|---|
| [08aefc6] | 64 |
|
|---|
| [fa0fbaf] | 65 | // ==========================================
|
|---|
| 66 | // SESSION
|
|---|
| 67 | // ==========================================
|
|---|
| 68 |
|
|---|
| 69 | builder.Services.AddSession(options =>
|
|---|
| 70 | {
|
|---|
| 71 | options.IdleTimeout = TimeSpan.FromHours(2);
|
|---|
| 72 | options.Cookie.HttpOnly = true;
|
|---|
| 73 | options.Cookie.IsEssential = true;
|
|---|
| 74 | });
|
|---|
| [08aefc6] | 75 |
|
|---|
| 76 | var app = builder.Build();
|
|---|
| 77 |
|
|---|
| [fa0fbaf] | 78 | // ==========================================
|
|---|
| 79 | // MIDDLEWARE
|
|---|
| 80 | // ==========================================
|
|---|
| 81 |
|
|---|
| [08aefc6] | 82 | if (!app.Environment.IsDevelopment())
|
|---|
| 83 | {
|
|---|
| 84 | app.UseExceptionHandler("/Home/Error");
|
|---|
| 85 | app.UseHsts();
|
|---|
| 86 | }
|
|---|
| 87 |
|
|---|
| 88 | app.UseHttpsRedirection();
|
|---|
| [fa0fbaf] | 89 |
|
|---|
| [08aefc6] | 90 | app.UseStaticFiles();
|
|---|
| 91 |
|
|---|
| 92 | app.UseRouting();
|
|---|
| 93 |
|
|---|
| 94 | app.UseSession();
|
|---|
| 95 |
|
|---|
| [fa0fbaf] | 96 | app.UseAuthentication();
|
|---|
| 97 |
|
|---|
| [08aefc6] | 98 | app.UseAuthorization();
|
|---|
| 99 |
|
|---|
| 100 | app.MapControllerRoute(
|
|---|
| 101 | name: "default",
|
|---|
| 102 | pattern: "{controller=Home}/{action=Index}/{id?}");
|
|---|
| 103 |
|
|---|
| [fa0fbaf] | 104 | app.Run();
|
|---|