Browse Source

Change the current tenant via querystrings.

pull/9369/head
maliming 5 years ago
parent
commit
a5fd8d2195
  1. 2
      modules/account/src/Volo.Abp.Account.Web/AbpAccountWebModule.cs
  2. 8
      modules/account/src/Volo.Abp.Account.Web/Pages/Account/AccountPageModel.cs
  3. 42
      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.Web.Pages.Account;
using Volo.Abp.Account.Web.ProfileManagement;
using Volo.Abp.AspNetCore.MultiTenancy;
using Volo.Abp.AspNetCore.Mvc.Localization;
using Volo.Abp.AspNetCore.Mvc.UI.Bundling;
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared;
@ -21,6 +22,7 @@ namespace Volo.Abp.Account.Web
typeof(AbpIdentityAspNetCoreModule),
typeof(AbpAutoMapperModule),
typeof(AbpAspNetCoreMvcUiThemeSharedModule),
typeof(AbpAspNetCoreMultiTenancyModule),
typeof(AbpExceptionHandlingModule)
)]
public class AbpAccountWebModule : AbpModule

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

@ -37,14 +37,6 @@ namespace Volo.Abp.Account.Web.Pages.Account
//identityResult.CheckErrors(LocalizationManager); //TODO: Get from old Abp
}
protected virtual void CheckCurrentTenant(Guid? tenantId)
{
if (CurrentTenant.Id != tenantId)
{
throw new ApplicationException($"Current tenant is different than given tenant. CurrentTenant.Id: {CurrentTenant.Id}, given tenantId: {tenantId}");
}
}
protected virtual string GetLocalizeExceptionMessage(Exception exception)
{
if (exception is ILocalizeErrorMessage || exception is IHasErrorCode)

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

@ -1,7 +1,11 @@
using System;
using System.ComponentModel.DataAnnotations;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Extensions;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using Volo.Abp.AspNetCore.MultiTenancy;
using Volo.Abp.Auditing;
using Volo.Abp.Identity;
using Volo.Abp.MultiTenancy;
@ -51,13 +55,49 @@ namespace Volo.Abp.Account.Web.Pages.Account
protected virtual ITenantResolveResultAccessor TenantResolveResultAccessor { get; }
public ResetPasswordModel(ITenantResolveResultAccessor tenantResolveResultAccessor)
protected virtual AbpAspNetCoreMultiTenancyOptions AspNetCoreMultiTenancyOptions { get; }
protected virtual AbpMultiTenancyOptions MultiTenancyOptions { get; }
public ResetPasswordModel(
ITenantResolveResultAccessor tenantResolveResultAccessor,
IOptions<AbpAspNetCoreMultiTenancyOptions> aspNetCoreMultiTenancyOptions,
IOptions<AbpMultiTenancyOptions> multiTenancyOptions)
{
TenantResolveResultAccessor = tenantResolveResultAccessor;
AspNetCoreMultiTenancyOptions = aspNetCoreMultiTenancyOptions.Value;
MultiTenancyOptions = multiTenancyOptions.Value;
}
public virtual Task<IActionResult> OnGetAsync()
{
if (MultiTenancyOptions.IsEnabled &&
TenantResolveResultAccessor.Result?.AppliedResolvers?.Contains(CookieTenantResolveContributor.ContributorName) == true)
{
if (CurrentTenant.Id != TenantId)
{
if (TenantId != null)
{
Response.Cookies.Append(
AspNetCoreMultiTenancyOptions.TenantKey,
TenantId.ToString(),
new CookieOptions
{
Path = "/",
HttpOnly = false,
Expires = DateTimeOffset.Now.AddYears(10)
}
);
}
else
{
Response.Cookies.Delete(AspNetCoreMultiTenancyOptions.TenantKey);
}
return Task.FromResult<IActionResult>(Redirect(HttpContext.Request.GetEncodedUrl()));
}
}
return Task.FromResult<IActionResult>(Page());
}

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

@ -35,6 +35,7 @@
<ItemGroup>
<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.MultiTenancy\Volo.Abp.AspNetCore.MultiTenancy.csproj" />
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.AutoMapper\Volo.Abp.AutoMapper.csproj" />
<ProjectReference Include="..\Volo.Abp.Account.HttpApi\Volo.Abp.Account.HttpApi.csproj" />
</ItemGroup>

Loading…
Cancel
Save