Skip to content

Commit 51bb801

Browse files
committed
Copied related code from SPA template to MPA template and made working.
1 parent 48ca24a commit 51bb801

28 files changed

+1192
-7
lines changed

src/AbpCompanyName.AbpProjectName.WebMpa/AbpCompanyName.AbpProjectName.WebMpa.csproj

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,43 @@
118118
<HintPath>..\packages\Microsoft.AspNet.Identity.Core.2.2.1\lib\net45\Microsoft.AspNet.Identity.Core.dll</HintPath>
119119
<Private>True</Private>
120120
</Reference>
121+
<Reference Include="Microsoft.AspNet.Identity.Owin, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
122+
<HintPath>..\packages\Microsoft.AspNet.Identity.Owin.2.2.1\lib\net45\Microsoft.AspNet.Identity.Owin.dll</HintPath>
123+
<Private>True</Private>
124+
</Reference>
121125
<Reference Include="Microsoft.CSharp" />
126+
<Reference Include="Microsoft.Owin, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
127+
<HintPath>..\packages\Microsoft.Owin.3.0.1\lib\net45\Microsoft.Owin.dll</HintPath>
128+
<Private>True</Private>
129+
</Reference>
130+
<Reference Include="Microsoft.Owin.Host.SystemWeb, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
131+
<HintPath>..\packages\Microsoft.Owin.Host.SystemWeb.3.0.1\lib\net45\Microsoft.Owin.Host.SystemWeb.dll</HintPath>
132+
<Private>True</Private>
133+
</Reference>
134+
<Reference Include="Microsoft.Owin.Security, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
135+
<HintPath>..\packages\Microsoft.Owin.Security.3.0.1\lib\net45\Microsoft.Owin.Security.dll</HintPath>
136+
<Private>True</Private>
137+
</Reference>
138+
<Reference Include="Microsoft.Owin.Security.Cookies, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
139+
<HintPath>..\packages\Microsoft.Owin.Security.Cookies.3.0.1\lib\net45\Microsoft.Owin.Security.Cookies.dll</HintPath>
140+
<Private>True</Private>
141+
</Reference>
142+
<Reference Include="Microsoft.Owin.Security.Facebook, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
143+
<HintPath>..\packages\Microsoft.Owin.Security.Facebook.3.0.1\lib\net45\Microsoft.Owin.Security.Facebook.dll</HintPath>
144+
<Private>True</Private>
145+
</Reference>
146+
<Reference Include="Microsoft.Owin.Security.Google, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
147+
<HintPath>..\packages\Microsoft.Owin.Security.Google.3.0.1\lib\net45\Microsoft.Owin.Security.Google.dll</HintPath>
148+
<Private>True</Private>
149+
</Reference>
150+
<Reference Include="Microsoft.Owin.Security.OAuth, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
151+
<HintPath>..\packages\Microsoft.Owin.Security.OAuth.3.0.1\lib\net45\Microsoft.Owin.Security.OAuth.dll</HintPath>
152+
<Private>True</Private>
153+
</Reference>
154+
<Reference Include="Microsoft.Owin.Security.Twitter, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
155+
<HintPath>..\packages\Microsoft.Owin.Security.Twitter.3.0.1\lib\net45\Microsoft.Owin.Security.Twitter.dll</HintPath>
156+
<Private>True</Private>
157+
</Reference>
122158
<Reference Include="Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
123159
<Private>True</Private>
124160
<HintPath>..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll</HintPath>
@@ -139,6 +175,10 @@
139175
<HintPath>..\packages\Nito.AsyncEx.3.0.1\lib\net45\Nito.AsyncEx.Enlightenment.dll</HintPath>
140176
<Private>True</Private>
141177
</Reference>
178+
<Reference Include="Owin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f0ebd12fd5e55cc5, processorArchitecture=MSIL">
179+
<HintPath>..\packages\Owin.1.0\lib\net40\Owin.dll</HintPath>
180+
<Private>True</Private>
181+
</Reference>
142182
<Reference Include="System.Collections.Immutable, Version=1.0.34.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
143183
<SpecificVersion>False</SpecificVersion>
144184
<HintPath>..\packages\Microsoft.Bcl.Immutable.1.0.34\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll</HintPath>
@@ -149,6 +189,7 @@
149189
<SpecificVersion>False</SpecificVersion>
150190
<HintPath>..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll</HintPath>
151191
</Reference>
192+
<Reference Include="System.Net.Http.WebRequest" />
152193
<Reference Include="System.Web.DynamicData" />
153194
<Reference Include="System.Web.Entity" />
154195
<Reference Include="System.Web.ApplicationServices" />
@@ -331,6 +372,13 @@
331372
<Content Include="Scripts\sweetalert\sweet-alert.min.js" />
332373
<Content Include="Scripts\toastr.js" />
333374
<Content Include="Scripts\toastr.min.js" />
375+
<Content Include="Views\Account\Login.css">
376+
<DependentUpon>Login.less</DependentUpon>
377+
</Content>
378+
<Content Include="Views\Account\Login.js" />
379+
<Content Include="Views\Account\Login.min.css">
380+
<DependentUpon>Login.css</DependentUpon>
381+
</Content>
334382
<Content Include="Web.config" />
335383
<Content Include="Views\_ViewStart.cshtml" />
336384
<Content Include="Views\Shared\_Layout.cshtml" />
@@ -341,8 +389,17 @@
341389
<Compile Include="App_Start\AbpProjectNameNavigationProvider.cs" />
342390
<Compile Include="App_Start\AbpProjectNameWebModule.cs" />
343391
<Compile Include="App_Start\RouteConfig.cs" />
392+
<Compile Include="App_Start\Startup.cs" />
344393
<Compile Include="Controllers\AboutController.cs" />
394+
<Compile Include="Controllers\AccountController.cs" />
345395
<Compile Include="Controllers\HomeController.cs" />
396+
<Compile Include="Controllers\Results\ChallengeResult.cs" />
397+
<Compile Include="Models\Layout\UserMenuOrLoginLinkViewModel.cs" />
398+
<Compile Include="Models\Account\LoginFormViewModel.cs" />
399+
<Compile Include="Models\Account\LoginViewModel.cs" />
400+
<Compile Include="Models\Account\RegisterResultViewModel.cs" />
401+
<Compile Include="Models\Account\RegisterViewModel.cs" />
402+
<Compile Include="Models\Account\TenantSelectionViewModel.cs" />
346403
<Compile Include="Models\Layout\LanguageSelectionViewModel.cs" />
347404
<Compile Include="Controllers\LayoutController.cs" />
348405
<Compile Include="Controllers\AbpProjectNameControllerBase.cs" />
@@ -362,6 +419,12 @@
362419
<Content Include="Views\Layout\_TopMenu.cshtml" />
363420
<Content Include="Views\Shared\Error.cshtml" />
364421
<Content Include="Scripts\sweetalert\sweet-alert.scss" />
422+
<Content Include="Views\Account\Login.cshtml" />
423+
<Content Include="Views\Account\Login.less" />
424+
<Content Include="Views\Account\Register.cshtml" />
425+
<Content Include="Views\Account\RegisterResult.cshtml" />
426+
<Content Include="Views\Account\TenantSelection.cshtml" />
427+
<Content Include="Views\Layout\_UserMenuOrLoginLink.cshtml" />
365428
<None Include="Web.Debug.config">
366429
<DependentUpon>Web.config</DependentUpon>
367430
</None>
@@ -402,7 +465,7 @@
402465
<AutoAssignPort>True</AutoAssignPort>
403466
<DevelopmentServerPort>61814</DevelopmentServerPort>
404467
<DevelopmentServerVPath>/</DevelopmentServerVPath>
405-
<IISUrl>http://localhost:61754/</IISUrl>
468+
<IISUrl>http://localhost:61759/</IISUrl>
406469
<NTLMAuthentication>False</NTLMAuthentication>
407470
<UseCustomServer>False</UseCustomServer>
408471
<CustomServerUrl>

