Merge Features.Auth and Features.UserManagement into Features.Users

This commit is contained in:
Aaron Po
2026-08-30 04:12:21 -04:00
parent ade2128a73
commit bd78fe6533
78 changed files with 137 additions and 325 deletions

View File

@@ -0,0 +1,6 @@
using MediatR;
namespace Features.Auth.Commands.ResendConfirmationEmail;
/// <summary>Resends the account confirmation email to a user, generating a fresh confirmation token.</summary>
public record ResendConfirmationEmailCommand(Guid UserId) : IRequest;

View File

@@ -0,0 +1,41 @@
using Features.Auth.Identity;
using Features.Auth.Services;
using MediatR;
using Microsoft.AspNetCore.Identity;
using Shared.Application.Emails;
namespace Features.Auth.Commands.ResendConfirmationEmail;
/// <summary>
/// Handles <see cref="ResendConfirmationEmailCommand" /> by generating a fresh confirmation token and
/// sending it via Features.Emails.
/// </summary>
/// <remarks>
/// Returns silently without sending an email if the user does not exist (to prevent user enumeration)
/// or if the user's account is already verified.
/// </remarks>
public class ResendConfirmationEmailHandler(
UserManager<ApplicationUser> userManager,
ITokenService tokenService,
IMediator mediator
) : IRequestHandler<ResendConfirmationEmailCommand>
{
public async Task Handle(
ResendConfirmationEmailCommand request,
CancellationToken cancellationToken
)
{
ApplicationUser? user = await userManager.FindByIdAsync(request.UserId.ToString());
if (user == null)
return; // Silent return to prevent user enumeration
if (await userManager.IsEmailConfirmedAsync(user))
return; // Already confirmed, no-op
string confirmationToken = tokenService.GenerateConfirmationToken(user.Id, user.UserName);
await mediator.Send(
new SendResendConfirmationEmailCommand(user.FirstName, user.Email, confirmationToken),
cancellationToken
);
}
}