Adding scaffolding for Logout page
- Removing Identity route from startup
This commit is contained in:
10
src/Web/Areas/Identity/Pages/Account/Logout.cshtml
Normal file
10
src/Web/Areas/Identity/Pages/Account/Logout.cshtml
Normal file
@@ -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
Normal file
41
src/Web/Areas/Identity/Pages/Account/Logout.cshtml.cs
Normal file
@@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -174,7 +174,7 @@ namespace Microsoft.eShopWeb.Web
|
|||||||
options.Cookie.HttpOnly = true;
|
options.Cookie.HttpOnly = true;
|
||||||
options.ExpireTimeSpan = TimeSpan.FromHours(1);
|
options.ExpireTimeSpan = TimeSpan.FromHours(1);
|
||||||
options.LoginPath = "/Account/Login";
|
options.LoginPath = "/Account/Login";
|
||||||
options.LogoutPath = "/Account/Signout";
|
options.LogoutPath = "/Account/Logout";
|
||||||
options.Cookie = new CookieBuilder
|
options.Cookie = new CookieBuilder
|
||||||
{
|
{
|
||||||
IsEssential = true // required for auth to work without explicit user consent; adjust to suit your privacy policy
|
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 =>
|
app.UseMvc(routes =>
|
||||||
{
|
{
|
||||||
routes.MapRoute(
|
|
||||||
name: "identity",
|
|
||||||
template: "Identity/{controller=Account}/{action=Register}/{id?}");
|
|
||||||
|
|
||||||
routes.MapRoute(
|
routes.MapRoute(
|
||||||
name: "default",
|
name: "default",
|
||||||
template: "{controller:slugify=Home}/{action:slugify=Index}/{id?}");
|
template: "{controller:slugify=Home}/{action:slugify=Index}/{id?}");
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
{
|
{
|
||||||
<section class="col-lg-4 col-md-5 col-xs-12">
|
<section class="col-lg-4 col-md-5 col-xs-12">
|
||||||
<div class="esh-identity">
|
<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">
|
<section class="esh-identity-section">
|
||||||
<div class="esh-identity-name">@Context.User.Identity.Name</div>
|
<div class="esh-identity-name">@Context.User.Identity.Name</div>
|
||||||
<img class="esh-identity-image" src="~/images/arrow-down.png">
|
<img class="esh-identity-image" src="~/images/arrow-down.png">
|
||||||
|
|||||||
@@ -18,8 +18,9 @@
|
|||||||
<PackageReference Include="BuildBundlerMinifier" Version="2.9.406" Condition="'$(Configuration)'=='Release'" PrivateAssets="All" />
|
<PackageReference Include="BuildBundlerMinifier" Version="2.9.406" Condition="'$(Configuration)'=='Release'" PrivateAssets="All" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.App" />
|
<PackageReference Include="Microsoft.AspNetCore.App" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
|
<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.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" />
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="4.0.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
Reference in New Issue
Block a user