Browse Source

Merge pull request #267 from dotnet-architecture/cleanup-legacy-identity

Cleanup legacy identity
main
Eric Fleming 7 years ago
committed by GitHub
parent
commit
86f65e3541
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      src/Web/Areas/Identity/Pages/Account/Logout.cshtml
  2. 41
      src/Web/Areas/Identity/Pages/Account/Logout.cshtml.cs
  3. 6
      src/Web/Startup.cs
  4. 2
      src/Web/Views/Shared/_LoginPartial.cshtml
  5. 3
      src/Web/Web.csproj

10
src/Web/Areas/Identity/Pages/Account/Logout.cshtml

@ -0,0 +1,10 @@
@page
@model LogoutModel
@{
ViewData["Title"] = "Log out";
}
<header>
<h1>@ViewData["Title"]</h1>
<p>You have successfully logged out of the application.</p>
</header>

41
src/Web/Areas/Identity/Pages/Account/Logout.cshtml.cs

@ -0,0 +1,41 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.eShopWeb.Infrastructure.Identity;
using Microsoft.Extensions.Logging;
namespace Microsoft.eShopWeb.Web.Areas.Identity.Pages.Account
{
[AllowAnonymous]
public class LogoutModel : PageModel
{
private readonly SignInManager<ApplicationUser> _signInManager;
private readonly ILogger<LogoutModel> _logger;
public LogoutModel(SignInManager<ApplicationUser> signInManager, ILogger<LogoutModel> logger)
{
_signInManager = signInManager;
_logger = logger;
}
public void OnGet()
{
}
public async Task<IActionResult> OnPost(string returnUrl = null)
{
await _signInManager.SignOutAsync();
_logger.LogInformation("User logged out.");
if (returnUrl != null)
{
return LocalRedirect(returnUrl);
}
else
{
return RedirectToPage("/Index");
}
}
}
}

6
src/Web/Startup.cs

@ -174,7 +174,7 @@ namespace Microsoft.eShopWeb.Web
options.Cookie.HttpOnly = true;
options.ExpireTimeSpan = TimeSpan.FromHours(1);
options.LoginPath = "/Account/Login";
options.LogoutPath = "/Account/Signout";
options.LogoutPath = "/Account/Logout";
options.Cookie = new CookieBuilder
{
IsEssential = true // required for auth to work without explicit user consent; adjust to suit your privacy policy
@ -236,10 +236,6 @@ namespace Microsoft.eShopWeb.Web
app.UseMvc(routes =>
{
routes.MapRoute(
name: "identity",
template: "Identity/{controller=Account}/{action=Register}/{id?}");
routes.MapRoute(
name: "default",
template: "{controller:slugify=Home}/{action:slugify=Index}/{id?}");

2
src/Web/Views/Shared/_LoginPartial.cshtml

@ -2,7 +2,7 @@
{
<section class="col-lg-4 col-md-5 col-xs-12">
<div class="esh-identity">
<form asp-area="" asp-controller="Account" asp-action="SignOut" method="post" id="logoutForm" class="navbar-right">
<form asp-area="Identity" asp-page="/Account/Logout" method="post" id="logoutForm" class="navbar-right">
<section class="esh-identity-section">
<div class="esh-identity-name">@Context.User.Identity.Name</div>
<img class="esh-identity-image" src="~/images/arrow-down.png">

3
src/Web/Web.csproj

@ -18,8 +18,9 @@
<PackageReference Include="BuildBundlerMinifier" Version="2.9.406" Condition="'$(Configuration)'=='Release'" PrivateAssets="All" />
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.CodeAnalysis" Version="3.1.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.3" />
<PackageReference Include="Microsoft.Web.LibraryManager.Build" Version="1.0.172" />
<PackageReference Include="Microsoft.Web.LibraryManager.Build" Version="2.0.48" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="4.0.1" />
</ItemGroup>
<ItemGroup>

Loading…
Cancel
Save