Add GetCreatorByAlias and CreatorAlias to User

This commit is contained in:
Jonathan Bourdon
2024-07-02 03:11:06 -04:00
parent bc2dc969ff
commit eb2136083b
13 changed files with 737 additions and 20 deletions

View File

@@ -16,7 +16,7 @@ using Microsoft.Extensions.Configuration;
namespace Hutopy.Infrastructure.Identity;
public class IdentityService(
UserManager<ApplicationUser> userManager,
ApplicationUserManager userManager,
SignInManager<ApplicationUser> signInManager,
IUserClaimsPrincipalFactory<ApplicationUser> userClaimsPrincipalFactory,
IAuthorizationService authorizationService,
@@ -135,10 +135,28 @@ public class IdentityService(
public async Task<UserModel?> FindUserByIdAsync(string id)
{
var response = await userManager.FindByIdAsync(id);
var user = await userManager.FindByIdAsync(id);
if (response == null) return null;
if (user == null) return null;
var userModel = BuildModelFrom(user);
return userModel;
}
public async Task<UserModel?> FindUserByCreatorAliasAsync(string creatorAlias, CancellationToken cancellationToken = default)
{
var user = await userManager.FindByCreatorAliasAsync(creatorAlias, cancellationToken);
if (user == null) return null;
var userModel = BuildModelFrom(user);
return userModel;
}
private static UserModel BuildModelFrom(ApplicationUser response)
{
var userModel = new UserModel
{
Id = response.Id,
@@ -179,10 +197,9 @@ public class IdentityService(
WebsiteIconUrl = response.StoredDataUrls.WebsiteIconUrl,
}
};
return userModel;
}
public async Task<UserModel?> FindUserByEmailAsync(string email)
{
var response = await userManager.FindByEmailAsync(email);