Browse Source

Merge pull request #9369 from abpframework/maliming/tenantid

Change the current tenant via querystrings.
pull/9382/head
Halil İbrahim Kalkan 5 years ago
committed by GitHub
parent
commit
361352a19a
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      modules/account/src/Volo.Abp.Account.Web/AbpAccountWebModule.cs
  2. 52
      modules/account/src/Volo.Abp.Account.Web/Pages/Account/AccountPageModel.cs
  3. 14
      modules/account/src/Volo.Abp.Account.Web/Pages/Account/ResetPassword.cshtml.cs
  4. 1
      modules/account/src/Volo.Abp.Account.Web/Volo.Abp.Account.Web.csproj

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

@ -3,6 +3,7 @@ using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Account.Localization; using Volo.Abp.Account.Localization;
using Volo.Abp.Account.Web.Pages.Account; using Volo.Abp.Account.Web.Pages.Account;
using Volo.Abp.Account.Web.ProfileManagement; using Volo.Abp.Account.Web.ProfileManagement;
using Volo.Abp.AspNetCore.MultiTenancy;
using Volo.Abp.AspNetCore.Mvc.Localization; using Volo.Abp.AspNetCore.Mvc.Localization;
using Volo.Abp.AspNetCore.Mvc.UI.Bundling; using Volo.Abp.AspNetCore.Mvc.UI.Bundling;
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared; using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared;
@ -21,6 +22,7 @@ namespace Volo.Abp.Account.Web
typeof(AbpIdentityAspNetCoreModule), typeof(AbpIdentityAspNetCoreModule),
typeof(AbpAutoMapperModule), typeof(AbpAutoMapperModule),
typeof(AbpAspNetCoreMvcUiThemeSharedModule), typeof(AbpAspNetCoreMvcUiThemeSharedModule),
typeof(AbpAspNetCoreMultiTenancyModule),
typeof(AbpExceptionHandlingModule) typeof(AbpExceptionHandlingModule)
)] )]
public class AbpAccountWebModule : AbpModule public class AbpAccountWebModule : AbpModule

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

