| | | 1 | | using ArturRios.Heimdall.Command.Services; |
| | | 2 | | using ArturRios.Messaging.Email; |
| | | 3 | | |
| | | 4 | | namespace ArturRios.Heimdall.WebApi.Email; |
| | | 5 | | |
| | | 6 | | /// <summary> |
| | | 7 | | /// Delivers UC-47's registration link through Mailgun. It tells the registrant that the link alone |
| | | 8 | | /// finishes nothing: the password chosen at sign-up must accompany it. A failure is logged by |
| | | 9 | | /// <see cref="MailgunSender" /> and never propagated. |
| | | 10 | | /// </summary> |
| | | 11 | | public class MailgunRegistrationLinkSender( |
| | | 12 | | IEmailService emailService, |
| | | 13 | | EmailDeliveryOptions options, |
| | | 14 | | ILogger<MailgunRegistrationLinkSender> logger) |
| | 4 | 15 | | : MailgunSender(emailService, logger), IRegistrationLinkSender |
| | | 16 | | { |
| | | 17 | | private const string Subject = "Finish creating your account"; |
| | | 18 | | |
| | 4 | 19 | | protected override string Purpose => "registration link"; |
| | | 20 | | |
| | | 21 | | public Task SendAsync(string email, string token, string? linkBase) |
| | | 22 | | { |
| | | 23 | | // The scope's own link wins; without one the deployment-wide setting applies. |
| | 4 | 24 | | var link = EmailDeliveryOptions.BuildLink( |
| | 4 | 25 | | string.IsNullOrWhiteSpace(linkBase) ? options.VerificationUrl : linkBase, token); |
| | | 26 | | |
| | 4 | 27 | | var body = string.IsNullOrEmpty(link) |
| | 4 | 28 | | ? $""" |
| | 4 | 29 | | Someone asked to create an account with this address. |
| | 4 | 30 | | |
| | 4 | 31 | | Use this token, with the password you chose when you signed up: {token} |
| | 4 | 32 | | |
| | 4 | 33 | | If you did not ask for this, ignore this email. No account is created unless the link is used with that p |
| | 4 | 34 | | """ |
| | 4 | 35 | | : $""" |
| | 4 | 36 | | Someone asked to create an account with this address. |
| | 4 | 37 | | |
| | 4 | 38 | | To finish, open this link and enter the password you chose when you signed up: {link} |
| | 4 | 39 | | |
| | 4 | 40 | | If you did not ask for this, ignore this email. No account is created unless the link is used with that p |
| | 4 | 41 | | """; |
| | | 42 | | |
| | 4 | 43 | | return DeliverAsync(email, Subject, body); |
| | | 44 | | } |
| | | 45 | | } |