📄
MatDenDagen/Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using System.Threading; using MatDenDagen; using MatDenDagen.Components; using MatDenDagen.Infrastructure.Storage; using MatDenDagen.Services; using Microsoft.AspNetCore.Authentication.Cookies; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.DependencyInjection; var builder = WebApplication.CreateBuilder(args); builder.ConfigureOpenTelemetry(); builder.Services.AddStorageServices().AddAdminService().AddDateService().AddExportService(); builder.Services.AddRazorComponents(); builder .Services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme) .AddCookie(options => { options.LoginPath = "/admin/login"; options.LogoutPath = "/admin/logout"; options.AccessDeniedPath = "/admin/login"; options.Cookie.Name = "AdminAuthCookie"; }); builder.Services.AddAuthorization(); var app = builder.Build(); app.UseAuthentication(); app.UseAuthorization(); app.UseStatusCodePagesWithReExecute("/not-found", createScopeForStatusCodePages: true); app.MapStaticAssets(); app.MapRazorComponents<App>().DisableAntiforgery(); app.MapGet( "/admin/export.zip", async ( [FromServices] ExportService exportService, HttpContext httpContext, HttpResponse httpResponse, CancellationToken cancellationToken ) => { httpContext.Features.Get<IHttpBodyControlFeature>()?.AllowSynchronousIO = true; httpResponse.Headers.ContentType = "application/zip"; httpResponse.Headers.ContentDisposition = "attachment; filename=\"export.zip\""; await exportService.ExportAllSubmissions(httpResponse.Body, cancellationToken); } ) .RequireAuthorization(p => p.RequireRole("Admin")); app.Run();