diff options
| author | Jake Mannens <jake@asger.xyz> | 2023-09-14 14:41:40 +1000 |
|---|---|---|
| committer | Jake Mannens <jake@asger.xyz> | 2023-09-14 14:41:40 +1000 |
| commit | 604ef537e0fabfbcc3abf9d7473b22f08dc549a6 (patch) | |
| tree | e3ba3b1c54c245f10ca8b2abbc4fe24d648868f8 /HBContext.cs | |
| parent | b3654a2764873cef9f171bb6ccd6726feae3e796 (diff) | |
Finalised login functionality
Diffstat (limited to 'HBContext.cs')
| -rw-r--r-- | HBContext.cs | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/HBContext.cs b/HBContext.cs index 415b745..c15c20b 100644 --- a/HBContext.cs +++ b/HBContext.cs @@ -3,14 +3,18 @@ using HyperBooru.Services; namespace HyperBooru; -public class HBContext : DbContext { - public const int NsfwTagId = -1; - public const int IngestTagId = -2; +enum HBObjectId { + NsfwTag = -1, + IngestTag = -2, + AdminUser = -3 +} +public class HBContext : DbContext { public static readonly Guid NsfwTag = new("EBDAD4F8-455A-4351-8017-1D4854D6FA38"); public static readonly Guid IngestTag = new("EA212801-5BCC-4C0E-814F-FB9D30DB58BC"); public DbSet<HBObject> Objects { get; set; } + public DbSet<User> Users { get; set; } public DbSet<TagDefinition> TagDefinitions { get; set; } public DbSet<Tag> Tags { get; set; } public DbSet<Media> Media { get; set; } @@ -42,19 +46,28 @@ public class HBContext : DbContext { // These should NEVER change modelBuilder.Entity<TagDefinition>().HasData(new TagDefinition[] { new() { - ObjectId = NsfwTagId, + ObjectId = (int) HBObjectId.NsfwTag, Guid = NsfwTag, Source = TagSource.Internal, Name = "nsfw" }, new() { - ObjectId = IngestTagId, + ObjectId = (int) HBObjectId.IngestTag, Guid = IngestTag, Source = TagSource.Internal, Name = "ingest" } }); + // Seed initial admin user + modelBuilder.Entity<User>().HasData(new User[] { + new() { + ObjectId = (int) HBObjectId.AdminUser, + Username = "admin", + PasswordHash = UserService.HashPassword("admin") + } + }); + // Some complex relationships cannot be inferred and require // additional configuration, as seen below. modelBuilder.Entity<TagDefinition>() |
