Merged PR 74: added findByUserNameAsync to the interface and service

added findByUserNameAsync to the interface and service
This commit is contained in:
Dominic Villemure
2024-06-06 22:05:07 +00:00
2 changed files with 19 additions and 0 deletions

View File

@@ -9,6 +9,7 @@ public interface IIdentityService
Task<UserModel?> FindUserByIdAsync(string id);
Task<UserModel?> GetCurrentUserAsync();
Task<UserModel?> FindUserByEmailAsync(string id);
Task<UserModel?> GetUserByUserNameAsync(string userName);
Task<bool> IsInRoleAsync(string userId, string role);
Task<bool> AuthorizeAsync(string userId, string policyName);
Task<Result> AddRoleAsync(string userId, string role);

View File

@@ -21,6 +21,24 @@ public class IdentityService(
return user?.UserName;
}
public async Task<UserModel?> GetUserByUserNameAsync(string userName)
{
var response = await userManager.FindByNameAsync(userName);
if (response == null) return null;
var userModel = new UserModel()
{
Id = response.Id,
UserName = response.UserName,
FirstName = response.FirstName,
LastName = response.LastName,
Email = response.Email,
};
return userModel;
}
public async Task<(Result Result, string UserId)> CreateUserAsync(string userName, string password)
{