mirror of
https://github.com/hmaxnl/DotBased.git
synced 2025-01-18 10:04:20 +01:00
[CHANGE] Implementation updates
This commit is contained in:
parent
efc8259930
commit
12efc92ac4
|
@ -64,6 +64,34 @@ public class AuthorityUserManager<TUser> where TUser : class
|
|||
return errors.Count > 0 ? ValidationResult.Failed(errors) : ValidationResult.Ok();
|
||||
}
|
||||
|
||||
public async Task<ListResult<TUser>> SearchUsersAsync(string query, int maxResults = 20, int offset = 0)
|
||||
{
|
||||
var searchResult = await UserRepository.GetUsersAsync(query, maxResults, offset);
|
||||
return searchResult.Item1 == null ? ListResult<TUser>.Failed("No results!") : ListResult<TUser>.Ok(searchResult.Item1, searchResult.Item2);
|
||||
}
|
||||
|
||||
public async Task<AuthorityResult<TUser>> UpdatePasswordAsync(TUser user, string password)
|
||||
{
|
||||
if (user is not AuthorityUserBase userBase)
|
||||
{
|
||||
return AuthorityResult<TUser>.Error($"Given user is not of base type {nameof(AuthorityUserBase)}!");
|
||||
}
|
||||
|
||||
var passwordValidation = await ValidatePasswordAsync(user, password);
|
||||
if (!passwordValidation.Success)
|
||||
{
|
||||
List<ValidationError> errors = [];
|
||||
errors.AddRange(passwordValidation.Errors);
|
||||
return AuthorityResult<TUser>.Failed(errors, ResultFailReason.Validation);
|
||||
}
|
||||
|
||||
userBase.PasswordHash = await PasswordHasher.HashPasswordAsync(password);
|
||||
userBase.SecurityVersion = AuthorityManager.GenerateVersion();
|
||||
|
||||
var updateResult = await UserRepository.UpdateUserAsync(user);
|
||||
return updateResult == null ? AuthorityResult<TUser>.Error("Failed to save updates!") : AuthorityResult<TUser>.Ok(updateResult);
|
||||
}
|
||||
|
||||
public async Task<AuthorityResult<TUser>> CreateUserAsync(TUser userModel, string password)
|
||||
{
|
||||
if (userModel is not AuthorityUserBase userBase)
|
||||
|
@ -81,10 +109,8 @@ public class AuthorityUserManager<TUser> where TUser : class
|
|||
return AuthorityResult<TUser>.Failed(errors, ResultFailReason.Validation);
|
||||
}
|
||||
|
||||
var version = AuthorityManager.GenerateVersion();
|
||||
userBase.Version = version;
|
||||
var securityVersion = AuthorityManager.GenerateVersion();
|
||||
userBase.SecurityVersion = securityVersion;
|
||||
userBase.Version = AuthorityManager.GenerateVersion();
|
||||
userBase.SecurityVersion = AuthorityManager.GenerateVersion();
|
||||
var hashedPassword = await PasswordHasher.HashPasswordAsync(password);
|
||||
userBase.PasswordHash = hashedPassword;
|
||||
|
||||
|
@ -94,4 +120,18 @@ public class AuthorityUserManager<TUser> where TUser : class
|
|||
? AuthorityResult<TUser>.Ok(userCreationResult)
|
||||
: AuthorityResult<TUser>.Error("Failed to create user in repository!");
|
||||
}
|
||||
|
||||
public async Task<Result<TUser>> UpdateUserAsync(TUser model)
|
||||
{
|
||||
var updateResult = await UserRepository.UpdateUserAsync(model);
|
||||
return updateResult != null ? Result<TUser>.Ok(updateResult) : Result<TUser>.Failed("Failed to update user in repository!");
|
||||
}
|
||||
|
||||
public async Task<bool> DeleteUserAsync(TUser model)
|
||||
{
|
||||
var deleteResult = await UserRepository.DeleteUserAsync(model);
|
||||
return deleteResult;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -2,14 +2,15 @@ namespace DotBased.AspNet.Authority.Repositories;
|
|||
|
||||
public interface IUserRepository<TUser> where TUser : class
|
||||
{
|
||||
public Task<TUser?> GetUserByIdAsync(string id);
|
||||
public Task<string> GetUserIdAsync(TUser user);
|
||||
public Task<TUser?> GetUserByEmailAsync(string email);
|
||||
public Task SetVersionAsync(TUser user, long version);
|
||||
public Task<long> GetVersionAsync(TUser user);
|
||||
public Task SetSecurityVersionAsync(TUser user, long version);
|
||||
public Task<long> GetSecurityVersionAsync(TUser user);
|
||||
public Task<TUser?> CreateUserAsync(TUser user);
|
||||
public Task<TUser?> UpdateUserAsync(TUser user);
|
||||
public Task<bool> DeleteUserAsync(TUser user);
|
||||
public Task<TUser?> GetUserByIdAsync(string id, CancellationToken? cancellationToken = null);
|
||||
public Task<string> GetUserIdAsync(TUser user, CancellationToken? cancellationToken = null);
|
||||
public Task<Tuple<List<TUser>?, int>> GetUsersAsync(string query, int maxResults = 20, int offset = 0, CancellationToken? cancellationToken = null);
|
||||
public Task<TUser?> GetUserByEmailAsync(string email, CancellationToken? cancellationToken = null);
|
||||
public Task SetVersionAsync(TUser user, long version, CancellationToken? cancellationToken = null);
|
||||
public Task<long> GetVersionAsync(TUser user, CancellationToken? cancellationToken = null);
|
||||
public Task SetSecurityVersionAsync(TUser user, long version, CancellationToken? cancellationToken = null);
|
||||
public Task<long> GetSecurityVersionAsync(TUser user, CancellationToken? cancellationToken = null);
|
||||
public Task<TUser?> CreateUserAsync(TUser user, CancellationToken? cancellationToken = null);
|
||||
public Task<TUser?> UpdateUserAsync(TUser user, CancellationToken? cancellationToken = null);
|
||||
public Task<bool> DeleteUserAsync(TUser user, CancellationToken? cancellationToken = null);
|
||||
}
|
Loading…
Reference in New Issue
Block a user