From af68bc2110c9adfb7a932fd5215df6dc361996ea Mon Sep 17 00:00:00 2001 From: maliming Date: Fri, 15 Nov 2019 14:30:19 +0800 Subject: [PATCH 1/2] Implement external login only. --- .../Account/IdentityServerSupportedLoginModel.cs | 11 ++++++----- .../Areas/Account/Controllers/LogoutController.cs | 7 ++++++- .../Pages/Account/Login.cshtml.cs | 4 +++- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/modules/account/src/Volo.Abp.Account.Web.IdentityServer/Pages/Account/IdentityServerSupportedLoginModel.cs b/modules/account/src/Volo.Abp.Account.Web.IdentityServer/Pages/Account/IdentityServerSupportedLoginModel.cs index b6902e86d8c..0714d5b3231 100644 --- a/modules/account/src/Volo.Abp.Account.Web.IdentityServer/Pages/Account/IdentityServerSupportedLoginModel.cs +++ b/modules/account/src/Volo.Abp.Account.Web.IdentityServer/Pages/Account/IdentityServerSupportedLoginModel.cs @@ -1,4 +1,4 @@ -using IdentityModel; +using IdentityModel; using IdentityServer4.Events; using IdentityServer4.Models; using IdentityServer4.Services; @@ -40,7 +40,7 @@ public IdentityServerSupportedLoginModel( IdentityServerEvents = identityServerEvents; } - public override async Task OnGetAsync() + public override async Task OnGetAsync() { LoginInput = new LoginInputModel(); @@ -63,7 +63,7 @@ public override async Task OnGetAsync() { LoginInput.UserNameOrEmailAddress = context.LoginHint; ExternalProviders = new[] { new ExternalProviderModel { AuthenticationScheme = context.IdP } }; - return; + return Page(); } var schemes = await _schemeProvider.GetAllSchemesAsync(); @@ -96,9 +96,10 @@ public override async Task OnGetAsync() if (IsExternalLoginOnly) { - //return await ExternalLogin(vm.ExternalLoginScheme, returnUrl); - throw new NotImplementedException(); + return await base.OnPostExternalLogin(providers.First().AuthenticationScheme); } + + return Page(); } [UnitOfWork] //TODO: Will be removed when we implement action filter diff --git a/modules/account/src/Volo.Abp.Account.Web/Areas/Account/Controllers/LogoutController.cs b/modules/account/src/Volo.Abp.Account.Web/Areas/Account/Controllers/LogoutController.cs index 1f1b43b8532..eb7d1cbc844 100644 --- a/modules/account/src/Volo.Abp.Account.Web/Areas/Account/Controllers/LogoutController.cs +++ b/modules/account/src/Volo.Abp.Account.Web/Areas/Account/Controllers/LogoutController.cs @@ -17,10 +17,15 @@ public LogoutController(SignInManager signInManager) } //todo@alper: this method can be moved to AccountController like "account/logout" - public async Task Index() + public async Task Index(string returnUrl = null) { await _signInManager.SignOutAsync(); + if (returnUrl != null) + { + return LocalRedirect(returnUrl); + } + return RedirectToPage("/Account/Login"); } } diff --git a/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Login.cshtml.cs b/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Login.cshtml.cs index cc82de414f2..74691dba331 100644 --- a/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Login.cshtml.cs +++ b/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Login.cshtml.cs @@ -56,7 +56,7 @@ public LoginModel( _accountOptions = accountOptions.Value; } - public virtual async Task OnGetAsync() + public virtual async Task OnGetAsync() { LoginInput = new LoginInputModel(); @@ -80,6 +80,8 @@ public virtual async Task OnGetAsync() //return await ExternalLogin(vm.ExternalLoginScheme, returnUrl); throw new NotImplementedException(); } + + return Page(); } [UnitOfWork] //TODO: Will be removed when we implement action filter From 7e0fd93bebad4976070b5c8fa8e31645f8750e54 Mon Sep 17 00:00:00 2001 From: maliming Date: Fri, 15 Nov 2019 15:04:03 +0800 Subject: [PATCH 2/2] Add Abp.Account.EnableLocalLogin setting. --- .../Pages/Account/IdentityServerSupportedLoginModel.cs | 6 ++++-- .../Volo.Abp.Account.Web/Pages/Account/Login.cshtml.cs | 8 +++++--- .../Settings/AccountSettingDefinitionProvider.cs | 4 ++++ .../Volo.Abp.Account.Web/Settings/AccountSettingNames.cs | 2 ++ 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/modules/account/src/Volo.Abp.Account.Web.IdentityServer/Pages/Account/IdentityServerSupportedLoginModel.cs b/modules/account/src/Volo.Abp.Account.Web.IdentityServer/Pages/Account/IdentityServerSupportedLoginModel.cs index 0714d5b3231..f1abf44750a 100644 --- a/modules/account/src/Volo.Abp.Account.Web.IdentityServer/Pages/Account/IdentityServerSupportedLoginModel.cs +++ b/modules/account/src/Volo.Abp.Account.Web.IdentityServer/Pages/Account/IdentityServerSupportedLoginModel.cs @@ -12,8 +12,10 @@ using System.Security.Claims; using System.Security.Principal; using System.Threading.Tasks; +using Volo.Abp.Account.Web.Settings; using Volo.Abp.DependencyInjection; using Volo.Abp.MultiTenancy; +using Volo.Abp.Settings; using Volo.Abp.Uow; namespace Volo.Abp.Account.Web.Pages.Account @@ -77,7 +79,7 @@ public override async Task OnGetAsync() }) .ToList(); - EnableLocalLogin = true; //TODO: We can get default from a setting? + EnableLocalLogin = await SettingProvider.IsTrueAsync(AccountSettingNames.EnableLocalLogin); if (context?.ClientId != null) { var client = await ClientStore.FindEnabledClientByIdAsync(context.ClientId); @@ -105,7 +107,7 @@ public override async Task OnGetAsync() [UnitOfWork] //TODO: Will be removed when we implement action filter public override async Task OnPostAsync(string action) { - EnableLocalLogin = true; //TODO: We can get default from a setting? + EnableLocalLogin = await SettingProvider.IsTrueAsync(AccountSettingNames.EnableLocalLogin); if (action == "Cancel") { diff --git a/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Login.cshtml.cs b/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Login.cshtml.cs index 74691dba331..e7e625416ac 100644 --- a/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Login.cshtml.cs +++ b/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Login.cshtml.cs @@ -10,8 +10,10 @@ using System.Linq; using System.Security.Claims; using System.Threading.Tasks; +using Volo.Abp.Account.Web.Settings; using Volo.Abp.Identity; using Volo.Abp.Security.Claims; +using Volo.Abp.Settings; using Volo.Abp.Uow; using Volo.Abp.Validation; using IdentityUser = Volo.Abp.Identity.IdentityUser; @@ -71,8 +73,8 @@ public virtual async Task OnGetAsync() }) .ToList(); - EnableLocalLogin = true; //TODO: We can get default from a setting? - + EnableLocalLogin = await SettingProvider.IsTrueAsync(AccountSettingNames.EnableLocalLogin); + ExternalProviders = providers.ToArray(); if (IsExternalLoginOnly) @@ -87,7 +89,7 @@ public virtual async Task OnGetAsync() [UnitOfWork] //TODO: Will be removed when we implement action filter public virtual async Task OnPostAsync(string action) { - EnableLocalLogin = true; //TODO: We can get default from a setting? + EnableLocalLogin = await SettingProvider.IsTrueAsync(AccountSettingNames.EnableLocalLogin); ValidateModel(); diff --git a/modules/account/src/Volo.Abp.Account.Web/Settings/AccountSettingDefinitionProvider.cs b/modules/account/src/Volo.Abp.Account.Web/Settings/AccountSettingDefinitionProvider.cs index 8d3ccba7c9c..be16fa7045b 100644 --- a/modules/account/src/Volo.Abp.Account.Web/Settings/AccountSettingDefinitionProvider.cs +++ b/modules/account/src/Volo.Abp.Account.Web/Settings/AccountSettingDefinitionProvider.cs @@ -9,6 +9,10 @@ public override void Define(ISettingDefinitionContext context) context.Add( new SettingDefinition(AccountSettingNames.IsSelfRegistrationEnabled, "true") ); + + context.Add( + new SettingDefinition(AccountSettingNames.EnableLocalLogin, "true") + ); } } } \ No newline at end of file diff --git a/modules/account/src/Volo.Abp.Account.Web/Settings/AccountSettingNames.cs b/modules/account/src/Volo.Abp.Account.Web/Settings/AccountSettingNames.cs index 3122dbdc6a3..a167be0ce80 100644 --- a/modules/account/src/Volo.Abp.Account.Web/Settings/AccountSettingNames.cs +++ b/modules/account/src/Volo.Abp.Account.Web/Settings/AccountSettingNames.cs @@ -3,5 +3,7 @@ public class AccountSettingNames { public const string IsSelfRegistrationEnabled = "Abp.Account.IsSelfRegistrationEnabled"; + + public const string EnableLocalLogin = "Abp.Account.EnableLocalLogin"; } }