feat: replace Token with User

This commit is contained in:
cswimr 2025-01-30 17:48:16 +00:00
parent 3cad9b1d13
commit 608e9a7f9e
Signed by: cswimr
GPG key ID: 0EC431A8DA8F8087
3 changed files with 23 additions and 10 deletions

View file

@ -6,7 +6,7 @@ namespace Myhm.Data
public class MyhmContext(DbContextOptions<MyhmContext> options) : DbContext(options)
{
public DbSet<Moderation> Moderation { get; set; } = default!;
public DbSet<Token> Token { get; set; } = default!;
public DbSet<User> User { get; set; } = default!;
protected override void OnModelCreating(ModelBuilder modelBuilder)
{

View file

@ -1,9 +0,0 @@
namespace Myhm.Data;
public class Token
{
public int Id { get; set; }
public string String { get; set; } = default!;
public int DiscordUserId { get; set; }
public DateTime CreatedAt { get; set; }
}

22
Data/User.cs Normal file
View file

@ -0,0 +1,22 @@
namespace Myhm.Data;
public class User
{
public int Id { get; set; }
public string Token { get; set; } = default!;
public int DiscordUserId { get; set; }
public DateTime CreatedAt { get; set; }
public bool WriteAccess { get; set; } = false;
public bool Disabled { get; set; } = false;
public static User FromToken(string token, MyhmContext context)
{
User user =
context.User.First(u => u.Token == token) ?? throw new Exception("User not found");
if (user.Disabled)
{
throw new Exception("User not found");
}
return user;
}
}