|
|
|
@ -22,17 +22,17 @@ namespace Volo.Abp.Account.Web.Areas.Account.Controllers
|
|
|
|
|
[Route("api/account")]
|
|
|
|
|
public class AccountController : AbpController
|
|
|
|
|
{
|
|
|
|
|
private readonly SignInManager<IdentityUser> _signInManager;
|
|
|
|
|
private readonly IdentityUserManager _userManager;
|
|
|
|
|
private readonly ISettingProvider _settingProvider;
|
|
|
|
|
protected SignInManager<IdentityUser> SignInManager { get; }
|
|
|
|
|
protected IdentityUserManager UserManager { get; }
|
|
|
|
|
protected ISettingProvider SettingProvider { get; }
|
|
|
|
|
|
|
|
|
|
public AccountController(SignInManager<IdentityUser> signInManager, IdentityUserManager userManager, ISettingProvider settingProvider)
|
|
|
|
|
{
|
|
|
|
|
LocalizationResource = typeof(AccountResource);
|
|
|
|
|
|
|
|
|
|
_signInManager = signInManager;
|
|
|
|
|
_userManager = userManager;
|
|
|
|
|
_settingProvider = settingProvider;
|
|
|
|
|
SignInManager = signInManager;
|
|
|
|
|
UserManager = userManager;
|
|
|
|
|
SettingProvider = settingProvider;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
@ -45,7 +45,7 @@ namespace Volo.Abp.Account.Web.Areas.Account.Controllers
|
|
|
|
|
|
|
|
|
|
await ReplaceEmailToUsernameOfInputIfNeeds(login);
|
|
|
|
|
|
|
|
|
|
return GetAbpLoginResult(await _signInManager.PasswordSignInAsync(
|
|
|
|
|
return GetAbpLoginResult(await SignInManager.PasswordSignInAsync(
|
|
|
|
|
login.UserNameOrEmailAddress,
|
|
|
|
|
login.Password,
|
|
|
|
|
login.RememberMe,
|
|
|
|
@ -57,7 +57,7 @@ namespace Volo.Abp.Account.Web.Areas.Account.Controllers
|
|
|
|
|
[Route("logout")]
|
|
|
|
|
public virtual async Task Logout()
|
|
|
|
|
{
|
|
|
|
|
await _signInManager.SignOutAsync();
|
|
|
|
|
await SignInManager.SignOutAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
@ -68,14 +68,14 @@ namespace Volo.Abp.Account.Web.Areas.Account.Controllers
|
|
|
|
|
|
|
|
|
|
await ReplaceEmailToUsernameOfInputIfNeeds(login);
|
|
|
|
|
|
|
|
|
|
var identityUser = await _userManager.FindByNameAsync(login.UserNameOrEmailAddress);
|
|
|
|
|
var identityUser = await UserManager.FindByNameAsync(login.UserNameOrEmailAddress);
|
|
|
|
|
|
|
|
|
|
if (identityUser == null)
|
|
|
|
|
{
|
|
|
|
|
return new AbpLoginResult(LoginResultType.InvalidUserNameOrPassword);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return GetAbpLoginResult(await _signInManager.CheckPasswordSignInAsync(identityUser, login.Password, true));
|
|
|
|
|
return GetAbpLoginResult(await SignInManager.CheckPasswordSignInAsync(identityUser, login.Password, true));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected virtual async Task ReplaceEmailToUsernameOfInputIfNeeds(UserLoginInfo login)
|
|
|
|
@ -85,13 +85,13 @@ namespace Volo.Abp.Account.Web.Areas.Account.Controllers
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var userByUsername = await _userManager.FindByNameAsync(login.UserNameOrEmailAddress);
|
|
|
|
|
var userByUsername = await UserManager.FindByNameAsync(login.UserNameOrEmailAddress);
|
|
|
|
|
if (userByUsername != null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var userByEmail = await _userManager.FindByEmailAsync(login.UserNameOrEmailAddress);
|
|
|
|
|
var userByEmail = await UserManager.FindByEmailAsync(login.UserNameOrEmailAddress);
|
|
|
|
|
if (userByEmail == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
@ -125,7 +125,7 @@ namespace Volo.Abp.Account.Web.Areas.Account.Controllers
|
|
|
|
|
return new AbpLoginResult(LoginResultType.Success);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ValidateLoginInfo(UserLoginInfo login)
|
|
|
|
|
protected virtual void ValidateLoginInfo(UserLoginInfo login)
|
|
|
|
|
{
|
|
|
|
|
if (login == null)
|
|
|
|
|
{
|
|
|
|
@ -143,9 +143,9 @@ namespace Volo.Abp.Account.Web.Areas.Account.Controllers
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task CheckLocalLoginAsync()
|
|
|
|
|
protected virtual async Task CheckLocalLoginAsync()
|
|
|
|
|
{
|
|
|
|
|
if (!await _settingProvider.IsTrueAsync(AccountSettingNames.EnableLocalLogin))
|
|
|
|
|
if (!await SettingProvider.IsTrueAsync(AccountSettingNames.EnableLocalLogin))
|
|
|
|
|
{
|
|
|
|
|
throw new UserFriendlyException(L["LocalLoginDisabledMessage"]);
|
|
|
|
|
}
|
|
|
|
|