aboutsummaryrefslogtreecommitdiffstats
path: root/code/api/Program.cs
diff options
context:
space:
mode:
authorivarlovlie <git@ivarlovlie.no>2022-12-21 23:37:23 +0100
committerivarlovlie <git@ivarlovlie.no>2022-12-21 23:37:23 +0100
commit82ade3c31fb17b662feec59e9e654ceb66edbb7a (patch)
tree26443c41c55d2cd2ae46fdd0d663aca84b779ffe /code/api/Program.cs
parente60703aadca7d423c0fbfb189d5ef439fc1df072 (diff)
downloadstorage-82ade3c31fb17b662feec59e9e654ceb66edbb7a.tar.xz
storage-82ade3c31fb17b662feec59e9e654ceb66edbb7a.zip
feat: Add initial schema and start login
Diffstat (limited to 'code/api/Program.cs')
-rw-r--r--code/api/Program.cs55
1 files changed, 43 insertions, 12 deletions
diff --git a/code/api/Program.cs b/code/api/Program.cs
index 1b0b1b5..e6281f7 100644
--- a/code/api/Program.cs
+++ b/code/api/Program.cs
@@ -1,20 +1,51 @@
+global using Microsoft.AspNetCore.Mvc;
+global using IOL.Helpers;
+global using I2R.Storage.Api.Services.Admin;
+global using Microsoft.AspNetCore.Mvc.RazorPages;
+global using Microsoft.EntityFrameworkCore;
+global using I2R.Storage.Api.Database;
+global using I2R.Storage.Api.Utilities;
+global using I2R.Storage.Api.Database.Models;
+global using I2R.Storage.Api.Resources;
+global using I2R.Storage.Api.Enums;
+global using Microsoft.Extensions.Localization;
+global using I2R.Storage.Api.Statics;
+global using Microsoft.AspNetCore.Authorization;
+global using System.Security.Claims;
+using Microsoft.AspNetCore.Authentication.Cookies;
+using Microsoft.AspNetCore.Localization;
+
var builder = WebApplication.CreateBuilder(args);
+builder.Services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
+ .AddCookie(o => {
+ o.Cookie.Name = "storage_session";
+ o.Cookie.HttpOnly = true;
+ });
+builder.Services.AddAuthorization(o => {
+ o.AddPolicy("least_privileged", b => { b.RequireRole("least_privileged"); });
+ o.AddPolicy("admin", b => { b.RequireRole("admin"); });
+});
+builder.Services.AddLocalization();
+builder.Services.AddRequestLocalization(o => { o.DefaultRequestCulture = new RequestCulture("en"); });
+builder.Services.AddScoped<UserService>();
+builder.Services.AddDbContext<AppDatabase>(o => {
+ o.UseNpgsql(builder.Configuration.GetAppDbConnectionString(), b => {
+ b.UseQuerySplittingBehavior(QuerySplittingBehavior.SplitQuery);
+ b.EnableRetryOnFailure(3);
+ });
+ o.UseSnakeCaseNamingConvention();
+});
+builder.Services.AddRazorPages().AddRazorRuntimeCompilation();
builder.Services.AddControllers();
-builder.Services.AddEndpointsApiExplorer();
-builder.Services.AddSwaggerGen();
var app = builder.Build();
-if (app.Environment.IsDevelopment())
-{
- app.UseSwagger();
- app.UseSwaggerUI();
-}
-
-
+app.UseStaticFiles();
+app.UseStatusCodePages();
+app.UseRequestLocalization();
app.UseAuthorization();
-
+app.UseAuthentication();
+app.MapRazorPages();
app.MapControllers();
-
-app.Run();
+app.Run(); \ No newline at end of file