2024-05-02 07:43:47 +01:00
|
|
|
using Aaru.Server.New.Components;
|
|
|
|
|
using Aaru.Server.New.Components.Account;
|
2024-05-04 03:57:15 +01:00
|
|
|
using Blazorise;
|
|
|
|
|
using Blazorise.Bootstrap;
|
|
|
|
|
using Blazorise.Icons.FontAwesome;
|
2024-05-03 03:24:40 +01:00
|
|
|
using Microsoft.AspNetCore.Components.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Identity;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2024-05-04 02:27:56 +01:00
|
|
|
using DbContext = Aaru.Server.Database.DbContext;
|
2024-05-02 07:43:47 +01:00
|
|
|
|
2024-05-03 03:24:40 +01:00
|
|
|
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
|
2024-05-02 07:43:47 +01:00
|
|
|
|
|
|
|
|
// Add services to the container.
|
|
|
|
|
builder.Services.AddRazorComponents().AddInteractiveServerComponents();
|
|
|
|
|
|
|
|
|
|
builder.Services.AddCascadingAuthenticationState();
|
|
|
|
|
builder.Services.AddScoped<IdentityUserAccessor>();
|
|
|
|
|
builder.Services.AddScoped<IdentityRedirectManager>();
|
|
|
|
|
builder.Services.AddScoped<AuthenticationStateProvider, IdentityRevalidatingAuthenticationStateProvider>();
|
|
|
|
|
|
|
|
|
|
builder.Services.AddAuthentication(options =>
|
|
|
|
|
{
|
|
|
|
|
options.DefaultScheme = IdentityConstants.ApplicationScheme;
|
|
|
|
|
options.DefaultSignInScheme = IdentityConstants.ExternalScheme;
|
|
|
|
|
})
|
|
|
|
|
.AddIdentityCookies();
|
|
|
|
|
|
2024-05-03 03:24:40 +01:00
|
|
|
string connectionString = builder.Configuration.GetConnectionString("DefaultConnection") ??
|
|
|
|
|
throw new InvalidOperationException("Connection string 'DefaultConnection' not found.");
|
2024-05-02 07:43:47 +01:00
|
|
|
|
2024-05-04 02:27:56 +01:00
|
|
|
builder.Services.AddDbContextFactory<DbContext>(options => options
|
|
|
|
|
.UseMySql(connectionString,
|
|
|
|
|
new MariaDbServerVersion(new Version(10, 4, 0)))
|
|
|
|
|
.UseLazyLoadingProxies());
|
2024-05-03 22:54:50 +01:00
|
|
|
|
2024-05-02 07:43:47 +01:00
|
|
|
builder.Services.AddDatabaseDeveloperPageExceptionFilter();
|
|
|
|
|
|
2024-05-03 22:54:50 +01:00
|
|
|
builder.Services.AddIdentityCore<IdentityUser>(options =>
|
|
|
|
|
{
|
|
|
|
|
options.SignIn.RequireConfirmedAccount = true;
|
|
|
|
|
options.User.RequireUniqueEmail = true;
|
|
|
|
|
})
|
|
|
|
|
.AddEntityFrameworkStores<DbContext>()
|
2024-05-02 07:43:47 +01:00
|
|
|
.AddSignInManager()
|
|
|
|
|
.AddDefaultTokenProviders();
|
|
|
|
|
|
2024-05-03 22:54:50 +01:00
|
|
|
builder.Services.AddSingleton<IEmailSender<IdentityUser>, IdentityNoOpEmailSender>();
|
2024-05-02 07:43:47 +01:00
|
|
|
|
2024-05-04 03:57:15 +01:00
|
|
|
builder.Services.AddBlazorise(options => { options.Immediate = true; }).AddBootstrapProviders().AddFontAwesomeIcons();
|
|
|
|
|
|
2024-05-03 03:24:40 +01:00
|
|
|
WebApplication app = builder.Build();
|
2024-05-02 07:43:47 +01:00
|
|
|
|
|
|
|
|
// Configure the HTTP request pipeline.
|
|
|
|
|
if(app.Environment.IsDevelopment())
|
|
|
|
|
app.UseMigrationsEndPoint();
|
|
|
|
|
else
|
|
|
|
|
{
|
2024-05-03 03:24:40 +01:00
|
|
|
app.UseExceptionHandler("/Error", true);
|
2024-05-02 07:43:47 +01:00
|
|
|
|
|
|
|
|
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
|
|
|
|
|
app.UseHsts();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
app.UseHttpsRedirection();
|
|
|
|
|
|
|
|
|
|
app.UseStaticFiles();
|
|
|
|
|
app.UseAntiforgery();
|
|
|
|
|
|
|
|
|
|
app.MapRazorComponents<App>().AddInteractiveServerRenderMode();
|
|
|
|
|
|
|
|
|
|
// Add additional endpoints required by the Identity /Account Razor components.
|
|
|
|
|
app.MapAdditionalIdentityEndpoints();
|
|
|
|
|
|
|
|
|
|
app.Run();
|