mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-10-14 17:54:42 +00:00
66 lines
2.0 KiB
C#
66 lines
2.0 KiB
C#
using Features.Emails.Templates.Rendering;
|
|
using Infrastructure.Configuration;
|
|
using Infrastructure.Email;
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
namespace Features.Emails.Services;
|
|
|
|
/// <summary>
|
|
/// Default implementation of <see cref="IEmailDispatcher" />.
|
|
/// </summary>
|
|
public class EmailDispatcher(
|
|
IEmailProvider emailProvider,
|
|
IEmailTemplateProvider emailTemplateProvider,
|
|
IConfiguration configuration
|
|
) : IEmailDispatcher
|
|
{
|
|
/// <summary>
|
|
/// The base URL of the website, used to build confirmation links. Read from the
|
|
/// <c>WEBSITE_BASE_URL</c> configuration value.
|
|
/// </summary>
|
|
/// <exception cref="InvalidOperationException">
|
|
/// Thrown when the <c>WEBSITE_BASE_URL</c> configuration value is not set.
|
|
/// </exception>
|
|
private string WebsiteBaseUrl =>
|
|
ConfigurationHelpers.GetKeyOrThrow(configuration, ConfigurationKeys.WebsiteBaseUrl);
|
|
|
|
/// <inheritdoc />
|
|
public async Task SendRegistrationEmailAsync(
|
|
string firstName,
|
|
string email,
|
|
string confirmationToken
|
|
)
|
|
{
|
|
string confirmationLink = $"{WebsiteBaseUrl}/users/confirm?token={confirmationToken}";
|
|
|
|
string emailHtml = await emailTemplateProvider.RenderUserRegisteredEmailAsync(
|
|
firstName,
|
|
confirmationLink
|
|
);
|
|
|
|
await emailProvider.SendAsync(email, "Welcome to The Biergarten App!", emailHtml);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public async Task SendResendConfirmationEmailAsync(
|
|
string firstName,
|
|
string email,
|
|
string confirmationToken
|
|
)
|
|
{
|
|
string confirmationLink = $"{WebsiteBaseUrl}/users/confirm?token={confirmationToken}";
|
|
|
|
string emailHtml = await emailTemplateProvider.RenderResendConfirmationEmailAsync(
|
|
firstName,
|
|
confirmationLink
|
|
);
|
|
|
|
await emailProvider.SendAsync(
|
|
email,
|
|
"Confirm Your Email - The Biergarten App",
|
|
emailHtml,
|
|
true
|
|
);
|
|
}
|
|
}
|