40 lines
1.5 KiB
C#
40 lines
1.5 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
|
|
|
namespace Server.Data;
|
|
|
|
public sealed class Account
|
|
{
|
|
public ulong Id { get; set; }
|
|
public string Username { get; set; } = "";
|
|
public string? Email { get; set; }
|
|
public byte[] PasswordHash { get; set; } = Array.Empty<byte>();
|
|
public byte[] PasswordSalt { get; set; } = Array.Empty<byte>();
|
|
public bool IsBanned { get; set; }
|
|
public DateTime? BannedUntil { get; set; }
|
|
public DateTime CreatedAt { get; set; }
|
|
public DateTime UpdatedAt { get; set; }
|
|
|
|
public ICollection<Session> Sessions { get; set; } = new List<Session>();
|
|
public ICollection<Character> Characters { get; set; } = new List<Character>();
|
|
}
|
|
|
|
public sealed class AccountConfig : IEntityTypeConfiguration<Account>
|
|
{
|
|
public void Configure(EntityTypeBuilder<Account> e)
|
|
{
|
|
e.ToTable("accounts");
|
|
e.HasKey(x => x.Id);
|
|
e.Property(x => x.Id).ValueGeneratedOnAdd();
|
|
e.Property(x => x.Username).HasMaxLength(32).IsRequired();
|
|
e.Property(x => x.Email).HasMaxLength(255);
|
|
e.HasIndex(x => x.Username).IsUnique();
|
|
e.HasIndex(x => x.Email).IsUnique();
|
|
e.Property(x => x.PasswordHash).HasColumnType("varbinary(64)");
|
|
e.Property(x => x.PasswordSalt).HasColumnType("varbinary(32)");
|
|
e.Property(x => x.CreatedAt).HasDefaultValueSql("CURRENT_TIMESTAMP(6)");
|
|
e.Property(x => x.UpdatedAt).HasDefaultValueSql("CURRENT_TIMESTAMP(6)")
|
|
.ValueGeneratedOnAddOrUpdate();
|
|
}
|
|
}
|