2026-02-02 04:45:56 -06:00
|
|
|
namespace FiscalOS.Core.Identity;
|
2026-02-01 06:13:08 -06:00
|
|
|
|
2026-02-02 04:45:56 -06:00
|
|
|
public sealed class User : Entity
|
2026-02-01 06:13:08 -06:00
|
|
|
{
|
2026-02-01 08:07:23 -06:00
|
|
|
public string Username { get; init; } = string.Empty;
|
2026-02-02 04:45:56 -06:00
|
|
|
public string HashedPassword { get; init; } = string.Empty;
|
2026-02-06 06:44:24 -06:00
|
|
|
public string EncryptionKeyId { get; init; } = string.Empty;
|
|
|
|
|
public string EncryptedDataKey { get; init; } = string.Empty;
|
2026-02-01 08:07:23 -06:00
|
|
|
|
2026-02-12 16:19:21 -06:00
|
|
|
private readonly List<RefreshToken> _refreshTokens = [];
|
2026-02-03 11:06:54 -06:00
|
|
|
public IEnumerable<RefreshToken> RefreshTokens => _refreshTokens;
|
2026-02-02 13:17:43 -06:00
|
|
|
|
2026-02-12 16:19:21 -06:00
|
|
|
private readonly List<Institution> _institutions = [];
|
|
|
|
|
public IEnumerable<Institution> Institutions => _institutions;
|
|
|
|
|
|
2026-02-02 13:17:43 -06:00
|
|
|
private User()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static User New()
|
|
|
|
|
{
|
|
|
|
|
return new();
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-06 06:44:24 -06:00
|
|
|
public static User From(string username, string hashedPassword, EncryptedDataKey encryptedDataKey)
|
2026-02-02 13:17:43 -06:00
|
|
|
{
|
2026-02-12 20:46:32 -06:00
|
|
|
ArgumentNullException.ThrowIfNull(username, nameof(username));
|
|
|
|
|
ArgumentNullException.ThrowIfNull(hashedPassword, nameof(hashedPassword));
|
|
|
|
|
ArgumentNullException.ThrowIfNull(encryptedDataKey, nameof(encryptedDataKey));
|
2026-02-06 06:44:24 -06:00
|
|
|
|
2026-02-02 13:17:43 -06:00
|
|
|
return new()
|
|
|
|
|
{
|
|
|
|
|
Username = username,
|
|
|
|
|
HashedPassword = hashedPassword,
|
2026-02-06 06:44:24 -06:00
|
|
|
EncryptedDataKey = encryptedDataKey.EncryptedKey,
|
|
|
|
|
EncryptionKeyId = encryptedDataKey.KeyIdUsed,
|
2026-02-02 13:17:43 -06:00
|
|
|
};
|
|
|
|
|
}
|
2026-02-03 11:06:54 -06:00
|
|
|
|
|
|
|
|
public void AddRefreshToken(RefreshToken refreshToken)
|
|
|
|
|
{
|
2026-02-12 20:46:32 -06:00
|
|
|
ArgumentNullException.ThrowIfNull(refreshToken, nameof(refreshToken));
|
2026-02-03 11:06:54 -06:00
|
|
|
|
|
|
|
|
_refreshTokens.Add(refreshToken);
|
|
|
|
|
}
|
2026-02-12 16:19:21 -06:00
|
|
|
|
|
|
|
|
public void AddInstitution(Institution institution)
|
|
|
|
|
{
|
2026-02-12 20:46:32 -06:00
|
|
|
ArgumentNullException.ThrowIfNull(institution, nameof(institution));
|
2026-02-12 16:19:21 -06:00
|
|
|
|
|
|
|
|
_institutions.Add(institution);
|
|
|
|
|
}
|
2026-02-01 06:13:08 -06:00
|
|
|
}
|