feat: replace Token with User
This commit is contained in:
parent
3cad9b1d13
commit
608e9a7f9e
3 changed files with 23 additions and 10 deletions
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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
22
Data/User.cs
Normal 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;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue