Browse Source

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

Make Account module services easily overridable by inheritance
pull/3175/head
Halil İbrahim Kalkan 7 years ago
committed by GitHub
parent
commit
237a353060
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      modules/account/src/Volo.Abp.Account.Application/Volo/Abp/Account/AccountAppService.cs
  2. 8
      modules/account/src/Volo.Abp.Account.HttpApi/Volo/Abp/Account/AccountController.cs
  3. 14
      modules/account/src/Volo.Abp.Account.Web.IdentityServer/Pages/Account/IdentityServerSupportedLoginModel.cs
  4. 2
      modules/account/src/Volo.Abp.Account.Web/AbpAccountUserMenuContributor.cs
  5. 2
      modules/account/src/Volo.Abp.Account.Web/AccountModuleToolbarContributor.cs
  6. 30
      modules/account/src/Volo.Abp.Account.Web/Areas/Account/Controllers/AccountController.cs
  7. 2
      modules/account/src/Volo.Abp.Account.Web/Modules/Account/Components/Toolbar/UserLoginLink/UserLoginLinkViewComponent.cs
  8. 8
      modules/account/src/Volo.Abp.Account.Web/Pages/Account/AccountPageModel.cs
  9. 12
      modules/account/src/Volo.Abp.Account.Web/Pages/Account/Login.cshtml.cs
  10. 5
      modules/account/src/Volo.Abp.Account.Web/Pages/Account/Logout.cshtml.cs
  11. 13
      modules/account/src/Volo.Abp.Account.Web/Pages/Account/Manage.cshtml.cs
  12. 6
      modules/account/src/Volo.Abp.Account.Web/Pages/Account/Register.cshtml.cs
  13. 6
      modules/account/src/Volo.Abp.Account.Web/Pages/Account/SendSecurityCode.cshtml.cs

6
modules/account/src/Volo.Abp.Account.Application/Volo/Abp/Account/AccountAppService.cs

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

8
modules/account/src/Volo.Abp.Account.HttpApi/Volo/Abp/Account/AccountController.cs

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

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

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

2
modules/account/src/Volo.Abp.Account.Web/AbpAccountUserMenuContributor.cs

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

2
modules/account/src/Volo.Abp.Account.Web/AccountModuleToolbarContributor.cs

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

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

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

2
modules/account/src/Volo.Abp.Account.Web/Modules/Account/Components/Toolbar/UserLoginLink/UserLoginLinkViewComponent.cs

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

8
modules/account/src/Volo.Abp.Account.Web/Pages/Account/AccountPageModel.cs

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

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

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

5
modules/account/src/Volo.Abp.Account.Web/Pages/Account/Logout.cshtml.cs

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

13
modules/account/src/Volo.Abp.Account.Web/Pages/Account/Manage.cshtml.cs

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

6
modules/account/src/Volo.Abp.Account.Web/Pages/Account/Register.cshtml.cs

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

6
modules/account/src/Volo.Abp.Account.Web/Pages/Account/SendSecurityCode.cshtml.cs

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