adding hidden basic asp.net core backend (#30)
Base functionality:
DB
email sending
user registration & login
storing new characters and reading them back
Notes:
Functionality is "hidden" with no links pointing to it.
Most pages are scaffolded and not reviewed at all :(
local Dev db setup is pushed to git
NO local email setup :(
This commit is contained in:
+30
-18
@@ -1,32 +1,40 @@
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Identity.UI;
|
||||
using Kemkas.Web.Config;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Kemkas.Web.Data;
|
||||
using Kemkas.Web.Models;
|
||||
using Kemkas.Web.Db;
|
||||
using Kemkas.Web.Db.Models;
|
||||
using Kemkas.Web.Services.Character;
|
||||
using Kemkas.Web.Services.Identity;
|
||||
using Microsoft.AspNetCore.DataProtection;
|
||||
using Microsoft.AspNetCore.Identity.UI.Services;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Add services to the container.
|
||||
|
||||
builder.Services.Configure<MailgunOptions>(builder.Configuration.GetSection(MailgunOptions.Section));
|
||||
|
||||
var connectionString = builder.Configuration.GetConnectionString("DefaultConnection") ??
|
||||
throw new InvalidOperationException("Connection string 'DefaultConnection' not found.");
|
||||
builder.Services.AddDbContext<ApplicationDbContext>(
|
||||
options =>
|
||||
options.UseSqlite(connectionString));
|
||||
builder.Services.AddDatabaseDeveloperPageExceptionFilter();
|
||||
options.UseNpgsql(connectionString));
|
||||
|
||||
builder.Services.AddDataProtection()
|
||||
.SetApplicationName("kemkas")
|
||||
.PersistKeysToDbContext<ApplicationDbContext>();
|
||||
|
||||
builder.Services.AddHttpClient();
|
||||
builder.Services.AddSingleton<IEmailSender, MailgunEmailSender>();
|
||||
|
||||
builder.Services.AddDefaultIdentity<ApplicationUser>(options => options.SignIn.RequireConfirmedAccount = true)
|
||||
.AddEntityFrameworkStores<ApplicationDbContext>();
|
||||
|
||||
builder.Services.AddIdentityServer()
|
||||
.AddApiAuthorization<ApplicationUser, ApplicationDbContext>();
|
||||
|
||||
// builder.Services.AddAuthentication()
|
||||
// .AddIdentityServerJwt();
|
||||
builder.Services.AddAuthentication();
|
||||
|
||||
builder.Services.AddControllersWithViews();
|
||||
builder.Services.AddRazorPages();
|
||||
|
||||
builder.Services.AddCharacterServices();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
@@ -37,16 +45,20 @@ if (app.Environment.IsDevelopment())
|
||||
else
|
||||
{
|
||||
// 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.UseHsts(); // TODO: check if this should be handled by proxy
|
||||
}
|
||||
|
||||
await using (var scope = app.Services.CreateAsyncScope())
|
||||
{
|
||||
var db = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
|
||||
await db.Database.MigrateAsync();
|
||||
}
|
||||
|
||||
// app.UseHttpsRedirection(); // reverse proxy should take care of that
|
||||
app.UseStaticFiles();
|
||||
app.UseRouting();
|
||||
|
||||
// app.UseAuthentication();
|
||||
// app.UseIdentityServer();
|
||||
// app.UseAuthorization();
|
||||
app.UseAuthentication();
|
||||
app.UseAuthorization();
|
||||
|
||||
app.MapControllerRoute(
|
||||
name: "default",
|
||||
|
||||
Reference in New Issue
Block a user