mirror of
https://github.com/whoswhip/Sharpbin.git
synced 2026-12-06 02:48:43 +00:00
feat: email verification via smtp
This commit is contained in:
@@ -12,6 +12,7 @@ namespace SharpbinV3.Server.Data
|
||||
public DbSet<UserTotp> UserTotps => Set<UserTotp>();
|
||||
public DbSet<Report> Reports => Set<Report>();
|
||||
public DbSet<ApiKey> ApiKeys => Set<ApiKey>();
|
||||
public DbSet<EmailVerificationToken> EmailVerificationTokens => Set<EmailVerificationToken>();
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
@@ -63,6 +64,12 @@ namespace SharpbinV3.Server.Data
|
||||
.WithMany(u => u.ApiKeys)
|
||||
.HasForeignKey(a => a.UserUUID)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
modelBuilder.Entity<EmailVerificationToken>()
|
||||
.HasOne(a => a.User)
|
||||
.WithMany(u => u.EmailVerificationTokens)
|
||||
.HasForeignKey(a => a.UserUUID)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace SharpbinV3.Server.Data.Entities
|
||||
{
|
||||
public enum EmailTokenType
|
||||
{
|
||||
VerifyEmail,
|
||||
ResetPassword,
|
||||
ChangeEmail,
|
||||
DeleteAccount,
|
||||
}
|
||||
|
||||
public sealed class EmailVerificationToken
|
||||
{
|
||||
[Key]
|
||||
public Guid UUID { get; set; } = Guid.CreateVersion7();
|
||||
public required Guid UserUUID { get; set; }
|
||||
public User User { get; set; } = null!;
|
||||
public required string TokenHash { get; set; }
|
||||
public long CreatedAt { get; set; } = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
||||
public long ExpiresAt { get; set; }
|
||||
public required EmailTokenType Type { get; set; }
|
||||
public bool Used { get; set; } = false;
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,8 @@ namespace SharpbinV3.Server.Data.Entities
|
||||
public required string PasswordHash { get; set; }
|
||||
|
||||
public string? Email { get; set; }
|
||||
public bool EmailVerified { get; set; } = false;
|
||||
|
||||
public string? DisplayName { get; set; }
|
||||
public long? LastLogin { get; set; }
|
||||
|
||||
@@ -24,6 +26,7 @@ namespace SharpbinV3.Server.Data.Entities
|
||||
public List<RefreshToken> RefreshTokens { get; set; } = [];
|
||||
public List<Report> Reports { get; set; } = [];
|
||||
public List<ApiKey> ApiKeys { get; set; } = [];
|
||||
public List<EmailVerificationToken> EmailVerificationTokens { get; set; } = [];
|
||||
public UserTotp? Totp { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user