2023-01-26 00:29:00 -06:00
|
|
|
using BeaconLib;
|
2023-01-02 15:44:04 -06:00
|
|
|
using LANCommander.Data;
|
|
|
|
|
using LANCommander.Data.Models;
|
2023-01-09 01:05:40 -06:00
|
|
|
using LANCommander.Services;
|
2023-01-04 23:45:11 -06:00
|
|
|
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
2023-01-02 15:44:04 -06:00
|
|
|
using Microsoft.AspNetCore.Identity;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2023-01-03 01:06:48 -06:00
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2023-01-04 23:45:11 -06:00
|
|
|
using Microsoft.IdentityModel.Tokens;
|
2023-02-04 12:18:10 -06:00
|
|
|
using MudBlazor.Services;
|
2023-01-04 23:45:11 -06:00
|
|
|
using System.Text;
|
2023-01-02 15:44:04 -06:00
|
|
|
|
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
|
|
2023-01-04 23:45:11 -06:00
|
|
|
ConfigurationManager configuration = builder.Configuration;
|
|
|
|
|
|
2023-01-02 15:44:04 -06:00
|
|
|
// Add services to the container.
|
|
|
|
|
var connectionString = builder.Configuration.GetConnectionString("DefaultConnection");
|
2023-01-26 00:27:52 -06:00
|
|
|
var settings = SettingService.GetSettings();
|
|
|
|
|
|
2023-02-04 12:18:10 -06:00
|
|
|
builder.Services.AddRazorPages();
|
|
|
|
|
builder.Services.AddServerSideBlazor();
|
|
|
|
|
|
2023-01-26 00:27:52 -06:00
|
|
|
builder.WebHost.ConfigureKestrel(options =>
|
|
|
|
|
{
|
|
|
|
|
// Configure as HTTP only
|
|
|
|
|
options.ListenAnyIP(settings.Port);
|
|
|
|
|
});
|
2023-01-02 18:31:17 -06:00
|
|
|
|
|
|
|
|
builder.Services.AddDbContext<LANCommander.Data.DatabaseContext>(b =>
|
|
|
|
|
{
|
|
|
|
|
b.UseLazyLoadingProxies();
|
2023-01-26 01:10:32 -06:00
|
|
|
b.UseSqlite(settings.DatabaseConnectionString);
|
2023-01-02 18:31:17 -06:00
|
|
|
});
|
2023-01-02 15:44:04 -06:00
|
|
|
|
|
|
|
|
builder.Services.AddDatabaseDeveloperPageExceptionFilter();
|
|
|
|
|
|
2023-01-04 23:45:11 -06:00
|
|
|
builder.Services.AddDefaultIdentity<User>((IdentityOptions options) =>
|
|
|
|
|
{
|
2023-01-03 19:41:28 -06:00
|
|
|
options.SignIn.RequireConfirmedAccount = false;
|
2023-01-02 15:44:04 -06:00
|
|
|
options.Password.RequireNonAlphanumeric = false;
|
|
|
|
|
options.SignIn.RequireConfirmedEmail = false;
|
2023-01-04 01:46:31 -06:00
|
|
|
})
|
|
|
|
|
.AddRoles<Role>()
|
2023-01-04 23:45:11 -06:00
|
|
|
.AddEntityFrameworkStores<LANCommander.Data.DatabaseContext>()
|
|
|
|
|
.AddDefaultTokenProviders();
|
|
|
|
|
|
|
|
|
|
builder.Services.AddAuthentication(options =>
|
|
|
|
|
{
|
|
|
|
|
/*options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
|
|
|
|
|
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
|
|
|
|
|
options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme;*/
|
|
|
|
|
})
|
|
|
|
|
.AddJwtBearer(options =>
|
|
|
|
|
{
|
|
|
|
|
options.SaveToken = true;
|
|
|
|
|
options.RequireHttpsMetadata = false;
|
|
|
|
|
options.TokenValidationParameters = new TokenValidationParameters()
|
|
|
|
|
{
|
|
|
|
|
ValidateIssuer = false,
|
|
|
|
|
ValidateAudience = false,
|
|
|
|
|
// ValidAudience = configuration["JWT:ValidAudience"],
|
|
|
|
|
// ValidIssuer = configuration["JWT:ValidIssuer"],
|
2023-01-26 01:10:32 -06:00
|
|
|
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(settings.TokenSecret))
|
2023-01-04 23:45:11 -06:00
|
|
|
};
|
|
|
|
|
});
|
2023-01-02 15:44:04 -06:00
|
|
|
|
2023-01-04 20:00:11 -06:00
|
|
|
builder.Services.AddControllersWithViews().AddJsonOptions(x =>
|
|
|
|
|
{
|
|
|
|
|
x.JsonSerializerOptions.ReferenceHandler = System.Text.Json.Serialization.ReferenceHandler.IgnoreCycles;
|
|
|
|
|
});
|
2023-02-04 12:18:10 -06:00
|
|
|
|
|
|
|
|
builder.Services.AddMudServices();
|
2023-01-02 15:44:04 -06:00
|
|
|
|
2023-01-10 02:25:16 -06:00
|
|
|
builder.Services.AddScoped<SettingService>();
|
2023-01-09 01:05:40 -06:00
|
|
|
builder.Services.AddScoped<ArchiveService>();
|
|
|
|
|
builder.Services.AddScoped<CategoryService>();
|
|
|
|
|
builder.Services.AddScoped<GameService>();
|
2023-01-15 03:11:51 -06:00
|
|
|
builder.Services.AddScoped<ScriptService>();
|
2023-01-09 01:05:40 -06:00
|
|
|
builder.Services.AddScoped<GenreService>();
|
|
|
|
|
builder.Services.AddScoped<KeyService>();
|
|
|
|
|
builder.Services.AddScoped<TagService>();
|
2023-01-10 02:25:16 -06:00
|
|
|
builder.Services.AddScoped<CompanyService>();
|
|
|
|
|
builder.Services.AddScoped<IGDBService>();
|
2023-01-09 01:05:40 -06:00
|
|
|
|
2023-01-26 00:29:00 -06:00
|
|
|
if (settings.Beacon)
|
|
|
|
|
builder.Services.AddHostedService<BeaconService>();
|
|
|
|
|
|
2023-02-04 12:18:10 -06:00
|
|
|
builder.WebHost.UseStaticWebAssets();
|
|
|
|
|
|
2023-01-02 15:44:04 -06:00
|
|
|
var app = builder.Build();
|
|
|
|
|
|
|
|
|
|
// Configure the HTTP request pipeline.
|
|
|
|
|
if (app.Environment.IsDevelopment())
|
|
|
|
|
{
|
|
|
|
|
app.UseMigrationsEndPoint();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
app.UseExceptionHandler("/Home/Error");
|
|
|
|
|
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
|
|
|
|
|
app.UseHsts();
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-24 18:23:32 -06:00
|
|
|
// app.UseHttpsRedirection();
|
2023-01-02 15:44:04 -06:00
|
|
|
app.UseStaticFiles();
|
|
|
|
|
|
|
|
|
|
app.UseRouting();
|
|
|
|
|
|
|
|
|
|
app.UseAuthentication();
|
|
|
|
|
app.UseAuthorization();
|
|
|
|
|
|
|
|
|
|
app.MapControllers();
|
2023-02-04 12:18:10 -06:00
|
|
|
app.MapBlazorHub();
|
|
|
|
|
app.MapFallbackToPage("/_Host");
|
2023-01-02 15:44:04 -06:00
|
|
|
|
2023-01-03 17:37:13 -06:00
|
|
|
if (!Directory.Exists("Upload"))
|
|
|
|
|
Directory.CreateDirectory("Upload");
|
|
|
|
|
|
2023-01-09 01:35:08 -06:00
|
|
|
if (!Directory.Exists("Icon"))
|
|
|
|
|
Directory.CreateDirectory("Icon");
|
|
|
|
|
|
2023-01-17 17:57:12 -06:00
|
|
|
if (!Directory.Exists("Save"))
|
|
|
|
|
Directory.CreateDirectory("Save");
|
|
|
|
|
|
2023-01-04 01:46:31 -06:00
|
|
|
app.Run();
|