:drunk: AI trying to fix bugs
This commit is contained in:
@ -7,6 +7,15 @@ using OtpNet;
|
||||
|
||||
namespace DysonNetwork.Common.Models;
|
||||
|
||||
public enum AccountStatus
|
||||
{
|
||||
PendingActivation,
|
||||
Active,
|
||||
Suspended,
|
||||
Banned,
|
||||
Deleted
|
||||
}
|
||||
|
||||
[Index(nameof(Name), IsUnique = true)]
|
||||
public class Account : ModelBase
|
||||
{
|
||||
@ -30,6 +39,47 @@ public class Account : ModelBase
|
||||
[JsonIgnore] public ICollection<Relationship> IncomingRelationships { get; set; } = new List<Relationship>();
|
||||
|
||||
[JsonIgnore] public ICollection<Subscription> Subscriptions { get; set; } = new List<Subscription>();
|
||||
|
||||
public AccountStatus Status { get; set; } = AccountStatus.PendingActivation;
|
||||
|
||||
[NotMapped]
|
||||
public string? Email => GetPrimaryEmail();
|
||||
|
||||
public string? GetPrimaryEmail()
|
||||
{
|
||||
return Contacts
|
||||
.FirstOrDefault(c => c.Type == AccountContactType.Email && c.IsPrimary)
|
||||
?.Content;
|
||||
}
|
||||
|
||||
public void SetPrimaryEmail(string email)
|
||||
{
|
||||
// Remove primary flag from existing primary email if any
|
||||
foreach (var contact in Contacts.Where(c => c.Type == AccountContactType.Email && c.IsPrimary))
|
||||
{
|
||||
contact.IsPrimary = false;
|
||||
}
|
||||
|
||||
// Find or create the email contact
|
||||
var emailContact = Contacts.FirstOrDefault(c =>
|
||||
c.Type == AccountContactType.Email &&
|
||||
string.Equals(c.Content, email, StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
if (emailContact == null)
|
||||
{
|
||||
emailContact = new AccountContact
|
||||
{
|
||||
Type = AccountContactType.Email,
|
||||
Content = email,
|
||||
IsPrimary = true
|
||||
};
|
||||
Contacts.Add(emailContact);
|
||||
}
|
||||
else
|
||||
{
|
||||
emailContact.IsPrimary = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class Leveling
|
||||
@ -128,11 +178,28 @@ public class AccountAuthFactor : ModelBase
|
||||
/// </summary>
|
||||
public int Trustworthy { get; set; } = 1;
|
||||
|
||||
[MaxLength(100)]
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
[MaxLength(500)]
|
||||
public string? Description { get; set; }
|
||||
|
||||
public bool IsDefault { get; set; }
|
||||
public bool IsBackup { get; set; }
|
||||
public Instant? LastUsedAt { get; set; }
|
||||
public Instant? EnabledAt { get; set; }
|
||||
public Instant? ExpiredAt { get; set; }
|
||||
public Instant? DisabledAt { get; set; }
|
||||
|
||||
[Column(TypeName = "jsonb")]
|
||||
public Dictionary<string, object>? Metadata { get; set; }
|
||||
|
||||
public Guid AccountId { get; set; }
|
||||
[JsonIgnore] public Account Account { get; set; } = null!;
|
||||
|
||||
// Navigation property for related AuthSessions
|
||||
[JsonIgnore]
|
||||
public virtual ICollection<AuthSession>? Sessions { get; set; }
|
||||
|
||||
public AccountAuthFactor HashSecret(int cost = 12)
|
||||
{
|
||||
@ -174,20 +241,5 @@ public enum AccountAuthFactorType
|
||||
EmailCode,
|
||||
InAppCode,
|
||||
TimedCode,
|
||||
PinCode,
|
||||
}
|
||||
|
||||
public class AccountConnection : ModelBase
|
||||
{
|
||||
public Guid Id { get; set; } = Guid.NewGuid();
|
||||
[MaxLength(4096)] public string Provider { get; set; } = null!;
|
||||
[MaxLength(8192)] public string ProvidedIdentifier { get; set; } = null!;
|
||||
[Column(TypeName = "jsonb")] public Dictionary<string, object>? Meta { get; set; } = new();
|
||||
|
||||
[JsonIgnore] [MaxLength(4096)] public string? AccessToken { get; set; }
|
||||
[JsonIgnore] [MaxLength(4096)] public string? RefreshToken { get; set; }
|
||||
public Instant? LastUsedAt { get; set; }
|
||||
|
||||
public Guid AccountId { get; set; }
|
||||
public Account Account { get; set; } = null!;
|
||||
PinCode
|
||||
}
|
||||
|
Reference in New Issue
Block a user