diff --git a/unjo.Core/Constants.cs b/unjo.Core/Constants.cs index b8f34184..fe7a7864 100644 --- a/unjo.Core/Constants.cs +++ b/unjo.Core/Constants.cs @@ -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"; diff --git a/unjo.Core/Entities/BackofficeUser/BackofficeUser.cs b/unjo.Core/Entities/BackofficeUser/BackofficeUser.cs new file mode 100644 index 00000000..56d34dbf --- /dev/null +++ b/unjo.Core/Entities/BackofficeUser/BackofficeUser.cs @@ -0,0 +1,154 @@ +using System; +using System.Collections.Generic; + +namespace unjo.Core.Entities +{ + public class BackofficeUser : DatabaseEntity, IBackofficeUser + { + /// + public bool IsSuper { get; set; } + + /// + public string Email { get; set; } + + /// + public string PasswordHash { get; set; } + + /// + public string SecurityStamp { get; set; } + + /// + public Media Avatar { get; set; } + + /// + public string LanguageId { get; set; } + + + + /// + public List RoleIds { get; set; } = new List(); + + /// + public List Claims { get; set; } = new List(); + + + + /// + public string PasswordResetToken { get; set; } + + /// + public DateTimeOffset? PasswordResetTokenExpirationDate { get; set; } + + /// + public int FailedPasswordAttempts { get; set; } + + /// + public bool IsLockedOut { get; set; } + + /// + public DateTimeOffset? LockoutEndDate { get; set; } + + + + /// + public bool TwoFactorEnabled { get; set; } + + /// + public string TwoFactorAuthenticatorKey { get; set; } + + /// + public List TwoFactorRecoveryCodes { get; set; } = new List(); + } + + + + public interface IBackofficeUser : IDatabaseEntity + { + /// + /// sudo. + /// The user who created the instance. + /// + bool IsSuper { get; set; } + + /// + /// E-Mail address which is also used as the username + /// + string Email { get; set; } + + /// + /// The password hash + /// + string PasswordHash { get; set; } + + /// + /// The security stamp + /// + string SecurityStamp { get; set; } + + /// + /// Avatar image + /// + Media Avatar { get; set; } + + /// + /// Backoffice display language + /// + string LanguageId { get; set; } + + + + /// + /// The roles of the user + /// + List RoleIds { get; set; } + + /// + /// The user's claims, for use in claims-based authentication. + /// + List Claims { get; set; } + + + + /// + /// A hash which is used to validate a password-change request + /// + string PasswordResetToken { get; set; } + + /// + /// The date when the current password-reset hash expires + /// + DateTimeOffset? PasswordResetTokenExpirationDate { get; set; } + + /// + /// Number of times sign in failed. + /// + int FailedPasswordAttempts { get; set; } + + /// + /// Whether the user is locked out. + /// + bool IsLockedOut { get; set; } + + /// + /// When the user lock out is over. + /// + DateTimeOffset? LockoutEndDate { get; set; } + + + + /// + /// Whether 2-factor authentication is enabled or not + /// + bool TwoFactorEnabled { get; set; } + + /// + /// The two-factor authenticator key + /// + string TwoFactorAuthenticatorKey { get; set; } + + /// + /// The list of two factor authentication recovery codes + /// + List TwoFactorRecoveryCodes { get; set; } + } +} diff --git a/unjo.Core/Entities/BackofficeUser/BackofficeUserClaim.cs b/unjo.Core/Entities/BackofficeUser/BackofficeUserClaim.cs new file mode 100644 index 00000000..cd084772 --- /dev/null +++ b/unjo.Core/Entities/BackofficeUser/BackofficeUserClaim.cs @@ -0,0 +1,48 @@ +using System.Security.Claims; + +namespace unjo.Core.Entities +{ + public class BackofficeUserClaim : IBackofficeUserClaim + { + /// + public string Type { get; set; } + + /// + public string Value { get; set; } + + /// + public Claim ToClaim() => new Claim(Type, Value); + + /// + public void FromClaim(Claim other) + { + Type = other?.Type; + Value = other?.Value; + } + } + + + + public interface IBackofficeUserClaim + { + /// + /// Gets or sets the claim type for this claim + /// + string Type { get; set; } + + /// + /// Gets or sets the claim value for this claim + /// + string Value { get; set; } + + /// + /// Constructs a new claim with the type and value + /// + void FromClaim(Claim other); + + /// + /// Initializes by copying ClaimType and ClaimValue from the other claim + /// + Claim ToClaim(); + } +} diff --git a/unjo.Core/Entities/BackofficeUser/BackofficeUserRole.cs b/unjo.Core/Entities/BackofficeUser/BackofficeUserRole.cs new file mode 100644 index 00000000..8931ec31 --- /dev/null +++ b/unjo.Core/Entities/BackofficeUser/BackofficeUserRole.cs @@ -0,0 +1,35 @@ +using System.Collections.Generic; + +namespace unjo.Core.Entities +{ + public class BackofficeUserRole : DatabaseEntity, IBackofficeUserRole + { + /// + public string Alias { get; set; } + + /// + public string Icon { get; set; } + + /// + public List Claims { get; set; } = new List(); + } + + + public interface IBackofficeUserRole : IDatabaseEntity + { + /// + /// Alias for natural queries + /// + string Alias { get; set; } + + /// + /// Displayed icon alongside name + /// + string Icon { get; set; } + + /// + /// The user's claims, for use in claims-based authentication. + /// + List Claims { get; set; } + } +} diff --git a/unjo.Core/Entities/DatabaseEntity.cs b/unjo.Core/Entities/DatabaseEntity.cs index ce274951..80403907 100644 --- a/unjo.Core/Entities/DatabaseEntity.cs +++ b/unjo.Core/Entities/DatabaseEntity.cs @@ -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 + { + /// + [GenerateId] + public string Id { get; set; } + + /// + [MapAppId] + public string AppId { get; set; } + + /// + public string Name { get; set; } + + /// + public uint Sort { get; set; } + + /// + public bool IsActive { get; set; } + + /// + public DateTimeOffset CreatedDate { get; set; } + } + + + public interface IDatabaseEntity { /// /// Id of the entity /// - [GenerateId] - public string Id { get; set; } + string Id { get; set; } /// /// Id of the associated application (auto-filled) /// - [MapAppId] - public string AppId { get; set; } + string AppId { get; set; } /// /// Full name of the entity /// - public string Name { get; set; } + string Name { get; set; } /// /// Sort order /// - public uint Sort { get; set; } + uint Sort { get; set; } /// /// Whether the entity is visible in the frontend /// - public bool IsPublished { get; set; } + bool IsActive { get; set; } /// /// Date of creation /// - public DateTimeOffset CreatedDate { get; set; } + DateTimeOffset CreatedDate { get; set; } } } diff --git a/unjo.Core/unjo.Core.csproj b/unjo.Core/unjo.Core.csproj index b2e7d1e7..a32b3b1a 100644 --- a/unjo.Core/unjo.Core.csproj +++ b/unjo.Core/unjo.Core.csproj @@ -10,4 +10,4 @@ - + \ No newline at end of file