1 changed files with 23 additions and 30 deletions
@ -1,64 +1,57 @@ |
|||||
using Microsoft.AspNetCore.Authentication; |
using Microsoft.AspNetCore.Authentication; |
||||
using Microsoft.AspNetCore.Mvc; |
using Microsoft.AspNetCore.Mvc; |
||||
using Microsoft.Extensions.Options; |
using Microsoft.Extensions.Options; |
||||
using System.Collections.Generic; |
using System; |
||||
using System.Threading.Tasks; |
using System.Threading.Tasks; |
||||
using Volo.Abp.Account.Web; |
using Volo.Abp.Account.Web; |
||||
using Volo.Abp.Account.Web.Pages.Account; |
|
||||
using Volo.Abp.DependencyInjection; |
using Volo.Abp.DependencyInjection; |
||||
using Volo.Abp.Identity; |
using Volo.Abp.Identity; |
||||
|
using Volo.Abp.MultiTenancy; |
||||
using Volo.Abp.OpenIddict; |
using Volo.Abp.OpenIddict; |
||||
using IdentityOptions = Microsoft.AspNetCore.Identity.IdentityOptions; |
using IdentityOptions = Microsoft.AspNetCore.Identity.IdentityOptions; |
||||
|
|
||||
namespace LINGYUN.Abp.Account.Web.OpenIddict.Pages.Account |
namespace LINGYUN.Abp.Account.Web.OpenIddict.Pages.Account |
||||
{ |
{ |
||||
/// <summary>
|
|
||||
/// 重写登录模型,实现双因素登录
|
|
||||
/// </summary>
|
|
||||
[Dependency(ReplaceServices = true)] |
[Dependency(ReplaceServices = true)] |
||||
[ExposeServices(typeof(LoginModel), typeof(OpenIddictSupportedLoginModel))] |
[ExposeServices( |
||||
public class TwoFactorSupportedLoginModel : OpenIddictSupportedLoginModel |
typeof(LINGYUN.Abp.Account.Web.Pages.Account.LoginModel), |
||||
|
typeof(TwoFactorSupportedLoginModel))] |
||||
|
public class TwoFactorSupportedLoginModel : LINGYUN.Abp.Account.Web.Pages.Account.LoginModel |
||||
{ |
{ |
||||
|
protected AbpOpenIddictRequestHelper OpenIddictRequestHelper { get; } |
||||
public TwoFactorSupportedLoginModel( |
public TwoFactorSupportedLoginModel( |
||||
IAuthenticationSchemeProvider schemeProvider, |
IAuthenticationSchemeProvider schemeProvider, |
||||
IOptions<AbpAccountOptions> accountOptions, |
IOptions<AbpAccountOptions> accountOptions, |
||||
IOptions<IdentityOptions> identityOptions, |
IOptions<IdentityOptions> identityOptions, |
||||
IdentityDynamicClaimsPrincipalContributorCache identityDynamicClaimsPrincipalContributorCache, |
IdentityDynamicClaimsPrincipalContributorCache identityDynamicClaimsPrincipalContributorCache, |
||||
AbpOpenIddictRequestHelper openIddictRequestHelper) |
AbpOpenIddictRequestHelper openIddictRequestHelper) |
||||
: base(schemeProvider, accountOptions, identityOptions, identityDynamicClaimsPrincipalContributorCache, openIddictRequestHelper) |
: base(schemeProvider, accountOptions, identityOptions, identityDynamicClaimsPrincipalContributorCache) |
||||
{ |
{ |
||||
|
OpenIddictRequestHelper = openIddictRequestHelper; |
||||
} |
} |
||||
|
|
||||
protected async override Task<List<ExternalProviderModel>> GetExternalProviders() |
public async override Task<IActionResult> OnGetAsync() |
||||
{ |
{ |
||||
var providers = await base.GetExternalProviders(); |
LoginInput = new LoginInputModel(); |
||||
|
|
||||
foreach (var provider in providers) |
var request = await OpenIddictRequestHelper.GetFromReturnUrlAsync(ReturnUrl); |
||||
|
if (request?.ClientId != null) |
||||
{ |
{ |
||||
var localizedDisplayName = L[provider.DisplayName]; |
// TODO: Find a proper cancel way.
|
||||
if (localizedDisplayName.ResourceNotFound) |
// ShowCancelButton = true;
|
||||
{ |
|
||||
localizedDisplayName = L["AuthenticationScheme:" + provider.DisplayName]; |
|
||||
} |
|
||||
|
|
||||
if (!localizedDisplayName.ResourceNotFound) |
LoginInput.UserNameOrEmailAddress = request.LoginHint; |
||||
|
|
||||
|
//TODO: Reference AspNetCore MultiTenancy module and use options to get the tenant key!
|
||||
|
var tenant = request.GetParameter(TenantResolverConsts.DefaultTenantKey)?.ToString(); |
||||
|
if (!string.IsNullOrEmpty(tenant)) |
||||
{ |
{ |
||||
provider.DisplayName = localizedDisplayName.Value; |
CurrentTenant.Change(Guid.Parse(tenant)); |
||||
|
Response.Cookies.Append(TenantResolverConsts.DefaultTenantKey, tenant); |
||||
} |
} |
||||
} |
} |
||||
|
|
||||
return providers; |
return await base.OnGetAsync(); |
||||
} |
|
||||
|
|
||||
protected override Task<IActionResult> TwoFactorLoginResultAsync() |
|
||||
{ |
|
||||
// 重定向双因素认证页面
|
|
||||
return Task.FromResult<IActionResult>(RedirectToPage("SendCode", new |
|
||||
{ |
|
||||
returnUrl = ReturnUrl, |
|
||||
returnUrlHash = ReturnUrlHash, |
|
||||
rememberMe = LoginInput.RememberMe |
|
||||
})); |
|
||||
} |
} |
||||
} |
} |
||||
} |
} |
||||
|
|||||
Loading…
Reference in new issue