| | | 1 | | using ArturRios.Heimdall.Command.Services; |
| | | 2 | | using ArturRios.Messaging.Email; |
| | | 3 | | |
| | | 4 | | namespace ArturRios.Heimdall.WebApi.Email; |
| | | 5 | | |
| | | 6 | | /// <summary> |
| | | 7 | | /// Delivers UC-12's password reset token as a real email through Mailgun (FR-PR-02). Registered |
| | | 8 | | /// in place of <see cref="LoggingPasswordResetSender" /> whenever Mailgun is configured. |
| | | 9 | | /// </summary> |
| | | 10 | | public class MailgunPasswordResetSender( |
| | | 11 | | IEmailService emailService, |
| | | 12 | | EmailDeliveryOptions options, |
| | | 13 | | ILogger<MailgunPasswordResetSender> logger) |
| | 12 | 14 | | : MailgunSender(emailService, logger), IPasswordResetSender |
| | | 15 | | { |
| | | 16 | | private const string Subject = "Reset your password"; |
| | | 17 | | |
| | 12 | 18 | | protected override string Purpose => "password reset"; |
| | | 19 | | |
| | | 20 | | public Task SendAsync(string email, string token, string? linkBase) |
| | | 21 | | { |
| | | 22 | | // The scope's own link wins; without one the deployment-wide setting applies. |
| | 12 | 23 | | var link = EmailDeliveryOptions.BuildLink( |
| | 12 | 24 | | string.IsNullOrWhiteSpace(linkBase) ? options.PasswordResetUrl : linkBase, token); |
| | | 25 | | |
| | | 26 | | // Without a configured front end there is nowhere to link to, so the token goes in plain. |
| | | 27 | | // It is still usable — UC-13 takes the token, and the link is only a convenience wrapper |
| | | 28 | | // around it. |
| | 12 | 29 | | var body = string.IsNullOrEmpty(link) |
| | 12 | 30 | | ? $""" |
| | 12 | 31 | | Someone asked to reset the password for this address. |
| | 12 | 32 | | |
| | 12 | 33 | | Use this token to set a new password: {token} |
| | 12 | 34 | | |
| | 12 | 35 | | If it wasn't you, ignore this email — nothing has changed. |
| | 12 | 36 | | """ |
| | 12 | 37 | | : $""" |
| | 12 | 38 | | Someone asked to reset the password for this address. |
| | 12 | 39 | | |
| | 12 | 40 | | Set a new password here: {link} |
| | 12 | 41 | | |
| | 12 | 42 | | If it wasn't you, ignore this email — nothing has changed. |
| | 12 | 43 | | """; |
| | | 44 | | |
| | 12 | 45 | | return DeliverAsync(email, Subject, body); |
| | | 46 | | } |
| | | 47 | | } |