Skip to content

Commit

Permalink
Merge pull request #5 from janaks09/netcore20
Browse files Browse the repository at this point in the history
Upgraded to .Net Core 2.0
  • Loading branch information
janaks09 committed Sep 1, 2017
2 parents 8dd4c4f + 5662dcc commit 5005559
Show file tree
Hide file tree
Showing 18 changed files with 58 additions and 92 deletions.
2 changes: 1 addition & 1 deletion NetCoreSaaS.Core/NetCoreSaaS.Core.csproj
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard1.6</TargetFramework>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>

</Project>
2 changes: 1 addition & 1 deletion NetCoreSaaS.Data/Entities/Tenant/TenantUser.cs
@@ -1,6 +1,6 @@
using System;
using System.ComponentModel.DataAnnotations;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.AspNetCore.Identity;

namespace NetCoreSaaS.Data.Entities.Tenant
{
Expand Down
10 changes: 5 additions & 5 deletions NetCoreSaaS.Data/NetCoreSaaS.Data.csproj
@@ -1,14 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard1.6</TargetFramework>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="1.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="1.1.1" PrivateAssets="All" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="1.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.Design" Version="1.1.1" PrivateAssets="All" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="2.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.0.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.Design" Version="2.0.0-preview1-final" PrivateAssets="All" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion NetCoreSaaS.Model/NetCoreSaaS.Model.csproj
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard1.6</TargetFramework>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>

</Project>
2 changes: 1 addition & 1 deletion NetCoreSaaS.Service/NetCoreSaaS.Service.csproj
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard1.6</TargetFramework>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>

</Project>
9 changes: 2 additions & 7 deletions NetCoreSaaS.WebHost/Controllers/AccountController.cs
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
Expand All @@ -8,13 +7,12 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using NetCoreSaaS.Core.ENums;
using NetCoreSaaS.Data.Entities.Catalog;
using NetCoreSaaS.Data.Entities.Tenant;
using NetCoreSaaS.WebHost.Models;
using NetCoreSaaS.WebHost.Models.AccountViewModels;
using NetCoreSaaS.WebHost.Services;
using Microsoft.AspNetCore.Authentication;

namespace NetCoreSaaS.WebHost.Controllers
{
Expand All @@ -27,20 +25,17 @@ public class AccountController : Controller
private readonly Tenant _currentTenant;
private readonly ISmsSender _smsSender;
private readonly ILogger _logger;
private readonly string _externalCookieScheme;

public AccountController(
UserManager<TenantUser> userManager,
SignInManager<TenantUser> signInManager,
IOptions<IdentityCookieOptions> identityCookieOptions,
IEmailSender emailSender,
Tenant currentTenant,
ISmsSender smsSender,
ILoggerFactory loggerFactory)
{
_userManager = userManager;
_signInManager = signInManager;
_externalCookieScheme = identityCookieOptions.Value.ExternalCookieAuthenticationScheme;
_emailSender = emailSender;
_currentTenant = currentTenant;
_smsSender = smsSender;
Expand All @@ -54,7 +49,7 @@ public class AccountController : Controller
public async Task<IActionResult> Login(string returnUrl = null)
{
// Clear the existing external cookie to ensure a clean login process
await HttpContext.Authentication.SignOutAsync(_externalCookieScheme);
await HttpContext.SignOutAsync(IdentityConstants.ExternalScheme);

ViewData["ReturnUrl"] = returnUrl;
return View();
Expand Down
10 changes: 4 additions & 6 deletions NetCoreSaaS.WebHost/Controllers/ManageController.cs
Expand Up @@ -11,6 +11,7 @@
using NetCoreSaaS.WebHost.Models;
using NetCoreSaaS.WebHost.Models.ManageViewModels;
using NetCoreSaaS.WebHost.Services;
using Microsoft.AspNetCore.Authentication;

namespace NetCoreSaaS.WebHost.Controllers
{
Expand All @@ -19,22 +20,19 @@ public class ManageController : Controller
{
private readonly UserManager<TenantUser> _userManager;
private readonly SignInManager<TenantUser> _signInManager;
private readonly string _externalCookieScheme;
private readonly IEmailSender _emailSender;
private readonly ISmsSender _smsSender;
private readonly ILogger _logger;

public ManageController(
UserManager<TenantUser> userManager,
SignInManager<TenantUser> signInManager,
IOptions<IdentityCookieOptions> identityCookieOptions,
IEmailSender emailSender,
ISmsSender smsSender,
ILoggerFactory loggerFactory)
{
_userManager = userManager;
_signInManager = signInManager;
_externalCookieScheme = identityCookieOptions.Value.ExternalCookieAuthenticationScheme;
_emailSender = emailSender;
_smsSender = smsSender;
_logger = loggerFactory.CreateLogger<ManageController>();
Expand Down Expand Up @@ -292,7 +290,7 @@ public async Task<IActionResult> ManageLogins(ManageMessageId? message = null)
return View("Error");
}
var userLogins = await _userManager.GetLoginsAsync(user);
var otherLogins = _signInManager.GetExternalAuthenticationSchemes().Where(auth => userLogins.All(ul => auth.AuthenticationScheme != ul.LoginProvider)).ToList();
var otherLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).Where(auth => userLogins.All(ul => auth.Name != ul.LoginProvider)).ToList();
ViewData["ShowRemoveButton"] = user.PasswordHash != null || userLogins.Count > 1;
return View(new ManageLoginsViewModel
{
Expand All @@ -308,7 +306,7 @@ public async Task<IActionResult> ManageLogins(ManageMessageId? message = null)
public async Task<IActionResult> LinkLogin(string provider)
{
// Clear the existing external cookie to ensure a clean login process
await HttpContext.Authentication.SignOutAsync(_externalCookieScheme);
await HttpContext.SignOutAsync(IdentityConstants.ExternalScheme);

// Request a redirect to the external login provider to link a login for the current user
var redirectUrl = Url.Action(nameof(LinkLoginCallback), "Manage");
Expand Down Expand Up @@ -337,7 +335,7 @@ public async Task<ActionResult> LinkLoginCallback()
{
message = ManageMessageId.AddLoginSuccess;
// Clear the existing external cookie to ensure a clean login process
await HttpContext.Authentication.SignOutAsync(_externalCookieScheme);
await HttpContext.SignOutAsync(IdentityConstants.ExternalScheme);
}
return RedirectToAction(nameof(ManageLogins), new { Message = message });
}
Expand Down
Expand Up @@ -8,7 +8,7 @@ namespace NetCoreSaaS.WebHost.Infrastructures.Extensions
public static class DbContextExtension
{

public static IServiceCollection AddSystemDataContext(this IServiceCollection services, IConfigurationRoot configuration, string migrationAssembly)
public static IServiceCollection AddSystemDataContext(this IServiceCollection services, IConfiguration configuration, string migrationAssembly)
{
services.AddDbContext<SystemDbContext>(builder =>
builder.UseSqlServer(configuration.GetConnectionString("SystemConnection"),
Expand All @@ -17,7 +17,7 @@ public static IServiceCollection AddSystemDataContext(this IServiceCollection se
}


public static IServiceCollection AddCustomerDataContext(this IServiceCollection services, IConfigurationRoot configuration, string migrationAssembly)
public static IServiceCollection AddCustomerDataContext(this IServiceCollection services, IConfiguration configuration, string migrationAssembly)
{
services.AddDbContext<CatalogDbContext>(builder =>
builder.UseSqlServer(configuration.GetConnectionString("CatalogConnection"),
Expand All @@ -26,7 +26,7 @@ public static IServiceCollection AddCustomerDataContext(this IServiceCollection
}


public static IServiceCollection AddTenantDbContext(this IServiceCollection services, IConfigurationRoot configuration, string migrationAssembly)
public static IServiceCollection AddTenantDbContext(this IServiceCollection services, IConfiguration configuration, string migrationAssembly)
{

services.AddDbContext<TenantDbContext>();
Expand Down
@@ -1,4 +1,4 @@
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using NetCoreSaaS.Data.Contexts;
Expand All @@ -21,7 +21,7 @@ public static IServiceCollection AddIdentityService(this IServiceCollection serv
}


public static IServiceCollection AddContexts(this IServiceCollection services, IConfigurationRoot configuration, string migrationsAssembly)
public static IServiceCollection AddContexts(this IServiceCollection services, IConfiguration configuration, string migrationsAssembly)
{

services.AddSystemDataContext(configuration, migrationsAssembly)
Expand Down
Expand Up @@ -4,13 +4,14 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http.Authentication;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Authentication;

namespace NetCoreSaaS.WebHost.Models.ManageViewModels
{
public class ManageLoginsViewModel
{
public IList<UserLoginInfo> CurrentLogins { get; set; }

public IList<AuthenticationDescription> OtherLogins { get; set; }
public IList<AuthenticationScheme> OtherLogins { get; set; }
}
}
28 changes: 8 additions & 20 deletions NetCoreSaaS.WebHost/NetCoreSaaS.WebHost.csproj
@@ -1,38 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>

<PropertyGroup>
<PackageTargetFallback>$(PackageTargetFallback);portable-net45+win8+wp8+wpa81;</PackageTargetFallback>
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback>
</PropertyGroup>

<PropertyGroup>
<UserSecretsId>aspnet-NetCoreSaaS.WebHost-4d87baca-42fd-437d-84a4-10e94130fc5f</UserSecretsId>
<AssemblyName>NetCoreSaaS.WebHost</AssemblyName>
<RootNamespace>NetCoreSaaS.WebHost</RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Cookies" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.3" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="1.1.2" PrivateAssets="All" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="1.1.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.Design" Version="1.1.2" PrivateAssets="All" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="1.1.1" PrivateAssets="All" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="1.1.2" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.2" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="1.1.1" PrivateAssets="All" />
<PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
<PackageReference Include="SaasKit.Multitenancy" Version="1.1.4" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.0.1" />
<DotNetCliToolReference Include="Microsoft.Extensions.SecretManager.Tools" Version="1.0.1" />
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="1.0.1" />
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />
<DotNetCliToolReference Include="Microsoft.Extensions.SecretManager.Tools" Version="2.0.0" />
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\NetCoreSaaS.Core\NetCoreSaaS.Core.csproj" />
Expand Down
20 changes: 10 additions & 10 deletions NetCoreSaaS.WebHost/Program.cs
@@ -1,21 +1,21 @@
using System.IO;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Hosting;

namespace NetCoreSaaS.WebHost
{
public class Program
{
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseKestrel()
.UseUrls("http://*.localhost:6001")
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.Build();
BuildWebHost(args).Run();
}

host.Run();
public static IWebHost BuildWebHost(string[] args)
{
return Microsoft.AspNetCore.WebHost.CreateDefaultBuilder(args)
.UseUrls("http://*.localhost:6001")
.UseStartup<Startup>()
.Build();
}
}

}
5 changes: 1 addition & 4 deletions NetCoreSaaS.WebHost/Services/IEmailSender.cs
@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Threading.Tasks;

namespace NetCoreSaaS.WebHost.Services
{
Expand Down
5 changes: 1 addition & 4 deletions NetCoreSaaS.WebHost/Services/ISmsSender.cs
@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Threading.Tasks;

namespace NetCoreSaaS.WebHost.Services
{
Expand Down
5 changes: 1 addition & 4 deletions NetCoreSaaS.WebHost/Services/MessageServices.cs
@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Threading.Tasks;

namespace NetCoreSaaS.WebHost.Services
{
Expand Down
18 changes: 4 additions & 14 deletions NetCoreSaaS.WebHost/Startup.cs
@@ -1,35 +1,25 @@
using System.Reflection;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using NetCoreSaaS.Data.Contexts;
using NetCoreSaaS.Data.Entities.Catalog;
using NetCoreSaaS.Data.Entities.Tenant;
using NetCoreSaaS.WebHost.Infrastructures.Extensions;
using NetCoreSaaS.WebHost.Infrastructures.Helpers.DbHelper;
using NetCoreSaaS.WebHost.Infrastructures.TenantResolver;
using NetCoreSaaS.WebHost.Models;
using NetCoreSaaS.WebHost.Services;

namespace NetCoreSaaS.WebHost
{
public class Startup
{
public Startup(IHostingEnvironment env)
public Startup(IConfiguration configuration)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);

builder.AddEnvironmentVariables();
Configuration = builder.Build();
Configuration = configuration;
}

public IConfigurationRoot Configuration { get; }
public IConfiguration Configuration { get; }

public void ConfigureServices(IServiceCollection services)
{
Expand Down Expand Up @@ -66,7 +56,7 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerF
app.UseStaticFiles();

app.UseMultitenancy<Tenant>();
app.UseIdentity();
app.UseAuthentication();
DbInitailizer.InitializeDatabase(app);

app.UseMvc(routes =>
Expand Down
4 changes: 2 additions & 2 deletions NetCoreSaaS.WebHost/Views/Account/Login.cshtml
Expand Up @@ -56,7 +56,7 @@
<h4>Use another service to log in.</h4>
<hr />
@{
var loginProviders = SignInManager.GetExternalAuthenticationSchemes().ToList();
var loginProviders = (await SignInManager.GetExternalAuthenticationSchemesAsync()).ToList();
if (loginProviders.Count == 0)
{
<div>
Expand All @@ -73,7 +73,7 @@
<p>
@foreach (var provider in loginProviders)
{
<button type="submit" class="btn btn-default" name="provider" value="@provider.AuthenticationScheme" title="Log in using your @provider.DisplayName account">@provider.AuthenticationScheme</button>
<button type="submit" class="btn btn-default" name="provider" value="@provider.Name" title="Log in using your @provider.DisplayName account">@provider.Name</button>
}
</p>
</div>
Expand Down

0 comments on commit 5005559

Please sign in to comment.