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

View File

@ -1,12 +1,8 @@
using Microsoft.AspNet.Authorization;
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Cors.Core;
using Microsoft.AspNet.Diagnostics.Entity;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.Identity.EntityFramework;
using Microsoft.Data.Entity;
using Microsoft.Dnx.Runtime;
using Microsoft.Framework.Caching.Memory;
using Microsoft.Framework.Configuration;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.Logging;
@ -63,13 +59,13 @@ namespace MusicStore
// Add Identity services to the services container
services.AddIdentity<ApplicationUser, IdentityRole>(options =>
{
options.Cookies.ApplicationCookie.AccessDeniedPath = new PathString("/Home/AccessDenied");
options.Cookies.ApplicationCookie.AccessDeniedPath = "/Home/AccessDenied";
})
.AddEntityFrameworkStores<MusicStoreContext>()
.AddDefaultTokenProviders();
services.Configure<CorsOptions>(options =>
services.AddCors(options =>
{
options.AddPolicy("CorsPolicy", builder =>
{
@ -80,11 +76,10 @@ namespace MusicStore
// Add MVC services to the services container
services.AddMvc();
//Add InMemoryCache
services.AddSingleton<IMemoryCache, MemoryCache>();
// Add memory cache services
services.AddCaching();
// Add session related services.
services.AddCaching();
services.AddSession();
// Add the system clock service
@ -94,7 +89,10 @@ namespace MusicStore
services.AddAuthorization(options =>
{
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.Security.Claims;
using Microsoft.AspNet.Authorization;
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Cors.Core;
using Microsoft.AspNet.Diagnostics.Entity;
using Microsoft.AspNet.Http.Features;
using Microsoft.Data.Entity;
using Microsoft.Dnx.Runtime;
using Microsoft.Framework.Caching.Memory;
using Microsoft.Framework.Configuration;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.Logging;
@ -61,7 +58,7 @@ namespace MusicStore
.AddDbContext<MusicStoreContext>(options =>
options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]));
services.Configure<CorsOptions>(options =>
services.AddCors(options =>
{
options.AddPolicy("CorsPolicy", builder =>
{
@ -72,21 +69,23 @@ namespace MusicStore
// Add MVC services to the services container
services.AddMvc();
//Add InMemoryCache
services.AddSingleton<IMemoryCache, MemoryCache>();
// Add memory cache services
services.AddCaching();
// Add session related services.
services.AddCaching();
services.AddSession();
// Add the system clock service
services.AddSingleton<ISystemClock, SystemClock>();
// Configure Auth
services.Configure<AuthorizationOptions>(options =>
services.AddAuthorization(options =>
{
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.Diagnostics.Entity;
using Microsoft.AspNet.Identity.EntityFramework;
using Microsoft.Data.Entity;
using Microsoft.Dnx.Runtime;
using Microsoft.Framework.Caching.Memory;
using Microsoft.Framework.Configuration;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.Logging;
@ -89,21 +87,23 @@ namespace MusicStore
// Add MVC services to the services container
services.AddMvc();
//Add InMemoryCache
services.AddSingleton<IMemoryCache, MemoryCache>();
// Add memory cache services
services.AddCaching();
// Add session related services.
services.AddCaching();
services.AddSession();
// Add the system clock service
services.AddSingleton<ISystemClock, SystemClock>();
// Configure Auth
services.Configure<AuthorizationOptions>(options =>
services.AddAuthorization(options =>
{
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
<h4>Use another service to log in.</h4>
<hr />
@{
var loginProviders = SignInManager.GetExternalAuthenticationSchemes();
if (loginProviders.Count() == 0)
if (!loginProviders.Any())
{
<div>
<p>
@ -19,7 +18,7 @@
<form asp-controller="Account" asp-action="ExternalLogin" asp-route-returnurl="@ViewBag.ReturnUrl" method="post" class="form-horizontal" role="form">
<div id="socialLoginList">
<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>
}

View File

@ -1,5 +1,4 @@
@using Microsoft.AspNet.Http.Authentication;
@model ManageLoginsViewModel
@model ManageLoginsViewModel
@{
ViewBag.Title = "Manage your external logins";
}
@ -37,14 +36,14 @@
</tbody>
</table>
}
@if (Model.OtherLogins.Count > 0)
@if (Model.OtherLogins.Any())
{
<h4>Add another service to log in.</h4>
<hr />
<form asp-controller="Manage" asp-action="LinkLogin" method="post" class="form-horizontal" role="form">
<div id="socialLoginList">
<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>
}