Browse Source

Added a temp action to switch current tenant.

pull/192/head
Halil İbrahim Kalkan 9 years ago
parent
commit
e0208ab252
  1. 55
      src/AbpDesk/AbpDesk.Web.Mvc/Controllers/MultiTenancyController.cs
  2. 4
      src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpIdentityServerDomainModule.cs

55
src/AbpDesk/AbpDesk.Web.Mvc/Controllers/MultiTenancyController.cs

@ -0,0 +1,55 @@
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Volo.Abp.AspNetCore.Mvc;
using Volo.Abp.MultiTenancy;
using Volo.Abp.Ui;
namespace AbpDesk.Web.Mvc.Controllers
{
/* TODO: This is temporary solution to switch tenant.
*/
public class MultiTenancyController : AbpController
{
private readonly ITenantStore _tenantStore;
public MultiTenancyController(ITenantStore tenantStore)
{
_tenantStore = tenantStore;
}
public async Task<ActionResult> SwitchTenant(string tenant = "")
{
var tenantInfo = await FindTenantAsync(tenant);
if (tenantInfo == null)
{
throw new UserFriendlyException("Unknown tenant: " + tenant);
}
HttpContext.Response.Cookies.Append(
"__tenant",
tenantInfo.Id.ToString(),
new CookieOptions
{
Expires = DateTimeOffset.Now.AddYears(1)
}
);
return Redirect("/");
}
private async Task<TenantInfo> FindTenantAsync(string tenantIdOrName)
{
if (Guid.TryParse(tenantIdOrName, out var parsedTenantId))
{
return await _tenantStore.FindAsync(parsedTenantId);
}
else
{
return await _tenantStore.FindAsync(tenantIdOrName);
}
}
}
}

4
src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpIdentityServerDomainModule.cs

@ -33,8 +33,8 @@ namespace Volo.Abp.IdentityServer
//TODO: Remove in-memory stores once EF Core stores are fully completed.
identityServerBuilder.AddDeveloperSigningCredential()
//.AddInMemoryClients(IdentityServerConfig.GetClients())
//.AddInMemoryApiResources(IdentityServerConfig.GetApiResources())
.AddInMemoryClients(IdentityServerConfig.GetClients())
.AddInMemoryApiResources(IdentityServerConfig.GetApiResources())
.AddAbpIdentityServer();
services.ExecutePreConfiguredActions(identityServerBuilder);

Loading…
Cancel
Save