- Added EmailBlacklist service and controller for managing blacklisted emails. - Created EmailBlacklistDto for data transfer and EmailBlacklistFormViewModel for form handling. - Implemented views for listing and adding emails to the blacklist. - Updated database schema with new EmailBlacklist entity and related migrations. - Enhanced OAuthClientFormViewModel to include ClientId and ClientSecret properties. - Added EmailBlacklistService to handle email blacklisting logic. - Integrated email blacklist service into the application with necessary dependencies.
86 lines
2.7 KiB
C#
86 lines
2.7 KiB
C#
using MemberCenter.Application.Abstractions;
|
|
using MemberCenter.Infrastructure.Configuration;
|
|
using MemberCenter.Infrastructure.Identity;
|
|
using MemberCenter.Infrastructure.Persistence;
|
|
using MemberCenter.Infrastructure.Services;
|
|
using Microsoft.AspNetCore.Identity;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
EnvLoader.LoadDotEnvIfDevelopment();
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
builder.Services.AddDbContext<MemberCenterDbContext>(options =>
|
|
{
|
|
var connectionString = builder.Configuration.GetConnectionString("Default")
|
|
?? Environment.GetEnvironmentVariable("ConnectionStrings__Default")
|
|
?? "Host=localhost;Database=member_center;Username=postgres;Password=postgres";
|
|
|
|
options.UseNpgsql(connectionString);
|
|
options.UseOpenIddict();
|
|
});
|
|
|
|
builder.Services
|
|
.AddIdentity<ApplicationUser, ApplicationRole>(options =>
|
|
{
|
|
options.User.RequireUniqueEmail = true;
|
|
options.Password.RequireDigit = true;
|
|
options.Password.RequireLowercase = true;
|
|
options.Password.RequireUppercase = true;
|
|
options.Password.RequireNonAlphanumeric = false;
|
|
options.Password.RequiredLength = 8;
|
|
})
|
|
.AddEntityFrameworkStores<MemberCenterDbContext>()
|
|
.AddDefaultTokenProviders();
|
|
|
|
builder.Services.ConfigureApplicationCookie(options =>
|
|
{
|
|
options.LoginPath = "/account/login";
|
|
});
|
|
|
|
builder.Services.AddAuthorization(options =>
|
|
{
|
|
options.AddPolicy("Admin", policy => policy.RequireRole("admin"));
|
|
});
|
|
|
|
builder.Services.AddScoped<INewsletterService, NewsletterService>();
|
|
builder.Services.AddScoped<IEmailBlacklistService, EmailBlacklistService>();
|
|
builder.Services.AddScoped<ITenantService, TenantService>();
|
|
builder.Services.AddScoped<INewsletterListService, NewsletterListService>();
|
|
builder.Services.AddScoped<IAuditLogService, AuditLogService>();
|
|
builder.Services.AddScoped<ISecuritySettingsService, SecuritySettingsService>();
|
|
builder.Services.AddScoped<ISubscriptionAdminService, SubscriptionAdminService>();
|
|
|
|
builder.Services.AddOpenIddict()
|
|
.AddCore(options =>
|
|
{
|
|
options.UseEntityFrameworkCore()
|
|
.UseDbContext<MemberCenterDbContext>()
|
|
.ReplaceDefaultEntities<Guid>();
|
|
});
|
|
|
|
builder.Services.AddControllersWithViews()
|
|
.AddRazorOptions(options =>
|
|
{
|
|
options.ViewLocationFormats.Insert(0, "/Views/Admin/{1}/{0}.cshtml");
|
|
options.ViewLocationFormats.Insert(0, "/Views/Admin/Shared/{0}.cshtml");
|
|
});
|
|
|
|
var app = builder.Build();
|
|
|
|
if (!app.Environment.IsDevelopment())
|
|
{
|
|
app.UseExceptionHandler("/Home/Error");
|
|
app.UseHsts();
|
|
}
|
|
|
|
app.UseRouting();
|
|
app.UseAuthentication();
|
|
app.UseAuthorization();
|
|
|
|
app.MapControllerRoute(
|
|
name: "default",
|
|
pattern: "{controller=Home}/{action=Index}/{id?}");
|
|
|
|
app.Run();
|