@ -1,13 +1,19 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Extensions;
using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using Volo.Abp.Account.Localization; using Volo.Abp.Account.Localization;
using Volo.Abp.AspNetCore.ExceptionHandling; using Volo.Abp.AspNetCore.ExceptionHandling;
using Volo.Abp.AspNetCore.MultiTenancy;
using Volo.Abp.AspNetCore.Mvc.UI.RazorPages; using Volo.Abp.AspNetCore.Mvc.UI.RazorPages;
using Volo.Abp.ExceptionHandling; using Volo.Abp.ExceptionHandling;
using Volo.Abp.Identity; using Volo.Abp.Identity;
using Volo.Abp.MultiTenancy;
using IdentityUser = Volo.Abp.Identity.IdentityUser; using IdentityUser = Volo.Abp.Identity.IdentityUser;
namespace Volo.Abp.Account.Web.Pages.Account namespace Volo.Abp.Account.Web.Pages.Account
@ -21,20 +27,48 @@ namespace Volo.Abp.Account.Web.Pages.Account
public IOptions<IdentityOptions> IdentityOptions { get; set; } public IOptions<IdentityOptions> IdentityOptions { get; set; }
public IExceptionToErrorInfoConverter ExceptionToErrorInfoConverter { get; set; } public IExceptionToErrorInfoConverter ExceptionToErrorInfoConverter { get; set; }
public ITenantResolveResultAccessor TenantResolveResultAccessor { get; set; }
public IOptions<AbpAspNetCoreMultiTenancyOptions> AspNetCoreMultiTenancyOptions { get; set; }
public IOptions<AbpMultiTenancyOptions> MultiTenancyOptions { get; set; }
protected AccountPageModel() protected AccountPageModel()
{ {
LocalizationResourceType = typeof(AccountResource); LocalizationResourceType = typeof(AccountResource);
ObjectMapperContext = typeof(AbpAccountWebModule); ObjectMapperContext = typeof(AbpAccountWebModule);
} }
protected virtual void CheckIdentityErrors(IdentityResult identityResult) protected virtual bool SwitchTenant(Guid? tenantId)
{ {
if (!identityResult.Succeeded) if (MultiTenancyOptions.Value.IsEnabled &&
TenantResolveResultAccessor.Result?.AppliedResolvers?.Contains(CookieTenantResolveContributor.ContributorName) == true)
{ {
throw new UserFriendlyException("Operation failed: " + identityResult.Errors.Select(e => $"[{e.Code}] {e.Description}").JoinAsString(", ")); if (CurrentTenant.Id != tenantId)
{
if (tenantId != null)
{
Response.Cookies.Append(
AspNetCoreMultiTenancyOptions.Value.TenantKey,
tenantId.ToString(),
new CookieOptions
{
Path = "/",
HttpOnly = false,
Expires = DateTimeOffset.Now.AddYears(10)
}
);
}
else
{
Response.Cookies.Delete(AspNetCoreMultiTenancyOptions.Value.TenantKey);
}
return true;
}
} }
//identityResult.CheckErrors(LocalizationManager); //TODO: Get from old Abp return false;
} }
protected virtual void CheckCurrentTenant(Guid? tenantId) protected virtual void CheckCurrentTenant(Guid? tenantId)
@ -45,6 +79,16 @@ namespace Volo.Abp.Account.Web.Pages.Account
} }
} }
protected virtual void CheckIdentityErrors(IdentityResult identityResult)
{
if (!identityResult.Succeeded)
{
throw new UserFriendlyException("Operation failed: " + identityResult.Errors.Select(e => $"[{e.Code}] {e.Description}").JoinAsString(", "));
}
//identityResult.CheckErrors(LocalizationManager); //TODO: Get from old Abp
}
protected virtual string GetLocalizeExceptionMessage(Exception exception) protected virtual string GetLocalizeExceptionMessage(Exception exception)
{ {
if (exception is ILocalizeErrorMessage || exception is IHasErrorCode) if (exception is ILocalizeErrorMessage || exception is IHasErrorCode)

14
modules/account/src/Volo.Abp.Account.Web/Pages/Account/ResetPassword.cshtml.cs

@ -1,10 +1,10 @@
using System; using System;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Http.Extensions;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Volo.Abp.Auditing; using Volo.Abp.Auditing;
using Volo.Abp.Identity; using Volo.Abp.Identity;
using Volo.Abp.MultiTenancy;
using Volo.Abp.Validation; using Volo.Abp.Validation;
namespace Volo.Abp.Account.Web.Pages.Account namespace Volo.Abp.Account.Web.Pages.Account
@ -49,15 +49,13 @@ namespace Volo.Abp.Account.Web.Pages.Account
[DisableAuditing] [DisableAuditing]
public string ConfirmPassword { get; set; } public string ConfirmPassword { get; set; }
protected virtual ITenantResolveResultAccessor TenantResolveResultAccessor { get; }
public ResetPasswordModel(ITenantResolveResultAccessor tenantResolveResultAccessor)
{
TenantResolveResultAccessor = tenantResolveResultAccessor;
}
public virtual Task<IActionResult> OnGetAsync() public virtual Task<IActionResult> OnGetAsync()
{ {
if (SwitchTenant(TenantId))
{
return Task.FromResult<IActionResult>(Redirect(HttpContext.Request.GetEncodedUrl()));
}
return Task.FromResult<IActionResult>(Page()); return Task.FromResult<IActionResult>(Page());
} }

1
modules/account/src/Volo.Abp.Account.Web/Volo.Abp.Account.Web.csproj

@ -35,6 +35,7 @@
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\..\identity\src\Volo.Abp.Identity.AspNetCore\Volo.Abp.Identity.AspNetCore.csproj" /> <ProjectReference Include="..\..\..\identity\src\Volo.Abp.Identity.AspNetCore\Volo.Abp.Identity.AspNetCore.csproj" />
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared\Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.csproj" /> <ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared\Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.csproj" />
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.AspNetCore.MultiTenancy\Volo.Abp.AspNetCore.MultiTenancy.csproj" />
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.AutoMapper\Volo.Abp.AutoMapper.csproj" /> <ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.AutoMapper\Volo.Abp.AutoMapper.csproj" />
<ProjectReference Include="..\Volo.Abp.Account.HttpApi\Volo.Abp.Account.HttpApi.csproj" /> <ProjectReference Include="..\Volo.Abp.Account.HttpApi\Volo.Abp.Account.HttpApi.csproj" />
</ItemGroup> </ItemGroup>

Loading…
Cancel
Save