Separate dashboard port, first-run password setup and default trusted proxies
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a34ff96490
commit
c22d452720
25 files changed
+654
-109
No files matched your search
@@ -0,0 +1,43 @@
|
||||
using Flypaper.Storage.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Flypaper.Storage.Settings;
|
||||
|
||||
public sealed class AdminCredentialStore(IDbContextFactory<FlypaperDbContext> dbContextFactory)
|
||||
{
|
||||
private const string PasswordHashKey = "Flypaper:Admin:PasswordHash";
|
||||
|
||||
public async Task<string?> GetPasswordHashAsync(CancellationToken ct = default)
|
||||
{
|
||||
await using var db = await dbContextFactory.CreateDbContextAsync(ct);
|
||||
return await db.Settings.Where(s => s.Key == PasswordHashKey).Select(s => s.Value).SingleOrDefaultAsync(ct);
|
||||
}
|
||||
|
||||
public async Task<bool> TryCreatePasswordHashAsync(string hash, CancellationToken ct = default)
|
||||
{
|
||||
await using var db = await dbContextFactory.CreateDbContextAsync(ct);
|
||||
db.Settings.Add(new SettingEntity { Key = PasswordHashKey, Value = hash });
|
||||
try
|
||||
{
|
||||
await db.SaveChangesAsync(ct);
|
||||
return true;
|
||||
}
|
||||
catch (DbUpdateException)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task UpdatePasswordHashAsync(string hash, CancellationToken ct = default)
|
||||
{
|
||||
await using var db = await dbContextFactory.CreateDbContextAsync(ct);
|
||||
var updated = await db.Settings
|
||||
.Where(s => s.Key == PasswordHashKey)
|
||||
.ExecuteUpdateAsync(setters => setters.SetProperty(s => s.Value, hash), ct);
|
||||
if (updated == 0)
|
||||
{
|
||||
db.Settings.Add(new SettingEntity { Key = PasswordHashKey, Value = hash });
|
||||
await db.SaveChangesAsync(ct);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user