Skip to content

Commit

Permalink
Adding scaffolding for Logout page
Browse files Browse the repository at this point in the history
- Removing Identity route from startup
  • Loading branch information
efleming18 committed Jun 21, 2019
1 parent ba8bdfa commit d5446de
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 7 deletions.
10 changes: 10 additions & 0 deletions src/Web/Areas/Identity/Pages/Account/Logout.cshtml
Original file line number Diff line number Diff line change
@@ -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 changes: 41 additions & 0 deletions src/Web/Areas/Identity/Pages/Account/Logout.cshtml.cs
Original file line number Diff line number Diff line change
@@ -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 Page();
}
}
}
}
6 changes: 1 addition & 5 deletions src/Web/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ private static void ConfigureCookieSettings(IServiceCollection services)
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
Expand Down Expand Up @@ -236,10 +236,6 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env)

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?}");
Expand Down
2 changes: 1 addition & 1 deletion src/Web/Views/Shared/_LoginPartial.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down
3 changes: 2 additions & 1 deletion src/Web/Web.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit d5446de

Please sign in to comment.