:drunk: No idea what did AI did
This commit is contained in:
74
DysonNetwork.Pass/Features/Auth/Models/AccountAuthFactor.cs
Normal file
74
DysonNetwork.Pass/Features/Auth/Models/AccountAuthFactor.cs
Normal 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();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user