Merge pull request #3173 from abpframework/Cotur-Virtualization-Account

Make Account module services easily overridable by inheritance
pull/3175/head
Halil İbrahim Kalkan 5 years ago committed by GitHub
commit 237a353060
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -10,14 +10,14 @@ namespace Volo.Abp.Account
{
public class AccountAppService : ApplicationService, IAccountAppService
{
private readonly IIdentityRoleRepository _roleRepository;
protected IIdentityRoleRepository RoleRepository { get; }
protected IdentityUserManager UserManager { get; }
public AccountAppService(
IdentityUserManager userManager,
IIdentityRoleRepository roleRepository)
{
_roleRepository = roleRepository;
RoleRepository = roleRepository;
UserManager = userManager;
}
@ -43,4 +43,4 @@ namespace Volo.Abp.Account
}
}
}
}
}

@ -10,18 +10,18 @@ namespace Volo.Abp.Account
[Route("api/account")]
public class AccountController : AbpController, IAccountAppService
{
private readonly IAccountAppService _accountAppService;
protected IAccountAppService AccountAppService { get; }
public AccountController(IAccountAppService accountAppService)
{
_accountAppService = accountAppService;
AccountAppService = accountAppService;
}
[HttpPost]
[Route("register")]
public Task<IdentityUserDto> RegisterAsync(RegisterDto input)
public virtual Task<IdentityUserDto> RegisterAsync(RegisterDto input)
{
return _accountAppService.RegisterAsync(input);
return AccountAppService.RegisterAsync(input);
}
}
}

