| | 1 | | using Microsoft.AspNetCore.Builder; |
| | 2 | | using Microsoft.AspNetCore.Components; |
| | 3 | | using Microsoft.AspNetCore.Components.Authorization; |
| | 4 | | using Microsoft.AspNetCore.Hosting; |
| | 5 | | using Microsoft.AspNetCore.HttpsPolicy; |
| | 6 | | using Microsoft.AspNetCore.Identity; |
| | 7 | | using Microsoft.AspNetCore.Identity.UI; |
| | 8 | | using Microsoft.EntityFrameworkCore; |
| | 9 | | using Microsoft.Extensions.Configuration; |
| | 10 | | using Microsoft.Extensions.DependencyInjection; |
| | 11 | | using Microsoft.Extensions.Hosting; |
| | 12 | | using MUNity.BlazorServer.Areas.Identity; |
| | 13 | | using MUNity.Database.Context; |
| | 14 | | using MUNity.Database.Models.User; |
| | 15 | | using MUNity.Services; |
| | 16 | | using System; |
| | 17 | | using System.Collections.Generic; |
| | 18 | | using System.Linq; |
| | 19 | | using System.Threading.Tasks; |
| | 20 | | using Radzen; |
| | 21 | |
|
| | 22 | | namespace MUNity.BlazorServer; |
| | 23 | |
|
| | 24 | | public class Startup |
| | 25 | | { |
| 0 | 26 | | public Startup(IConfiguration configuration) |
| 0 | 27 | | { |
| 0 | 28 | | Configuration = configuration; |
| 0 | 29 | | } |
| | 30 | |
|
| 0 | 31 | | public IConfiguration Configuration { get; } |
| | 32 | |
|
| | 33 | | // This method gets called by the runtime. Use this method to add services to the container. |
| | 34 | | // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 |
| | 35 | | public void ConfigureServices(IServiceCollection services) |
| 0 | 36 | | { |
| | 37 | | // Blazor stuff |
| 0 | 38 | | services.AddRazorPages(); |
| 0 | 39 | | services.AddServerSideBlazor(); |
| | 40 | |
|
| | 41 | | //Trigger deploy |
| | 42 | | // Database |
| | 43 | | // To get more output add: .EnableSensitiveDataLogging().LogTo(Console.WriteLine) after Use...() |
| | 44 | | // Set the Data Source to: ../../tests/MUNityDatabaseTest/bin/Debug/net6.0/testmunbw.db |
| | 45 | | // For demo use the name demo.db |
| | 46 | | // to use the latest result of the MUNBW test |
| 0 | 47 | | services.AddDbContext<MunityContext>(options => |
| 0 | 48 | | options.UseSqlite("Data Source=demo.db")); |
| | 49 | |
|
| | 50 | | // Identity |
| 0 | 51 | | services.AddAuthentication(); |
| 0 | 52 | | services.AddIdentity<MunityUser, MunityRole>(options => |
| 0 | 53 | | { |
| 0 | 54 | | options.User.RequireUniqueEmail = true; |
| 0 | 55 | | options.Password.RequireDigit = true; |
| 0 | 56 | | options.Password.RequireLowercase = true; |
| 0 | 57 | | options.Password.RequireUppercase = true; |
| 0 | 58 | | options.Password.RequireNonAlphanumeric = false; |
| 0 | 59 | | }) |
| 0 | 60 | | .AddEntityFrameworkStores<MunityContext>() |
| 0 | 61 | | .AddDefaultUI() |
| 0 | 62 | | .AddDefaultTokenProviders(); |
| | 63 | |
|
| | 64 | |
|
| | 65 | |
|
| | 66 | | //services.AddScoped<AuthenticationStateProvider, RevalidatingIdentityAuthenticationStateProvider<MunityUser>>() |
| 0 | 67 | | services.AddDatabaseDeveloperPageExceptionFilter(); |
| | 68 | |
|
| | 69 | | // Radzen.Blazor |
| 0 | 70 | | services.AddScoped<DialogService>(); |
| 0 | 71 | | services.AddScoped<NotificationService>(); |
| 0 | 72 | | services.AddScoped<TooltipService>(); |
| 0 | 73 | | services.AddScoped<ContextMenuService>(); |
| | 74 | |
|
| | 75 | | // MUNity Services |
| 0 | 76 | | services.AddScoped<UserConferenceAuthService>(); |
| 0 | 77 | | services.AddScoped<UserService>(); |
| 0 | 78 | | services.AddScoped<OrganizationService>(); |
| 0 | 79 | | services.AddScoped<ProjectService>(); |
| 0 | 80 | | services.AddScoped<ConferenceService>(); |
| 0 | 81 | | services.AddScoped<DelegationService>(); |
| 0 | 82 | | services.AddScoped<ConferenceRoleService>(); |
| 0 | 83 | | services.AddScoped<UserNotificationService>(); |
| 0 | 84 | | services.AddScoped<ConferenceApplicationService>(); |
| 0 | 85 | | services.AddScoped<IMailService, MailService>(); |
| 0 | 86 | | services.AddScoped<ConferenceWebsiteService>(); |
| | 87 | |
|
| 0 | 88 | | services.AddLogging(); |
| | 89 | |
|
| 0 | 90 | | } |
| | 91 | |
|
| | 92 | | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. |
| | 93 | | public void Configure(IApplicationBuilder app, IWebHostEnvironment env) |
| 0 | 94 | | { |
| 0 | 95 | | if (env.IsDevelopment()) |
| 0 | 96 | | { |
| 0 | 97 | | app.UseDeveloperExceptionPage(); |
| 0 | 98 | | app.UseMigrationsEndPoint(); |
| 0 | 99 | | } |
| | 100 | | else |
| 0 | 101 | | { |
| 0 | 102 | | app.UseExceptionHandler("/Error"); |
| | 103 | | // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka. |
| 0 | 104 | | app.UseHsts(); |
| 0 | 105 | | } |
| | 106 | |
|
| 0 | 107 | | app.UseHttpsRedirection(); |
| 0 | 108 | | app.UseStaticFiles(); |
| | 109 | |
|
| 0 | 110 | | app.UseRouting(); |
| | 111 | |
|
| 0 | 112 | | app.UseAuthentication(); |
| 0 | 113 | | app.UseAuthorization(); |
| | 114 | |
|
| 0 | 115 | | app.UseEndpoints(endpoints => |
| 0 | 116 | | { |
| 0 | 117 | | endpoints.MapControllers(); |
| 0 | 118 | | endpoints.MapBlazorHub(); |
| 0 | 119 | | endpoints.MapFallbackToPage("/_Host"); |
| 0 | 120 | | }); |
| | 121 | |
|
| 0 | 122 | | MigrateDatabase(app); |
| 0 | 123 | | } |
| | 124 | |
|
| | 125 | | private void MigrateDatabase(IApplicationBuilder app) |
| 0 | 126 | | { |
| 0 | 127 | | var scope = app.ApplicationServices.GetRequiredService<IServiceScopeFactory>().CreateScope(); |
| 0 | 128 | | var context = scope.ServiceProvider.GetRequiredService<MunityContext>(); |
| 0 | 129 | | context.Database.EnsureCreated(); |
| 0 | 130 | | context.Database.Migrate(); |
| 0 | 131 | | } |
| | 132 | | } |