-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add two-factor authentication (#13704)
- Loading branch information
1 parent
b5efeb5
commit e295fae
Showing
44 changed files
with
2,947 additions
and
72 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
src/OrchardCore.Modules/OrchardCore.Roles/ViewModels/RoleLoginSettingsViewModel.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,10 @@ | ||
using System; | ||
|
||
namespace OrchardCore.Roles.ViewModels; | ||
|
||
public class RoleLoginSettingsViewModel | ||
{ | ||
public bool EnableTwoFactorAuthenticationForSpecificRoles { get; set; } | ||
|
||
public RoleEntry[] Roles { get; set; } = Array.Empty<RoleEntry>(); | ||
} |
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
50 changes: 50 additions & 0 deletions
50
src/OrchardCore.Modules/OrchardCore.Users/Controllers/AccountBaseController.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,50 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Identity; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using OrchardCore.Users.Models; | ||
using OrchardCore.Workflows.Services; | ||
|
||
namespace OrchardCore.Users.Controllers; | ||
|
||
public class AccountBaseController : Controller | ||
{ | ||
protected readonly UserManager<IUser> _userManager; | ||
|
||
public AccountBaseController(UserManager<IUser> userManager) | ||
{ | ||
_userManager = userManager; | ||
} | ||
|
||
protected async Task<IActionResult> LoggedInActionResult(IUser user, string returnUrl = null, ExternalLoginInfo info = null) | ||
{ | ||
var workflowManager = HttpContext.RequestServices.GetService<IWorkflowManager>(); | ||
if (workflowManager != null && user is User u) | ||
{ | ||
var input = new Dictionary<string, object> | ||
{ | ||
["UserName"] = user.UserName, | ||
["ExternalClaims"] = info?.Principal?.GetSerializableClaims() ?? Enumerable.Empty<SerializableClaim>(), | ||
["Roles"] = u.RoleNames, | ||
["Provider"] = info?.LoginProvider | ||
}; | ||
await workflowManager.TriggerEventAsync(nameof(Workflows.Activities.UserLoggedInEvent), | ||
input: input, correlationId: u.UserId); | ||
} | ||
|
||
return RedirectToLocal(returnUrl); | ||
} | ||
|
||
protected IActionResult RedirectToLocal(string returnUrl) | ||
{ | ||
if (Url.IsLocalUrl(returnUrl)) | ||
{ | ||
return Redirect(returnUrl.ToUriComponents()); | ||
} | ||
|
||
return Redirect("~/"); | ||
} | ||
} |
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
Oops, something went wrong.