@ -68,10 +68,10 @@ namespace Volo.Abp.Account.Web.Pages.Account
return Page();
}
var schemes = await _schemeProvider.GetAllSchemesAsync();
var schemes = await SchemeProvider.GetAllSchemesAsync();
var providers = schemes
.Where(x => x.DisplayName != null || x.Name.Equals(_accountOptions.WindowsAuthenticationSchemeName, StringComparison.OrdinalIgnoreCase))
.Where(x => x.DisplayName != null || x.Name.Equals(AccountOptions.WindowsAuthenticationSchemeName, StringComparison.OrdinalIgnoreCase))
.Select(x => new ExternalProviderModel
{
DisplayName = x.DisplayName,
@ -174,7 +174,7 @@ namespace Volo.Abp.Account.Web.Pages.Account
[UnitOfWork]
public override async Task<IActionResult> OnPostExternalLogin(string provider)
{
if (_accountOptions.WindowsAuthenticationSchemeName == provider)
if (AccountOptions.WindowsAuthenticationSchemeName == provider)
{
return await ProcessWindowsLoginAsync();
}
@ -184,10 +184,10 @@ namespace Volo.Abp.Account.Web.Pages.Account
private async Task<IActionResult> ProcessWindowsLoginAsync()
{
var result = await HttpContext.AuthenticateAsync(_accountOptions.WindowsAuthenticationSchemeName);
var result = await HttpContext.AuthenticateAsync(AccountOptions.WindowsAuthenticationSchemeName);
if (!(result?.Principal is WindowsPrincipal windowsPrincipal))
{
return Challenge(_accountOptions.WindowsAuthenticationSchemeName);
return Challenge(AccountOptions.WindowsAuthenticationSchemeName);
}
var props = new AuthenticationProperties
@ -195,11 +195,11 @@ namespace Volo.Abp.Account.Web.Pages.Account
RedirectUri = Url.Page("./Login", pageHandler: "ExternalLoginCallback", values: new { ReturnUrl, ReturnUrlHash }),
Items =
{
{"scheme", _accountOptions.WindowsAuthenticationSchemeName},
{"scheme", AccountOptions.WindowsAuthenticationSchemeName},
}
};
var identity = new ClaimsIdentity(_accountOptions.WindowsAuthenticationSchemeName);
var identity = new ClaimsIdentity(AccountOptions.WindowsAuthenticationSchemeName);
identity.AddClaim(new Claim(JwtClaimTypes.Subject, windowsPrincipal.Identity.Name));
identity.AddClaim(new Claim(JwtClaimTypes.Name, windowsPrincipal.Identity.Name));

@ -9,7 +9,7 @@ namespace Volo.Abp.Account.Web
{
public class AbpAccountUserMenuContributor : IMenuContributor
{
public Task ConfigureMenuAsync(MenuConfigurationContext context)
public virtual Task ConfigureMenuAsync(MenuConfigurationContext context)
{
if (context.Menu.Name != StandardMenus.User)
{

@ -8,7 +8,7 @@ namespace Volo.Abp.Account.Web
{
public class AccountModuleToolbarContributor : IToolbarContributor
{
public Task ConfigureToolbarAsync(IToolbarConfigurationContext context)
public virtual Task ConfigureToolbarAsync(IToolbarConfigurationContext context)
{
if (context.Toolbar.Name != StandardToolbars.Main)
{

@ -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"]);
}

@ -5,7 +5,7 @@ namespace Volo.Abp.Account.Web.Modules.Account.Components.Toolbar.UserLoginLink
{
public class UserLoginLinkViewComponent : AbpViewComponent
{
public IViewComponentResult Invoke()
public virtual IViewComponentResult Invoke()
{
return View("~/Modules/Account/Components/Toolbar/UserLoginLink/Default.cshtml");
}

@ -21,12 +21,12 @@ namespace Volo.Abp.Account.Web.Pages.Account
ObjectMapperContext = typeof(AbpAccountWebModule);
}
protected RedirectResult RedirectSafely(string returnUrl, string returnUrlHash = null)
protected virtual RedirectResult RedirectSafely(string returnUrl, string returnUrlHash = null)
{
return Redirect(GetRedirectUrl(returnUrl, returnUrlHash));
}
protected void CheckIdentityErrors(IdentityResult identityResult)
protected virtual void CheckIdentityErrors(IdentityResult identityResult)
{
if (!identityResult.Succeeded)
{
@ -36,7 +36,7 @@ namespace Volo.Abp.Account.Web.Pages.Account
//identityResult.CheckErrors(LocalizationManager); //TODO: Get from old Abp
}
private string GetRedirectUrl(string returnUrl, string returnUrlHash = null)
protected virtual string GetRedirectUrl(string returnUrl, string returnUrlHash = null)
{
returnUrl = NormalizeReturnUrl(returnUrl);
@ -48,7 +48,7 @@ namespace Volo.Abp.Account.Web.Pages.Account
return returnUrl;
}
private string NormalizeReturnUrl(string returnUrl)
protected virtual string NormalizeReturnUrl(string returnUrl)
{
if (returnUrl.IsNullOrEmpty())
{

@ -48,25 +48,25 @@ namespace Volo.Abp.Account.Web.Pages.Account
//public IClientStore ClientStore { get; set; }
//public IEventService IdentityServerEvents { get; set; }
protected IAuthenticationSchemeProvider _schemeProvider;
protected AbpAccountOptions _accountOptions;
protected IAuthenticationSchemeProvider SchemeProvider { get; }
protected AbpAccountOptions AccountOptions { get; }
public LoginModel(
IAuthenticationSchemeProvider schemeProvider,
IOptions<AbpAccountOptions> accountOptions)
{
_schemeProvider = schemeProvider;
_accountOptions = accountOptions.Value;
SchemeProvider = schemeProvider;
AccountOptions = accountOptions.Value;
}
public virtual async Task<IActionResult> OnGetAsync()
{
LoginInput = new LoginInputModel();
var schemes = await _schemeProvider.GetAllSchemesAsync();
var schemes = await SchemeProvider.GetAllSchemesAsync();
var providers = schemes
.Where(x => x.DisplayName != null || x.Name.Equals(_accountOptions.WindowsAuthenticationSchemeName, StringComparison.OrdinalIgnoreCase))
.Where(x => x.DisplayName != null || x.Name.Equals(AccountOptions.WindowsAuthenticationSchemeName, StringComparison.OrdinalIgnoreCase))
.Select(x => new ExternalProviderModel
{
DisplayName = x.DisplayName,

@ -23,5 +23,10 @@ namespace Volo.Abp.Account.Web.Pages.Account
return RedirectToPage("/Account/Login");
}
public virtual Task OnPostAsync()
{
return Task.CompletedTask;
}
}
}

@ -10,19 +10,24 @@ namespace Volo.Abp.Account.Web.Pages.Account
public PersonalSettingsInfoModel PersonalSettingsInfoModel { get; set; }
private readonly IProfileAppService _profileAppService;
protected IProfileAppService ProfileAppService { get; }
public ManageModel(IProfileAppService profileAppService)
{
_profileAppService = profileAppService;
ProfileAppService = profileAppService;
}
public async Task OnGetAsync()
public virtual async Task OnGetAsync()
{
var user = await _profileAppService.GetAsync();
var user = await ProfileAppService.GetAsync();
PersonalSettingsInfoModel = ObjectMapper.Map<ProfileDto, PersonalSettingsInfoModel>(user);
}
public virtual Task OnPostAsync()
{
return Task.CompletedTask;
}
}
public class ChangePasswordInfoModel

@ -15,7 +15,7 @@ namespace Volo.Abp.Account.Web.Pages.Account
{
public class RegisterModel : AccountPageModel
{
private readonly IAccountAppService _accountAppService;
protected IAccountAppService AccountAppService { get; }
[BindProperty(SupportsGet = true)]
public string ReturnUrl { get; set; }
@ -28,7 +28,7 @@ namespace Volo.Abp.Account.Web.Pages.Account
public RegisterModel(IAccountAppService accountAppService)
{
_accountAppService = accountAppService;
AccountAppService = accountAppService;
}
public virtual async Task OnGetAsync()
@ -51,7 +51,7 @@ namespace Volo.Abp.Account.Web.Pages.Account
UserName = Input.UserName
};
var userDto = await _accountAppService.RegisterAsync(registerDto);
var userDto = await AccountAppService.RegisterAsync(registerDto);
var user = await UserManager.GetByIdAsync(userDto.Id);
await UserManager.SetEmailAsync(user, Input.EmailAddress);

@ -12,7 +12,7 @@ namespace Volo.Abp.Account.Web.Pages.Account
{
public List<SelectListItem> Providers { get; set; }
public async Task<IActionResult> OnGetAsync()
public virtual async Task<IActionResult> OnGetAsync()
{
var user = await SignInManager.GetTwoFactorAuthenticationUserAsync();
if (user == null)
@ -41,5 +41,9 @@ namespace Volo.Abp.Account.Web.Pages.Account
//);
}
public virtual Task OnPostAsync()
{
return Task.CompletedTask;
}
}
}
Loading…
Cancel
Save