src/AbpCompanyName.AbpProjectName.WebMpa/App_Start/AbpProjectNameNavigationProvider.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ public override void SetNavigation(INavigationProviderContext context)
1919
"Home",
2020
new LocalizableString("HomePage", AbpProjectNameConsts.LocalizationSourceName),
2121
url: "/",
22-
icon: "fa fa-home"
22+
icon: "fa fa-home",
23+
requiresAuthentication: true
2324
)
2425
).AddItem(
2526
new MenuItemDefinition(
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
using System;
2+
using System.Configuration;
3+
using AbpCompanyName.AbpProjectName.Api.Controllers;
4+
using AbpCompanyName.AbpProjectName.WebMpa;
5+
using Microsoft.AspNet.Identity;
6+
using Microsoft.Owin;
7+
using Microsoft.Owin.Security.Cookies;
8+
using Microsoft.Owin.Security.Facebook;
9+
using Microsoft.Owin.Security.Google;
10+
using Microsoft.Owin.Security.Twitter;
11+
using Owin;
12+
13+
[assembly: OwinStartup(typeof(Startup))]
14+
15+
namespace AbpCompanyName.AbpProjectName.WebMpa
16+
{
17+
public class Startup
18+
{
19+
public void Configuration(IAppBuilder app)
20+
{
21+
app.UseOAuthBearerAuthentication(AccountController.OAuthBearerOptions);
22+
23+
app.UseCookieAuthentication(new CookieAuthenticationOptions
24+
{
25+
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
26+
LoginPath = new PathString("/Account/Login")
27+
});
28+
29+
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
30+
31+
if (IsTrue("ExternalAuth.Facebook.IsEnabled"))
32+
{
33+
app.UseFacebookAuthentication(CreateFacebookAuthOptions());
34+
}
35+
36+
if (IsTrue("ExternalAuth.Twitter.IsEnabled"))
37+
{
38+
app.UseTwitterAuthentication(CreateTwitterAuthOptions());
39+
}
40+
41+
if (IsTrue("ExternalAuth.Google.IsEnabled"))
42+
{
43+
app.UseGoogleAuthentication(CreateGoogleAuthOptions());
44+
}
45+
}
46+
47+
private static FacebookAuthenticationOptions CreateFacebookAuthOptions()
48+
{
49+
var options = new FacebookAuthenticationOptions
50+
{
51+
AppId = ConfigurationManager.AppSettings["ExternalAuth.Facebook.AppId"],
52+
AppSecret = ConfigurationManager.AppSettings["ExternalAuth.Facebook.AppSecret"]
53+
};
54+
55+
options.Scope.Add("email");
56+
options.Scope.Add("public_profile");
57+
58+
return options;
59+
}
60+
61+
private static TwitterAuthenticationOptions CreateTwitterAuthOptions()
62+
{
63+
return new TwitterAuthenticationOptions
64+
{
65+
ConsumerKey = ConfigurationManager.AppSettings["ExternalAuth.Twitter.ConsumerKey"],
66+
ConsumerSecret = ConfigurationManager.AppSettings["ExternalAuth.Twitter.ConsumerSecret"]
67+
};
68+
}
69+
70+
private static GoogleOAuth2AuthenticationOptions CreateGoogleAuthOptions()
71+
{
72+
return new GoogleOAuth2AuthenticationOptions
73+
{
74+
ClientId = ConfigurationManager.AppSettings["ExternalAuth.Google.ClientId"],
75+
ClientSecret = ConfigurationManager.AppSettings["ExternalAuth.Google.ClientSecret"]
76+
};
77+
}
78+
79+
private static bool IsTrue(string appSettingName)
80+
{
81+
return string.Equals(
82+
ConfigurationManager.AppSettings[appSettingName],
83+
"true",
84+
StringComparison.InvariantCultureIgnoreCase);
85+
}
86+
}
87+
}

src/AbpCompanyName.AbpProjectName.WebMpa/Controllers/AbpProjectNameControllerBase.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
using Abp.Web.Mvc.Controllers;
1+
using Abp.IdentityFramework;
2+
using Abp.UI;
3+
using Abp.Web.Mvc.Controllers;
4+
using Microsoft.AspNet.Identity;
25

36
namespace AbpCompanyName.AbpProjectName.WebMpa.Controllers
47
{
@@ -11,5 +14,18 @@ protected AbpProjectNameControllerBase()
1114
{
1215
LocalizationSourceName = AbpProjectNameConsts.LocalizationSourceName;
1316
}
17+
18+
protected virtual void CheckModelState()
19+
{
20+
if (!ModelState.IsValid)
21+
{
22+
throw new UserFriendlyException(L("FormIsNotValidMessage"));
23+
}
24+
}
25+
26+
protected void CheckErrors(IdentityResult identityResult)
27+
{
28+
identityResult.CheckErrors(LocalizationManager);
29+
}
1430
}
1531
}

0 commit comments

Comments
 (0)