mirror of
https://github.com/hmaxnl/DotBased.git
synced 2025-01-18 10:04:20 +01:00
[ADD] Adding models, repositories. Implementing business logic.
This commit is contained in:
parent
7ebe1e1752
commit
44e64793b7
|
@ -1,7 +1,7 @@
|
|||
namespace DotBased.AspNet.Authority.Attributes;
|
||||
|
||||
/// <summary>
|
||||
/// Indicates that the property should be protected.
|
||||
/// Indicates to protect the property before saving to the repository.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
public class ProtectAttribute : Attribute
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
<ItemGroup>
|
||||
<Folder Include="Authentication\" />
|
||||
<Folder Include="Models\Security\" />
|
||||
<Folder Include="Repositories\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
namespace DotBased.AspNet.Authority.Interfaces;
|
||||
|
||||
public interface ISecurityVersionRepository<in TRepositoryObject>
|
||||
{
|
||||
public Task<long> GetSecurityVersionAsync(TRepositoryObject obj);
|
||||
|
||||
}
|
|
@ -1,6 +1,8 @@
|
|||
namespace DotBased.AspNet.Authority.Interfaces;
|
||||
|
||||
public interface IUserRepository
|
||||
public interface IUserRepository<TUser, TId> : IVersionRepository<TUser>, ISecurityVersionRepository<TUser> where TUser : class where TId : IEquatable<TId>
|
||||
{
|
||||
public Task<TUser?> GetUserByIdAsync(TId id);
|
||||
|
||||
public Task<TId> GetUserIdAsync(TUser user);
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
namespace DotBased.AspNet.Authority.Interfaces;
|
||||
|
||||
public interface IVersionRepository<in TRepositoryObject>
|
||||
{
|
||||
public Task<long> GetVersionAsync(TRepositoryObject obj);
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
namespace DotBased.AspNet.Authority.Models.Authority;
|
||||
|
||||
public class AuthorityAttribute
|
||||
{
|
||||
public AuthorityAttribute(string attributeKey, string bound) : this()
|
||||
{
|
||||
AttributeKey = attributeKey;
|
||||
BoundId = bound;
|
||||
}
|
||||
|
||||
public AuthorityAttribute()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public string AttributeKey { get; set; } // ClaimType/Authority.attribute.enabled
|
||||
|
||||
public string BoundId { get; set; } // Bound to User, Group, Role id
|
||||
|
||||
public string? AttributeValue { get; set; }
|
||||
|
||||
public string? Type { get; set; } // AspNet.Claim.Role/Property/Data.JSON, Data.Raw, Data.Base64 etc.
|
||||
|
||||
public long Version { get; set; }
|
||||
}
|
26
DotBased.AspNet.Authority/Models/Authority/AuthorityGroup.cs
Normal file
26
DotBased.AspNet.Authority/Models/Authority/AuthorityGroup.cs
Normal file
|
@ -0,0 +1,26 @@
|
|||
namespace DotBased.AspNet.Authority.Models.Authority;
|
||||
|
||||
public class AuthorityGroup : AuthorityGroup<Guid>
|
||||
{
|
||||
public AuthorityGroup(string name) : this()
|
||||
{
|
||||
Name = name;
|
||||
}
|
||||
|
||||
public AuthorityGroup()
|
||||
{
|
||||
Id = Guid.NewGuid();
|
||||
CreatedDate = DateTime.Now;
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class AuthorityGroup<TKey> where TKey : IEquatable<TKey>
|
||||
{
|
||||
public TKey Id { get; set; }
|
||||
|
||||
public string? Name { get; set; }
|
||||
|
||||
public long Version { get; set; }
|
||||
|
||||
public DateTime CreatedDate { get; set; }
|
||||
}
|
28
DotBased.AspNet.Authority/Models/Authority/AuthorityRole.cs
Normal file
28
DotBased.AspNet.Authority/Models/Authority/AuthorityRole.cs
Normal file
|
@ -0,0 +1,28 @@
|
|||
namespace DotBased.AspNet.Authority.Models.Authority;
|
||||
|
||||
public class AuthorityRole : AuthorityRole<Guid>
|
||||
{
|
||||
public AuthorityRole(string name) : this()
|
||||
{
|
||||
Name = name;
|
||||
}
|
||||
|
||||
public AuthorityRole()
|
||||
{
|
||||
Id = Guid.NewGuid();
|
||||
CreatedDate = DateTime.Now;
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class AuthorityRole<TKey> where TKey : IEquatable<TKey>
|
||||
{
|
||||
public TKey Id { get; set; }
|
||||
|
||||
public string? Name { get; set; }
|
||||
|
||||
public long Version { get; set; }
|
||||
|
||||
public DateTime CreatedDate { get; set; }
|
||||
|
||||
public override string ToString() => Name ?? string.Empty;
|
||||
}
|
|
@ -1,10 +1,52 @@
|
|||
using DotBased.AspNet.Authority.Attributes;
|
||||
|
||||
namespace DotBased.AspNet.Authority.Models.Authority;
|
||||
|
||||
public class AuthorityUser : AuthorityUserBase<Guid>
|
||||
public class AuthorityUser : AuthorityUser<Guid>
|
||||
{
|
||||
public AuthorityUser(string userName) : this()
|
||||
{
|
||||
UserName = userName;
|
||||
}
|
||||
|
||||
public AuthorityUser()
|
||||
{
|
||||
Id = Guid.NewGuid();
|
||||
CreatedDate = DateTime.Now;
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class AuthorityUser<TKey> where TKey : IEquatable<TKey>
|
||||
{
|
||||
public TKey Id { get; set; }
|
||||
|
||||
public bool Enabled { get; set; }
|
||||
|
||||
public bool Locked { get; set; }
|
||||
|
||||
public DateTime LockedDate { get; set; }
|
||||
|
||||
public string? UserName { get; set; }
|
||||
|
||||
public string? PasswordHash { get; set; }
|
||||
|
||||
public DateTime CreatedDate { get; set; }
|
||||
|
||||
public bool TwoFactorEnabled { get; set; }
|
||||
|
||||
public long Version { get; set; }
|
||||
|
||||
public long SecurityVersion { get; set; }
|
||||
|
||||
[Protect]
|
||||
public string? EmailAddress { get; set; }
|
||||
|
||||
public bool EmailConfirmed { get; set; }
|
||||
|
||||
[Protect]
|
||||
public string? PhoneNumber { get; set; }
|
||||
|
||||
public bool PhoneNumberConfirmed { get; set; }
|
||||
|
||||
public override string ToString() => UserName ?? EmailAddress ?? string.Empty;
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
using DotBased.AspNet.Authority.Attributes;
|
||||
|
||||
namespace DotBased.AspNet.Authority.Models.Authority;
|
||||
|
||||
public abstract class AuthorityUserBase<TKey> where TKey : IEquatable<TKey>
|
||||
{
|
||||
public TKey Id { get; set; }
|
||||
|
||||
public bool Enabled { get; set; }
|
||||
|
||||
public bool Locked { get; set; }
|
||||
|
||||
public string UserName { get; set; }
|
||||
|
||||
public string PasswordHash { get; set; }
|
||||
|
||||
public DateTime CreatedDate { get; set; }
|
||||
|
||||
public bool TwoFactorEnabled { get; set; }
|
||||
|
||||
public string ConcurrencyStamp { get; set; }
|
||||
public string SecurityStamp { get; set; }
|
||||
|
||||
|
||||
[Protect]
|
||||
public string EmailAddress { get; set; }
|
||||
|
||||
public bool EmailConfirmed { get; set; }
|
||||
|
||||
[Protect]
|
||||
public string PhoneNumber { get; set; }
|
||||
|
||||
public bool PhoneNumberConfirmed { get; set; }
|
||||
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
namespace DotBased.AspNet.Authority.Repositories;
|
||||
|
||||
public class AuthorityRepository // Inherit the repository interfaces?
|
||||
{
|
||||
|
||||
}
|
|
@ -2,5 +2,5 @@ namespace DotBased.AspNet.Authority.Services;
|
|||
|
||||
public class AuthorityService
|
||||
{
|
||||
|
||||
public long GenerateVersion() => DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
||||
}
|
Loading…
Reference in New Issue
Block a user