Ignore:
Timestamp:
09/01/26 06:11:34 (4 weeks ago)
Author:
mmilevski <markomilevski3@…>
Branches:
main
Children:
d2eccb3
Parents:
08aefc6
Message:

Added major improvements.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • KernelRecordsMVC.Web/Program.cs

    r08aefc6 rfa0fbaf  
    11using Microsoft.EntityFrameworkCore;
    2 using KernelRecordsMVC.Data;
     2using Npgsql;
     3using Npgsql.NameTranslation;
     4using KernelRecordsMVC.Domain.Enums;
     5using KernelRecordsMVC.Infrastructure.Data;
    36
    47var builder = WebApplication.CreateBuilder(args);
    58
     9// ==========================================
     10// AUTHENTICATION
     11// ==========================================
     12
     13builder.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
     23builder.Services.AddAuthorization();
     24
    625builder.Services.AddControllersWithViews();
    726
     27// ==========================================
     28// DATABASE
     29// ==========================================
     30
     31var dataSourceBuilder = new NpgsqlDataSourceBuilder(
     32    builder.Configuration.GetConnectionString("KernelRecords"));
     33
     34var nameTranslator = new NpgsqlNullNameTranslator();
     35
     36dataSourceBuilder.MapEnum<AdminType>(
     37    "project.admin_type",
     38    nameTranslator);
     39
     40dataSourceBuilder.MapEnum<ProductFormat>(
     41    "project.product_format",
     42    nameTranslator);
     43
     44dataSourceBuilder.MapEnum<PaymentMethodType>(
     45    "project.payment_method_type",
     46    nameTranslator);
     47
     48dataSourceBuilder.MapEnum<OrderStatusType>(
     49    "project.order_status_type",
     50    nameTranslator);
     51
     52dataSourceBuilder.MapEnum<ModificationType>(
     53    "project.modification_type",
     54    nameTranslator);
     55
     56dataSourceBuilder.MapEnum<ArtistReleaseType>(
     57    "project.artist_release_type",
     58    nameTranslator);
     59
     60var dataSource = dataSourceBuilder.Build();
     61
    862builder.Services.AddDbContext<KernelRecordsContext>(options =>
    9     options.UseNpgsql(
    10         builder.Configuration.GetConnectionString("KernelRecords")));
     63    options.UseNpgsql(dataSource));
    1164
    12 builder.Services.AddSession();
     65// ==========================================
     66// SESSION
     67// ==========================================
     68
     69builder.Services.AddSession(options =>
     70{
     71    options.IdleTimeout = TimeSpan.FromHours(2);
     72    options.Cookie.HttpOnly = true;
     73    options.Cookie.IsEssential = true;
     74});
    1375
    1476var app = builder.Build();
     77
     78// ==========================================
     79// MIDDLEWARE
     80// ==========================================
    1581
    1682if (!app.Environment.IsDevelopment())
    … …  
    2187
    2288app.UseHttpsRedirection();
     89
    2390app.UseStaticFiles();
    2491
    … …  
    2693
    2794app.UseSession();
     95
     96app.UseAuthentication();
    2897
    2998app.UseAuthorization();
Note: See TracChangeset for help on using the changeset viewer.