Skip to content

Commit 39c6892

Browse files
committed
Enabled multi-tenancy and modified login.
1 parent aaf24a1 commit 39c6892

File tree

7 files changed

+53
-7
lines changed

7 files changed

+53
-7
lines changed

src/AbpCompanyName.AbpProjectName.Core/AbpProjectNameCoreModule.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ namespace AbpCompanyName.AbpProjectName
77
[DependsOn(typeof(AbpZeroCoreModule))]
88
public class AbpProjectNameCoreModule : AbpModule
99
{
10+
public override void PreInitialize()
11+
{
12+
//Remove the following line to disable multi-tenancy.
13+
Configuration.MultiTenancy.IsEnabled = true;
14+
}
15+
1016
public override void Initialize()
1117
{
1218
IocManager.RegisterAssemblyByConvention(Assembly.GetExecutingAssembly());

src/AbpCompanyName.AbpProjectName.WebSpaAngular/AbpCompanyName.AbpProjectName.WebSpaAngular.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,6 +1169,7 @@
11691169
<Compile Include="Global.asax.cs">
11701170
<DependentUpon>Global.asax</DependentUpon>
11711171
</Compile>
1172+
<Compile Include="Models\Account\LoginFormViewModel.cs" />
11721173
<Compile Include="Models\Account\LoginViewModel.cs" />
11731174
<Compile Include="Properties\AssemblyInfo.cs" />
11741175
<Compile Include="Views\AbpProjectNameWebViewPageBase.cs" />

src/AbpCompanyName.AbpProjectName.WebSpaAngular/Controllers/AccountController.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
using System.Threading.Tasks;
22
using System.Web;
33
using System.Web.Mvc;
4+
using Abp.Auditing;
45
using Abp.Authorization.Users;
6+
using Abp.Configuration.Startup;
57
using Abp.UI;
68
using Abp.Web.Mvc.Models;
79
using AbpCompanyName.AbpProjectName.Users;
@@ -14,6 +16,7 @@ namespace AbpCompanyName.AbpProjectName.WebSpaAngular.Controllers
1416
public class AccountController : AbpProjectNameControllerBase
1517
{
1618
private readonly UserManager _userManager;
19+
private readonly IMultiTenancyConfig _multiTenancyConfig;
1720

1821
private IAuthenticationManager AuthenticationManager
1922
{
@@ -23,9 +26,10 @@ private IAuthenticationManager AuthenticationManager
2326
}
2427
}
2528

26-
public AccountController(UserManager userManager)
29+
public AccountController(UserManager userManager, IMultiTenancyConfig multiTenancyConfig)
2730
{
2831
_userManager = userManager;
32+
_multiTenancyConfig = multiTenancyConfig;
2933
}
3034

3135
public ActionResult Login(string returnUrl = "")
@@ -35,12 +39,16 @@ public ActionResult Login(string returnUrl = "")
3539
returnUrl = Request.ApplicationPath;
3640
}
3741

38-
ViewBag.ReturnUrl = returnUrl;
39-
40-
return View();
42+
return View(
43+
new LoginFormViewModel
44+
{
45+
ReturnUrl = returnUrl,
46+
IsMultiTenancyEnabled = _multiTenancyConfig.IsEnabled
47+
});
4148
}
4249

4350
[HttpPost]
51+
[DisableAuditing]
4452
public async Task<JsonResult> Login(LoginViewModel loginModel, string returnUrl = "")
4553
{
4654
if (!ModelState.IsValid)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace AbpCompanyName.AbpProjectName.WebSpaAngular.Models.Account
2+
{
3+
public class LoginFormViewModel
4+
{
5+
public string ReturnUrl { get; set; }
6+
7+
public bool IsMultiTenancyEnabled { get; set; }
8+
}
9+
}

src/AbpCompanyName.AbpProjectName.WebSpaAngular/Views/Account/Login.cshtml

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
@section Styles
1+
@model AbpCompanyName.AbpProjectName.WebSpaAngular.Models.Account.LoginFormViewModel
2+
@section Styles
23
{
34
<link href="~/Views/Account/Login.css" rel="stylesheet" />
45
}
@@ -10,14 +11,30 @@
1011
<div id="LoginArea" class="row">
1112
<div class="col-lg-12">
1213
<div class="well bs-component">
13-
<form class="form-horizontal">
14+
<form class="form-horizontal" action="@(Url.Action("Login","Account"))?returnUrl=@(Model.ReturnUrl)">
1415
<fieldset>
1516
<legend>Login</legend>
17+
18+
@if (Model.IsMultiTenancyEnabled)
19+
{
20+
<div class="form-group">
21+
<div class="col-lg-12">
22+
<input type="text" class="form-control" id="TenancyName" placeholder="Tenancy name">
23+
<span class="text-muted">Can be empty to login as host.</span>
24+
</div>
25+
</div>
26+
}
27+
else
28+
{
29+
<input type="hidden" id="TenancyName" value="">
30+
}
31+
1632
<div class="form-group">
1733
<div class="col-lg-12">
18-
<input type="text" class="form-control floating-label" id="EmailAddressInput" placeholder="User name or email">
34+
<input type="text" class="form-control " id="EmailAddressInput" placeholder="User name or email">
1935
</div>
2036
</div>
37+
2138
<div class="form-group">
2239
<div class="col-lg-12">
2340
<input type="password" class="form-control" id="PasswordInput" placeholder="Password">
@@ -30,6 +47,7 @@
3047
</div>
3148
</div>
3249
</div>
50+
3351
<div class="form-group">
3452
<div class="col-lg-12">
3553
<button id="LoginButton" class="btn btn-primary"><i class="fa fa-sign-out"></i> Login</button>

src/AbpCompanyName.AbpProjectName.WebSpaAngular/Views/Account/Login.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
url: abp.appPath + 'Account/Login',
1010
type: 'POST',
1111
data: JSON.stringify({
12+
tenancyName: $('#TenancyName').val(),
1213
usernameOrEmailAddress: $('#EmailAddressInput').val(),
1314
password: $('#PasswordInput').val(),
1415
rememberMe: $('#RememberMeInput').is(':checked')

src/Tests/AbpCompanyName.AbpProjectName.Tests/AbpCompanyName.AbpProjectName.Tests.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@
160160
<Name>AbpCompanyName.AbpProjectName.EntityFramework</Name>
161161
</ProjectReference>
162162
</ItemGroup>
163+
<ItemGroup>
164+
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
165+
</ItemGroup>
163166
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
164167
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
165168
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">

0 commit comments

Comments
 (0)