-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- do not remember a user's 2fa options - use gov notify to send the emails - add notify options to configuration
- Loading branch information
1 parent
8d51aa6
commit 599ee30
Showing
10 changed files
with
78 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace Cfo.Cats.Application.Common.Interfaces; | ||
|
||
public interface ICommunicationsService | ||
{ | ||
Task SendSmsCodeAsync(string mobileNumber, string code); | ||
Task SendEmailCodeAsync(string email, string code); | ||
} |
This file was deleted.
Oops, something went wrong.
28 changes: 6 additions & 22 deletions
28
...ation/Features/Identity/Notifications/SendFactorCode/SendFactorCodeNotificationHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,13 @@ | ||
namespace Cfo.Cats.Application.Features.Identity.Notifications.SendFactorCode; | ||
|
||
public class SendFactorCodeNotificationHandler : INotificationHandler<SendFactorCodeNotification> | ||
public class SendFactorCodeNotificationHandler( | ||
ILogger<SendFactorCodeNotificationHandler> logger, | ||
ICommunicationsService communicationsService | ||
) : INotificationHandler<SendFactorCodeNotification> | ||
{ | ||
private readonly IStringLocalizer<SendFactorCodeNotificationHandler> localizer; | ||
private readonly ILogger<SendFactorCodeNotificationHandler> logger; | ||
private readonly IMailService mailService; | ||
|
||
public SendFactorCodeNotificationHandler( | ||
IStringLocalizer<SendFactorCodeNotificationHandler> localizer, | ||
ILogger<SendFactorCodeNotificationHandler> logger, | ||
IMailService mailService | ||
) | ||
{ | ||
this.localizer = localizer; | ||
this.logger = logger; | ||
this.mailService = mailService; | ||
} | ||
|
||
public async Task Handle( | ||
SendFactorCodeNotification notification, | ||
CancellationToken cancellationToken | ||
) | ||
public async Task Handle(SendFactorCodeNotification notification, CancellationToken cancellationToken) | ||
{ | ||
var subject = localizer["Your Verification Code"]; | ||
await mailService.SendAsync(notification.Email, subject, notification.AuthenticatorCode); | ||
await communicationsService.SendEmailCodeAsync(notification.Email, notification.AuthenticatorCode); | ||
logger.LogInformation("Verification Code email sent to {Email})", notification.Email); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using Notify.Client; | ||
|
||
namespace Cfo.Cats.Infrastructure.Services; | ||
|
||
public class CommunicationsService(IOptions<NotifyOptions> options, ILogger<CommunicationsService> logger) : ICommunicationsService | ||
{ | ||
public Task SendSmsCodeAsync(string mobileNumber, string code) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
public async Task SendEmailCodeAsync(string email, string code) | ||
{ | ||
try | ||
{ | ||
var client = Client(); | ||
var response = await client.SendEmailAsync(emailAddress: email, | ||
templateId: options.Value.EmailTemplate, | ||
personalisation: new Dictionary<string, dynamic>() { | ||
{ | ||
"subject", | ||
"Your two factor authentication code." | ||
}, | ||
{ | ||
"body", $"Your two factor authentication code is {code}" | ||
} | ||
}); | ||
} | ||
catch (Exception e) | ||
{ | ||
logger.LogError("Failed to send Email code. {e}", e); | ||
} | ||
} | ||
|
||
private NotificationClient Client() => new(options.Value.ApiKey); | ||
} | ||
|
||
public class NotifyOptions | ||
{ | ||
|
||
public const string Notify = "Notify"; | ||
public string ApiKey { get; set; } | ||
public string SmsTemplate { get; set; } | ||
|
||
public string EmailTemplate { get; set; } | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters