add user + claim + role entities
This commit is contained in:
@@ -2,6 +2,11 @@
|
||||
{
|
||||
public static class Constants
|
||||
{
|
||||
public static class Database
|
||||
{
|
||||
public const string SharedAppId = "shared";
|
||||
}
|
||||
|
||||
public static class Sections
|
||||
{
|
||||
public const string Dashboard = "dashboard";
|
||||
|
||||
@@ -0,0 +1,154 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace unjo.Core.Entities
|
||||
{
|
||||
public class BackofficeUser : DatabaseEntity, IBackofficeUser
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public bool IsSuper { get; set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public string Email { get; set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public string PasswordHash { get; set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public string SecurityStamp { get; set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Media Avatar { get; set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public string LanguageId { get; set; }
|
||||
|
||||
|
||||
|
||||
/// <inheritdoc/>
|
||||
public List<string> RoleIds { get; set; } = new List<string>();
|
||||
|
||||
/// <inheritdoc/>
|
||||
public List<IBackofficeUserClaim> Claims { get; set; } = new List<IBackofficeUserClaim>();
|
||||
|
||||
|
||||
|
||||
/// <inheritdoc/>
|
||||
public string PasswordResetToken { get; set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public DateTimeOffset? PasswordResetTokenExpirationDate { get; set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public int FailedPasswordAttempts { get; set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool IsLockedOut { get; set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public DateTimeOffset? LockoutEndDate { get; set; }
|
||||
|
||||
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool TwoFactorEnabled { get; set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public string TwoFactorAuthenticatorKey { get; set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public List<string> TwoFactorRecoveryCodes { get; set; } = new List<string>();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public interface IBackofficeUser : IDatabaseEntity
|
||||
{
|
||||
/// <summary>
|
||||
/// sudo.
|
||||
/// The user who created the instance.
|
||||
/// </summary>
|
||||
bool IsSuper { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// E-Mail address which is also used as the username
|
||||
/// </summary>
|
||||
string Email { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The password hash
|
||||
/// </summary>
|
||||
string PasswordHash { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The security stamp
|
||||
/// </summary>
|
||||
string SecurityStamp { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Avatar image
|
||||
/// </summary>
|
||||
Media Avatar { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Backoffice display language
|
||||
/// </summary>
|
||||
string LanguageId { get; set; }
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The roles of the user
|
||||
/// </summary>
|
||||
List<string> RoleIds { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The user's claims, for use in claims-based authentication.
|
||||
/// </summary>
|
||||
List<IBackofficeUserClaim> Claims { get; set; }
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// A hash which is used to validate a password-change request
|
||||
/// </summary>
|
||||
string PasswordResetToken { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The date when the current password-reset hash expires
|
||||
/// </summary>
|
||||
DateTimeOffset? PasswordResetTokenExpirationDate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Number of times sign in failed.
|
||||
/// </summary>
|
||||
int FailedPasswordAttempts { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether the user is locked out.
|
||||
/// </summary>
|
||||
bool IsLockedOut { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// When the user lock out is over.
|
||||
/// </summary>
|
||||
DateTimeOffset? LockoutEndDate { get; set; }
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Whether 2-factor authentication is enabled or not
|
||||
/// </summary>
|
||||
bool TwoFactorEnabled { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The two-factor authenticator key
|
||||
/// </summary>
|
||||
string TwoFactorAuthenticatorKey { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The list of two factor authentication recovery codes
|
||||
/// </summary>
|
||||
List<string> TwoFactorRecoveryCodes { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
using System.Security.Claims;
|
||||
|
||||
namespace unjo.Core.Entities
|
||||
{
|
||||
public class BackofficeUserClaim : IBackofficeUserClaim
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public string Type { get; set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public string Value { get; set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Claim ToClaim() => new Claim(Type, Value);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void FromClaim(Claim other)
|
||||
{
|
||||
Type = other?.Type;
|
||||
Value = other?.Value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public interface IBackofficeUserClaim
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the claim type for this claim
|
||||
/// </summary>
|
||||
string Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the claim value for this claim
|
||||
/// </summary>
|
||||
string Value { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new claim with the type and value
|
||||
/// </summary>
|
||||
void FromClaim(Claim other);
|
||||
|
||||
/// <summary>
|
||||
/// Initializes by copying ClaimType and ClaimValue from the other claim
|
||||
/// </summary>
|
||||
Claim ToClaim();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace unjo.Core.Entities
|
||||
{
|
||||
public class BackofficeUserRole : DatabaseEntity, IBackofficeUserRole
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public string Alias { get; set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public string Icon { get; set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public List<IBackofficeUserClaim> Claims { get; set; } = new List<IBackofficeUserClaim>();
|
||||
}
|
||||
|
||||
|
||||
public interface IBackofficeUserRole : IDatabaseEntity
|
||||
{
|
||||
/// <summary>
|
||||
/// Alias for natural queries
|
||||
/// </summary>
|
||||
string Alias { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Displayed icon alongside name
|
||||
/// </summary>
|
||||
string Icon { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The user's claims, for use in claims-based authentication.
|
||||
/// </summary>
|
||||
List<IBackofficeUserClaim> Claims { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -5,38 +5,60 @@ using unjo.Core.Attributes;
|
||||
namespace unjo.Core.Entities
|
||||
{
|
||||
[DebuggerDisplay("Id = {Id,nq}, Name = {Name}")]
|
||||
public abstract class DatabaseEntity
|
||||
public abstract class DatabaseEntity : IDatabaseEntity
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
[GenerateId]
|
||||
public string Id { get; set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
[MapAppId]
|
||||
public string AppId { get; set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public uint Sort { get; set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool IsActive { get; set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public DateTimeOffset CreatedDate { get; set; }
|
||||
}
|
||||
|
||||
|
||||
public interface IDatabaseEntity
|
||||
{
|
||||
/// <summary>
|
||||
/// Id of the entity
|
||||
/// </summary>
|
||||
[GenerateId]
|
||||
public string Id { get; set; }
|
||||
string Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Id of the associated application (auto-filled)
|
||||
/// </summary>
|
||||
[MapAppId]
|
||||
public string AppId { get; set; }
|
||||
string AppId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Full name of the entity
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Sort order
|
||||
/// </summary>
|
||||
public uint Sort { get; set; }
|
||||
uint Sort { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether the entity is visible in the frontend
|
||||
/// </summary>
|
||||
public bool IsPublished { get; set; }
|
||||
bool IsActive { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Date of creation
|
||||
/// </summary>
|
||||
public DateTimeOffset CreatedDate { get; set; }
|
||||
DateTimeOffset CreatedDate { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,4 +10,4 @@
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="3.1.2" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
</Project>
|
||||
Reference in New Issue
Block a user