diff --git a/DotBased.AspNet.Authority/Managers/AuthorityManager.cs b/DotBased.AspNet.Authority/Managers/AuthorityManager.cs index 4b78e03..50548b1 100644 --- a/DotBased.AspNet.Authority/Managers/AuthorityManager.cs +++ b/DotBased.AspNet.Authority/Managers/AuthorityManager.cs @@ -16,6 +16,7 @@ public partial class AuthorityManager IServiceProvider services, ICryptographer cryptographer, IUserRepository userRepository, + IRoleRepository roleRepository, IPasswordHasher passwordHasher) { _logger = LogService.RegisterLogger(); @@ -23,6 +24,7 @@ public partial class AuthorityManager Services = services; Cryptographer = cryptographer; UserRepository = userRepository; + RoleRepository = roleRepository; PasswordHasher = passwordHasher; } @@ -33,6 +35,7 @@ public partial class AuthorityManager public ICryptographer Cryptographer { get; } public IUserRepository UserRepository { get; } + public IRoleRepository RoleRepository { get; } public IPasswordHasher PasswordHasher { get; } diff --git a/DotBased.AspNet.Authority/Managers/AuthorityRoleManager.cs b/DotBased.AspNet.Authority/Managers/AuthorityRoleManager.cs index 22e70cb..3500cb4 100644 --- a/DotBased.AspNet.Authority/Managers/AuthorityRoleManager.cs +++ b/DotBased.AspNet.Authority/Managers/AuthorityRoleManager.cs @@ -1,6 +1,26 @@ +using DotBased.AspNet.Authority.Models.Authority; + namespace DotBased.AspNet.Authority.Managers; public partial class AuthorityManager { - + public async Task> CreateRoleAsync(AuthorityRole role, CancellationToken? cancellationToken = null) + { + return Result.Failed("Not implemented!"); + } + + public async Task DeleteRoleAsync(AuthorityRole role, CancellationToken? cancellationToken = null) + { + return Result.Failed("Not implemented!"); + } + + public async Task> UpdateRoleAsync(AuthorityRole role, CancellationToken? cancellationToken = null) + { + return Result.Failed("Not implemented!"); + } + + public async Task AddUserToRole(AuthorityUser user, AuthorityRole role, CancellationToken? cancellationToken = null) + { + + } } \ No newline at end of file diff --git a/DotBased.AspNet.Authority/Managers/AuthorityUserManager.cs b/DotBased.AspNet.Authority/Managers/AuthorityUserManager.cs index 94feb6f..5b07cfc 100644 --- a/DotBased.AspNet.Authority/Managers/AuthorityUserManager.cs +++ b/DotBased.AspNet.Authority/Managers/AuthorityUserManager.cs @@ -34,13 +34,13 @@ public partial class AuthorityManager return errors.Count > 0 ? ValidationResult.Failed(errors) : ValidationResult.Ok(); } - public async Task> SearchUsersAsync(string query, int maxResults = 20, int offset = 0) + public async Task> SearchUsersAsync(string query, int maxResults = 20, int offset = 0, CancellationToken? cancellationToken = null) { - var searchResult = await UserRepository.GetAuthorityUsersAsync(query, maxResults, offset); + var searchResult = await UserRepository.GetAuthorityUsersAsync(query, maxResults, offset, cancellationToken); return searchResult.Item1 == null ? ListResult.Failed("No results!") : ListResult.Ok(searchResult.Item1, searchResult.Item2); } - public async Task> UpdatePasswordAsync(AuthorityUser user, string password) + public async Task> UpdatePasswordAsync(AuthorityUser user, string password, CancellationToken? cancellationToken = null) { var passwordValidation = await ValidatePasswordAsync(user, password); if (!passwordValidation.Success) @@ -53,11 +53,11 @@ public partial class AuthorityManager user.PasswordHash = await PasswordHasher.HashPasswordAsync(password); user.SecurityVersion = GenerateVersion(); - var updateResult = await UserRepository.UpdateUserAsync(user); + var updateResult = await UserRepository.UpdateUserAsync(user, cancellationToken); return updateResult == null ? AuthorityResult.Error("Failed to save updates!") : AuthorityResult.Ok(updateResult); } - public async Task> CreateUserAsync(AuthorityUser userModel, string password) + public async Task> CreateUserAsync(AuthorityUser userModel, string password, CancellationToken? cancellationToken = null) { var userValidation = await ValidateUserAsync(userModel); var passwordValidation = await ValidatePasswordAsync(userModel, password); @@ -74,22 +74,22 @@ public partial class AuthorityManager var hashedPassword = await PasswordHasher.HashPasswordAsync(password); userModel.PasswordHash = hashedPassword; - var userCreationResult = await UserRepository.CreateUserAsync(userModel); + var userCreationResult = await UserRepository.CreateUserAsync(userModel, cancellationToken); return userCreationResult != null ? AuthorityResult.Ok(userCreationResult) : AuthorityResult.Error("Failed to create user in repository!"); } - public async Task> UpdateUserAsync(AuthorityUser model) + public async Task> UpdateUserAsync(AuthorityUser model, CancellationToken? cancellationToken = null) { - var updateResult = await UserRepository.UpdateUserAsync(model); + var updateResult = await UserRepository.UpdateUserAsync(model, cancellationToken); return updateResult != null ? Result.Ok(updateResult) : Result.Failed("Failed to update user in repository!"); } - public async Task DeleteUserAsync(AuthorityUser model) + public async Task DeleteUserAsync(AuthorityUser model, CancellationToken? cancellationToken = null) { - var deleteResult = await UserRepository.DeleteUserAsync(model); + var deleteResult = await UserRepository.DeleteUserAsync(model, cancellationToken); return deleteResult; } diff --git a/DotBased.AspNet.Authority/Models/Authority/AuthorityRole.cs b/DotBased.AspNet.Authority/Models/Authority/AuthorityRole.cs index 90ccee5..4fc2600 100644 --- a/DotBased.AspNet.Authority/Models/Authority/AuthorityRole.cs +++ b/DotBased.AspNet.Authority/Models/Authority/AuthorityRole.cs @@ -1,22 +1,8 @@ namespace DotBased.AspNet.Authority.Models.Authority; -public class AuthorityRole : AuthorityRole +public abstract class AuthorityRole { - public AuthorityRole(string name) : this() - { - Name = name; - } - - public AuthorityRole() - { - Id = Guid.NewGuid(); - CreatedDate = DateTime.Now; - } -} - -public abstract class AuthorityRole where TKey : IEquatable -{ - public TKey Id { get; set; } + public Guid Id { get; set; } public string? Name { get; set; }