forked from VirtoCommerce/vc-platform
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added two factor token providers which send tokens using INotificatio…
…nManager
- Loading branch information
1 parent
05bb62d
commit bd24c66
Showing
6 changed files
with
97 additions
and
41 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
VirtoCommerce.Platform.Data.Security/Identity/ApplicationEmailTokenProvider.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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNet.Identity; | ||
using VirtoCommerce.Platform.Core.Notifications; | ||
using VirtoCommerce.Platform.Data.Notifications; | ||
|
||
namespace VirtoCommerce.Platform.Data.Security.Identity | ||
{ | ||
public class ApplicationEmailTokenProvider : EmailTokenProvider<ApplicationUser> | ||
{ | ||
private readonly INotificationManager _notificationManager; | ||
|
||
public ApplicationEmailTokenProvider(INotificationManager notificationManager) | ||
{ | ||
_notificationManager = notificationManager; | ||
} | ||
|
||
public override async Task NotifyAsync(string token, UserManager<ApplicationUser, string> manager, ApplicationUser user) | ||
{ | ||
if (manager == null) | ||
throw new ArgumentNullException(nameof(manager)); | ||
|
||
var notification = _notificationManager.GetNewNotification<TwoFactorSmsNotification>(); | ||
|
||
notification.Recipient = await manager.GetPhoneNumberAsync(user.Id); | ||
notification.Token = token; | ||
|
||
_notificationManager.SendNotification(notification); | ||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
VirtoCommerce.Platform.Data.Security/Identity/ApplicationPhoneNumberTokenProvider.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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNet.Identity; | ||
using VirtoCommerce.Platform.Core.Notifications; | ||
using VirtoCommerce.Platform.Data.Notifications; | ||
|
||
namespace VirtoCommerce.Platform.Data.Security.Identity | ||
{ | ||
public class ApplicationPhoneNumberTokenProvider : PhoneNumberTokenProvider<ApplicationUser> | ||
{ | ||
private readonly INotificationManager _notificationManager; | ||
|
||
public ApplicationPhoneNumberTokenProvider(INotificationManager notificationManager) | ||
{ | ||
_notificationManager = notificationManager; | ||
} | ||
|
||
public override async Task NotifyAsync(string token, UserManager<ApplicationUser, string> manager, ApplicationUser user) | ||
{ | ||
if (manager == null) | ||
throw new ArgumentNullException(nameof(manager)); | ||
|
||
var notification = _notificationManager.GetNewNotification<TwoFactorEmailNotification>(); | ||
|
||
notification.Recipient = await manager.GetEmailAsync(user.Id); | ||
notification.Token = token; | ||
|
||
_notificationManager.SendNotification(notification); | ||
} | ||
} | ||
} |
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
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