Browse Source

Merge pull request #2761 from abpframework/maliming/EnableLocalLogin

Check EnableLocalLogin in the login method of the account module.
pull/2766/head
Halil İbrahim Kalkan 7 years ago
committed by GitHub
parent
commit
2328841062
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  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!",
"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.",
"LocalLoginDisabledMessage": "Local login is disabled for this application.",
"Login": "Login",
"Cancel": "Cancel",
"Register": "Register",

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

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

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

@ -11,6 +11,7 @@
"InvalidUserNameOrPassword": "使用者名稱或密碼錯誤!",
"LoginIsNotAllowed": "無法登入!你需要驗證電子信箱地址/手機號碼.",
"SelfRegistrationDisabledMessage": "應用程式未開放註冊,請聯絡管理員以加入新使用者.",
"LocalLoginDisabledMessage": "應用程序未開放本地賬戶登錄.",
"Login": "登入",
"Cancel": "取消",
"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
public override async Task<IActionResult> OnPostAsync(string action)
{
EnableLocalLogin = await SettingProvider.IsTrueAsync(AccountSettingNames.EnableLocalLogin).ConfigureAwait(false);
if (action == "Cancel")
{
var context = await Interaction.GetAuthorizationContextAsync(ReturnUrl).ConfigureAwait(false);
@ -122,6 +120,8 @@ namespace Volo.Abp.Account.Web.Pages.Account
return Redirect(ReturnUrl);
}
await CheckLocalLoginAsync();
ValidateModel();
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 Microsoft.AspNetCore.Identity;
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.AspNetCore.Mvc;
using Volo.Abp.Identity;
using Volo.Abp.Settings;
using Volo.Abp.Validation;
using SignInResult = Microsoft.AspNetCore.Identity.SignInResult;
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 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;
_userManager = userManager;
_settingProvider = settingProvider;
}
[HttpPost]
[Route("login")]
public virtual async Task<AbpLoginResult> Login(UserLoginInfo login)
{
await CheckLocalLoginAsync();
ValidateLoginInfo(login);
await ReplaceEmailToUsernameOfInputIfNeeds(login).ConfigureAwait(false);
@ -133,5 +142,13 @@ namespace Volo.Abp.Account.Web.Areas.Account.Controllers
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
public virtual async Task<IActionResult> OnPostAsync(string action)
{
EnableLocalLogin = await SettingProvider.IsTrueAsync(AccountSettingNames.EnableLocalLogin).ConfigureAwait(false);
await CheckLocalLoginAsync();
ValidateModel();
@ -237,6 +237,14 @@ namespace Volo.Abp.Account.Web.Pages.Account
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
{
[Required]

Loading…
Cancel
Save