From 4a5abf59eba7f726e24447bdbb7be7d10ac84ba6 Mon Sep 17 00:00:00 2001 From: Dominic Villemure Date: Thu, 6 Jun 2024 18:04:42 -0400 Subject: [PATCH] added findByUserNameAsync to the interface and service --- .../Common/Interfaces/IIdentityService.cs | 1 + src/Infrastructure/Identity/IdentityService.cs | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/Application/Common/Interfaces/IIdentityService.cs b/src/Application/Common/Interfaces/IIdentityService.cs index b816ad7..0af5c4a 100644 --- a/src/Application/Common/Interfaces/IIdentityService.cs +++ b/src/Application/Common/Interfaces/IIdentityService.cs @@ -9,6 +9,7 @@ public interface IIdentityService Task FindUserByIdAsync(string id); Task GetCurrentUserAsync(); Task FindUserByEmailAsync(string id); + Task GetUserByUserNameAsync(string userName); Task IsInRoleAsync(string userId, string role); Task AuthorizeAsync(string userId, string policyName); Task AddRoleAsync(string userId, string role); diff --git a/src/Infrastructure/Identity/IdentityService.cs b/src/Infrastructure/Identity/IdentityService.cs index 618b647..3326217 100644 --- a/src/Infrastructure/Identity/IdentityService.cs +++ b/src/Infrastructure/Identity/IdentityService.cs @@ -21,6 +21,24 @@ public class IdentityService( return user?.UserName; } + + public async Task 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) {