Browse Source

Check EnableLocalLogin in the login method of the account module.

Resolve #2758
pull/2761/head
maliming 7 years ago
parent
commit
6b8a2ad3f6
  1. 1
      modules/account/src/Volo.Abp.Account.Application.Contracts/Volo/Abp/Account/Localization/Resources/en.json
  2. 1
      modules/account/src/Volo.Abp.Account.Application.Contracts/Volo/Abp/Account/Localization/Resources/zh-Hans.json
  3. 1
      modules/account/src/Volo.Abp.Account.Application.Contracts/Volo/Abp/Account/Localization/Resources/zh-Hant.json
  4. 4
      modules/account/src/Volo.Abp.Account.Web.IdentityServer/Pages/Account/IdentityServerSupportedLoginModel.cs
  5. 21
      modules/account/src/Volo.Abp.Account.Web/Areas/Account/Controllers/AccountController.cs
  6. 10
      modules/account/src/Volo.Abp.Account.Web/Pages/Account/Login.cshtml.cs

1
modules/account/src/Volo.Abp.Account.Application.Contracts/Volo/Abp/Account/Localization/Resources/en.json

@ -11,6 +11,7 @@
"InvalidUserNameOrPassword": "Invalid username or password!", "InvalidUserNameOrPassword": "Invalid username or password!",
"LoginIsNotAllowed": "You are not allowed to login! You need to confirm your email/phone number.", "LoginIsNotAllowed": "You are not allowed to login! You need to confirm your email/phone number.",
"SelfRegistrationDisabledMessage": "Self-registration is disabled for this application. Please contact the application administrator to register a new user.", "SelfRegistrationDisabledMessage": "Self-registration is disabled for this application. Please contact the application administrator to register a new user.",
"LocalLoginDisabledMessage": "Local login is disabled for this application.",
"Login": "Login", "Login": "Login",
"Cancel": "Cancel", "Cancel": "Cancel",
"Register": "Register", "Register": "Register",

1
modules/account/src/Volo.Abp.Account.Application.Contracts/Volo/Abp/Account/Localization/Resources/zh-Hans.json

@ -11,6 +11,7 @@
"InvalidUserNameOrPassword": "用户名或密码错误!", "InvalidUserNameOrPassword": "用户名或密码错误!",
"LoginIsNotAllowed": "无法登录!你需要验证邮箱地址/手机号.", "LoginIsNotAllowed": "无法登录!你需要验证邮箱地址/手机号.",
"SelfRegistrationDisabledMessage": "应用程序未开放注册,请联系管理员添加新用户.", "SelfRegistrationDisabledMessage": "应用程序未开放注册,请联系管理员添加新用户.",
"LocalLoginDisabledMessage": "应用程序未开放本地账户登录.",
"Login": "登录", "Login": "登录",
"Cancel": "取消", "Cancel": "取消",
"Register": "注册", "Register": "注册",

1
modules/account/src/Volo.Abp.Account.Application.Contracts/Volo/Abp/Account/Localization/Resources/zh-Hant.json

@ -11,6 +11,7 @@
"InvalidUserNameOrPassword": "使用者名稱或密碼錯誤!", "InvalidUserNameOrPassword": "使用者名稱或密碼錯誤!",
"LoginIsNotAllowed": "無法登入!你需要驗證電子信箱地址/手機號碼.", "LoginIsNotAllowed": "無法登入!你需要驗證電子信箱地址/手機號碼.",
"SelfRegistrationDisabledMessage": "應用程式未開放註冊,請聯絡管理員以加入新使用者.", "SelfRegistrationDisabledMessage": "應用程式未開放註冊,請聯絡管理員以加入新使用者.",
"LocalLoginDisabledMessage": "應用程序未開放本地賬戶登錄.",
"Login": "登入", "Login": "登入",
"Cancel": "取消", "Cancel": "取消",
"Register": "註冊", "Register": "註冊",

4
modules/account/src/Volo.Abp.Account.Web.IdentityServer/Pages/Account/IdentityServerSupportedLoginModel.cs

@ -107,8 +107,6 @@ namespace Volo.Abp.Account.Web.Pages.Account
[UnitOfWork] //TODO: Will be removed when we implement action filter [UnitOfWork] //TODO: Will be removed when we implement action filter
public override async Task<IActionResult> OnPostAsync(string action) public override async Task<IActionResult> OnPostAsync(string action)
{ {
EnableLocalLogin = await SettingProvider.IsTrueAsync(AccountSettingNames.EnableLocalLogin).ConfigureAwait(false);
if (action == "Cancel") if (action == "Cancel")
{ {
var context = await Interaction.GetAuthorizationContextAsync(ReturnUrl).ConfigureAwait(false); var context = await Interaction.GetAuthorizationContextAsync(ReturnUrl).ConfigureAwait(false);
@ -122,6 +120,8 @@ namespace Volo.Abp.Account.Web.Pages.Account
return Redirect(ReturnUrl); return Redirect(ReturnUrl);
} }
await CheckLocalLoginAsync();
ValidateModel(); ValidateModel();
await ReplaceEmailToUsernameOfInputIfNeeds().ConfigureAwait(false); await ReplaceEmailToUsernameOfInputIfNeeds().ConfigureAwait(false);

21
modules/account/src/Volo.Abp.Account.Web/Areas/Account/Controllers/AccountController.cs

@ -1,10 +1,13 @@
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Volo.Abp.Account.Localization;
using Volo.Abp.Account.Settings;
using Volo.Abp.Account.Web.Areas.Account.Controllers.Models; using Volo.Abp.Account.Web.Areas.Account.Controllers.Models;
using Volo.Abp.AspNetCore.Mvc; using Volo.Abp.AspNetCore.Mvc;
using Volo.Abp.Identity; using Volo.Abp.Identity;
using Volo.Abp.Settings;
using Volo.Abp.Validation; using Volo.Abp.Validation;
using SignInResult = Microsoft.AspNetCore.Identity.SignInResult; using SignInResult = Microsoft.AspNetCore.Identity.SignInResult;
using UserLoginInfo = Volo.Abp.Account.Web.Areas.Account.Controllers.Models.UserLoginInfo; using UserLoginInfo = Volo.Abp.Account.Web.Areas.Account.Controllers.Models.UserLoginInfo;
@ -21,17 +24,23 @@ namespace Volo.Abp.Account.Web.Areas.Account.Controllers
{ {
private readonly SignInManager<IdentityUser> _signInManager; private readonly SignInManager<IdentityUser> _signInManager;
private readonly IdentityUserManager _userManager; private readonly IdentityUserManager _userManager;
private readonly ISettingProvider _settingProvider;
public AccountController(SignInManager<IdentityUser> signInManager, IdentityUserManager userManager) public AccountController(SignInManager<IdentityUser> signInManager, IdentityUserManager userManager, ISettingProvider settingProvider)
{ {
LocalizationResource = typeof(AccountResource);
_signInManager = signInManager; _signInManager = signInManager;
_userManager = userManager; _userManager = userManager;
_settingProvider = settingProvider;
} }
[HttpPost] [HttpPost]
[Route("login")] [Route("login")]
public virtual async Task<AbpLoginResult> Login(UserLoginInfo login) public virtual async Task<AbpLoginResult> Login(UserLoginInfo login)
{ {
await CheckLocalLoginAsync();
ValidateLoginInfo(login); ValidateLoginInfo(login);
await ReplaceEmailToUsernameOfInputIfNeeds(login).ConfigureAwait(false); await ReplaceEmailToUsernameOfInputIfNeeds(login).ConfigureAwait(false);
@ -133,5 +142,13 @@ namespace Volo.Abp.Account.Web.Areas.Account.Controllers
throw new ArgumentNullException(nameof(login.Password)); throw new ArgumentNullException(nameof(login.Password));
} }
} }
private async Task CheckLocalLoginAsync()
{
if (!await _settingProvider.IsTrueAsync(AccountSettingNames.EnableLocalLogin).ConfigureAwait(false))
{
throw new UserFriendlyException(L["LocalLoginDisabledMessage"]);
}
}
} }
} }

10
modules/account/src/Volo.Abp.Account.Web/Pages/Account/Login.cshtml.cs

@ -89,7 +89,7 @@ namespace Volo.Abp.Account.Web.Pages.Account
[UnitOfWork] //TODO: Will be removed when we implement action filter [UnitOfWork] //TODO: Will be removed when we implement action filter
public virtual async Task<IActionResult> OnPostAsync(string action) public virtual async Task<IActionResult> OnPostAsync(string action)
{ {
EnableLocalLogin = await SettingProvider.IsTrueAsync(AccountSettingNames.EnableLocalLogin).ConfigureAwait(false); await CheckLocalLoginAsync();
ValidateModel(); ValidateModel();
@ -237,6 +237,14 @@ namespace Volo.Abp.Account.Web.Pages.Account
LoginInput.UserNameOrEmailAddress = userByEmail.UserName; LoginInput.UserNameOrEmailAddress = userByEmail.UserName;
} }
protected virtual async Task CheckLocalLoginAsync()
{
if (!await SettingProvider.IsTrueAsync(AccountSettingNames.EnableLocalLogin).ConfigureAwait(false))
{
throw new UserFriendlyException(L["LocalLoginDisabledMessage"]);
}
}
public class LoginInputModel public class LoginInputModel
{ {
[Required] [Required]

Loading…
Cancel
Save