Conditional Identity
This commit is contained in:
parent
817328f679
commit
cf98fd0a68
2 changed files with 20 additions and 3 deletions
18
Program.cs
18
Program.cs
|
|
@ -18,8 +18,13 @@ builder.Services.AddDbContext<ApplicationDbContext>(options =>
|
|||
options.UseSqlite(connectionString));
|
||||
builder.Services.AddDatabaseDeveloperPageExceptionFilter();
|
||||
|
||||
bool adminAuthenticate = builder.Configuration.GetValue("Admin:Authentication", true);
|
||||
if (adminAuthenticate)
|
||||
{
|
||||
builder.Services.AddDefaultIdentity<IdentityUser>(options => options.SignIn.RequireConfirmedAccount = true)
|
||||
.AddEntityFrameworkStores<ApplicationDbContext>();
|
||||
}
|
||||
|
||||
builder.Services.AddRazorPages();
|
||||
|
||||
builder.Services.Configure<DhcpOptions>(builder.Configuration.GetRequiredSection("Dhcp"));
|
||||
|
|
@ -64,7 +69,7 @@ else
|
|||
|
||||
app.UseRouting();
|
||||
|
||||
if (app.Configuration.GetValue("Admin:Authentication", true))
|
||||
if (adminAuthenticate)
|
||||
{
|
||||
app.UseAuthorization();
|
||||
}
|
||||
|
|
@ -72,4 +77,15 @@ if (app.Configuration.GetValue("Admin:Authentication", true))
|
|||
app.UseStaticFiles();
|
||||
app.MapRazorPages();
|
||||
|
||||
using (var scope = app.Services.CreateScope())
|
||||
{
|
||||
using var appDb = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
|
||||
appDb.Database.Migrate();
|
||||
|
||||
if (adminAuthenticate)
|
||||
{
|
||||
/* TODO: Generate Admin Account if None found */
|
||||
}
|
||||
}
|
||||
|
||||
app.Run();
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
[Unit]
|
||||
Description=PowerDNS/DHCP Companion Remote
|
||||
After=kea-dhcp.service
|
||||
Before=pdns.service
|
||||
|
||||
[Service]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue