Remove unneeded namespaces, use new startup APIs

This commit is contained in:
Eilon Lipton 2015-10-01 18:00:38 -07:00
parent f3fb2374ac
commit 26aca2b99c
6 changed files with 31 additions and 35 deletions

View File

@ -2,6 +2,7 @@
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNet.Authorization;
using Microsoft.AspNet.Cors.Core; using Microsoft.AspNet.Cors.Core;
using Microsoft.AspNet.Mvc; using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Mvc.Rendering; using Microsoft.AspNet.Mvc.Rendering;
@ -13,7 +14,7 @@ using MusicStore.ViewModels;
namespace MusicStore.Areas.Admin.Controllers namespace MusicStore.Areas.Admin.Controllers
{ {
[Area("Admin")] [Area("Admin")]
[Microsoft.AspNet.Authorization.Authorize("ManageStore")] [Authorize("ManageStore")]
public class StoreManagerController : Controller public class StoreManagerController : Controller
{ {
[FromServices] [FromServices]

View File

@ -1,12 +1,8 @@
using Microsoft.AspNet.Authorization;
using Microsoft.AspNet.Builder; using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Cors.Core;
using Microsoft.AspNet.Diagnostics.Entity; using Microsoft.AspNet.Diagnostics.Entity;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.Identity.EntityFramework; using Microsoft.AspNet.Identity.EntityFramework;
using Microsoft.Data.Entity; using Microsoft.Data.Entity;
using Microsoft.Dnx.Runtime; using Microsoft.Dnx.Runtime;
using Microsoft.Framework.Caching.Memory;
using Microsoft.Framework.Configuration; using Microsoft.Framework.Configuration;
using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.Logging; using Microsoft.Framework.Logging;
@ -63,13 +59,13 @@ namespace MusicStore
// Add Identity services to the services container // Add Identity services to the services container
services.AddIdentity<ApplicationUser, IdentityRole>(options => services.AddIdentity<ApplicationUser, IdentityRole>(options =>
{ {
options.Cookies.ApplicationCookie.AccessDeniedPath = new PathString("/Home/AccessDenied"); options.Cookies.ApplicationCookie.AccessDeniedPath = "/Home/AccessDenied";
}) })
.AddEntityFrameworkStores<MusicStoreContext>() .AddEntityFrameworkStores<MusicStoreContext>()
.AddDefaultTokenProviders(); .AddDefaultTokenProviders();
services.Configure<CorsOptions>(options => services.AddCors(options =>
{ {
options.AddPolicy("CorsPolicy", builder => options.AddPolicy("CorsPolicy", builder =>
{ {
@ -80,11 +76,10 @@ namespace MusicStore
// Add MVC services to the services container // Add MVC services to the services container
services.AddMvc(); services.AddMvc();
//Add InMemoryCache // Add memory cache services
services.AddSingleton<IMemoryCache, MemoryCache>(); services.AddCaching();
// Add session related services. // Add session related services.
services.AddCaching();
services.AddSession(); services.AddSession();
// Add the system clock service // Add the system clock service
@ -94,7 +89,10 @@ namespace MusicStore
services.AddAuthorization(options => services.AddAuthorization(options =>
{ {
options.AddPolicy( options.AddPolicy(
"ManageStore", new AuthorizationPolicyBuilder().RequireClaim("ManageStore", "Allowed").Build()); "ManageStore",
authBuilder => {
authBuilder.RequireClaim("ManageStore", "Allowed");
});
}); });
} }

View File

@ -1,13 +1,10 @@
using System; using System;
using System.Security.Claims; using System.Security.Claims;
using Microsoft.AspNet.Authorization;
using Microsoft.AspNet.Builder; using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Cors.Core;
using Microsoft.AspNet.Diagnostics.Entity; using Microsoft.AspNet.Diagnostics.Entity;
using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Http.Features;
using Microsoft.Data.Entity; using Microsoft.Data.Entity;
using Microsoft.Dnx.Runtime; using Microsoft.Dnx.Runtime;
using Microsoft.Framework.Caching.Memory;
using Microsoft.Framework.Configuration; using Microsoft.Framework.Configuration;
using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.Logging; using Microsoft.Framework.Logging;
@ -61,7 +58,7 @@ namespace MusicStore
.AddDbContext<MusicStoreContext>(options => .AddDbContext<MusicStoreContext>(options =>
options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"])); options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]));
services.Configure<CorsOptions>(options => services.AddCors(options =>
{ {
options.AddPolicy("CorsPolicy", builder => options.AddPolicy("CorsPolicy", builder =>
{ {
@ -72,21 +69,23 @@ namespace MusicStore
// Add MVC services to the services container // Add MVC services to the services container
services.AddMvc(); services.AddMvc();
//Add InMemoryCache // Add memory cache services
services.AddSingleton<IMemoryCache, MemoryCache>(); services.AddCaching();
// Add session related services. // Add session related services.
services.AddCaching();
services.AddSession(); services.AddSession();
// Add the system clock service // Add the system clock service
services.AddSingleton<ISystemClock, SystemClock>(); services.AddSingleton<ISystemClock, SystemClock>();
// Configure Auth // Configure Auth
services.Configure<AuthorizationOptions>(options => services.AddAuthorization(options =>
{ {
options.AddPolicy( options.AddPolicy(
"ManageStore", new AuthorizationPolicyBuilder().RequireClaim("ManageStore", "Allowed").Build()); "ManageStore",
authBuilder => {
authBuilder.RequireClaim("ManageStore", "Allowed");
});
}); });
} }

View File

@ -1,10 +1,8 @@
using Microsoft.AspNet.Authorization;
using Microsoft.AspNet.Builder; using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Diagnostics.Entity; using Microsoft.AspNet.Diagnostics.Entity;
using Microsoft.AspNet.Identity.EntityFramework; using Microsoft.AspNet.Identity.EntityFramework;
using Microsoft.Data.Entity; using Microsoft.Data.Entity;
using Microsoft.Dnx.Runtime; using Microsoft.Dnx.Runtime;
using Microsoft.Framework.Caching.Memory;
using Microsoft.Framework.Configuration; using Microsoft.Framework.Configuration;
using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.Logging; using Microsoft.Framework.Logging;
@ -89,21 +87,23 @@ namespace MusicStore
// Add MVC services to the services container // Add MVC services to the services container
services.AddMvc(); services.AddMvc();
//Add InMemoryCache // Add memory cache services
services.AddSingleton<IMemoryCache, MemoryCache>(); services.AddCaching();
// Add session related services. // Add session related services.
services.AddCaching();
services.AddSession(); services.AddSession();
// Add the system clock service // Add the system clock service
services.AddSingleton<ISystemClock, SystemClock>(); services.AddSingleton<ISystemClock, SystemClock>();
// Configure Auth // Configure Auth
services.Configure<AuthorizationOptions>(options => services.AddAuthorization(options =>
{ {
options.AddPolicy( options.AddPolicy(
"ManageStore", new AuthorizationPolicyBuilder().RequireClaim("ManageStore", "Allowed").Build()); "ManageStore",
authBuilder => {
authBuilder.RequireClaim("ManageStore", "Allowed");
});
}); });
} }

View File

@ -1,11 +1,10 @@
@using Microsoft.AspNet.Http.Authentication; @model ExternalLoginListViewModel
@model ExternalLoginListViewModel
@inject SignInManager<ApplicationUser> SignInManager @inject SignInManager<ApplicationUser> SignInManager
<h4>Use another service to log in.</h4> <h4>Use another service to log in.</h4>
<hr /> <hr />
@{ @{
var loginProviders = SignInManager.GetExternalAuthenticationSchemes(); var loginProviders = SignInManager.GetExternalAuthenticationSchemes();
if (loginProviders.Count() == 0) if (!loginProviders.Any())
{ {
<div> <div>
<p> <p>
@ -19,7 +18,7 @@
<form asp-controller="Account" asp-action="ExternalLogin" asp-route-returnurl="@ViewBag.ReturnUrl" method="post" class="form-horizontal" role="form"> <form asp-controller="Account" asp-action="ExternalLogin" asp-route-returnurl="@ViewBag.ReturnUrl" method="post" class="form-horizontal" role="form">
<div id="socialLoginList"> <div id="socialLoginList">
<p> <p>
@foreach (AuthenticationDescription p in loginProviders) @foreach (var p in loginProviders)
{ {
<button type="submit" class="btn btn-default" id="@p.AuthenticationScheme" name="provider" value="@p.AuthenticationScheme" title="Log in using your @p.DisplayName account">@p.AuthenticationScheme</button> <button type="submit" class="btn btn-default" id="@p.AuthenticationScheme" name="provider" value="@p.AuthenticationScheme" title="Log in using your @p.DisplayName account">@p.AuthenticationScheme</button>
} }

View File

@ -1,5 +1,4 @@
@using Microsoft.AspNet.Http.Authentication; @model ManageLoginsViewModel
@model ManageLoginsViewModel
@{ @{
ViewBag.Title = "Manage your external logins"; ViewBag.Title = "Manage your external logins";
} }
@ -37,14 +36,14 @@
</tbody> </tbody>
</table> </table>
} }
@if (Model.OtherLogins.Count > 0) @if (Model.OtherLogins.Any())
{ {
<h4>Add another service to log in.</h4> <h4>Add another service to log in.</h4>
<hr /> <hr />
<form asp-controller="Manage" asp-action="LinkLogin" method="post" class="form-horizontal" role="form"> <form asp-controller="Manage" asp-action="LinkLogin" method="post" class="form-horizontal" role="form">
<div id="socialLoginList"> <div id="socialLoginList">
<p> <p>
@foreach (AuthenticationDescription p in Model.OtherLogins) @foreach (var p in Model.OtherLogins)
{ {
<button type="submit" class="btn btn-default" id="@p.AuthenticationScheme" name="provider" value="@p.AuthenticationScheme" title="Log in using your @p.DisplayName account">@p.AuthenticationScheme</button> <button type="submit" class="btn btn-default" id="@p.AuthenticationScheme" name="provider" value="@p.AuthenticationScheme" title="Log in using your @p.DisplayName account">@p.AuthenticationScheme</button>
} }