:drunk: No idea what did AI did

This commit is contained in:
2025-07-06 19:46:59 +08:00
parent 14b79f16f4
commit 3391c08c04
40 changed files with 2484 additions and 112 deletions

View File

@ -0,0 +1,74 @@
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text.Json;
using DysonNetwork.Common.Models;
using NodaTime;
namespace DysonNetwork.Pass.Features.Auth.Models;
public class AccountAuthFactor : ModelBase
{
[Required]
public Guid AccountId { get; set; }
[ForeignKey(nameof(AccountId))]
public virtual Account Account { get; set; } = null!;
[Required]
public AuthFactorType FactorType { get; set; }
[Required]
[MaxLength(100)]
public string Name { get; set; } = string.Empty;
[MaxLength(500)]
public string? Description { get; set; }
[Required]
public string Secret { get; set; } = string.Empty;
[Required]
public bool IsDefault { get; set; }
[Required]
public bool IsBackup { get; set; }
public Instant? LastUsedAt { get; set; }
public Instant? EnabledAt { get; set; }
public Instant? DisabledAt { get; set; }
[Column(TypeName = "jsonb")]
public JsonDocument? Metadata { get; set; }
// Navigation property for related AuthSessions
public virtual ICollection<AuthSession> Sessions { get; set; } = new List<AuthSession>();
public void UpdateMetadata(Action<JsonDocument> updateAction)
{
if (Metadata == null)
{
Metadata = JsonSerializer.SerializeToDocument(new { });
}
updateAction(Metadata);
}
public void MarkAsUsed()
{
LastUsedAt = SystemClock.Instance.GetCurrentInstant();
}
public void Enable()
{
EnabledAt = SystemClock.Instance.GetCurrentInstant();
DisabledAt = null;
}
public void Disable()
{
DisabledAt = SystemClock.Instance.GetCurrentInstant();
}
}