Skip to content

Commit

Permalink
Added logout page and updated readme to dotnet 8
Browse files Browse the repository at this point in the history
  • Loading branch information
jrmccannon committed Dec 21, 2023
1 parent 8d9b6af commit bf6d30e
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public IActionResult OnGet()
{
return LocalRedirect("/");
}
return Page();
return Page();
}

public async Task OnPostAsync(LoginForm form, CancellationToken cancellationToken)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@page
@model Passwordless.AspNetIdentity.Example.Pages.Account.Logout

@{
ViewData["Title"] = "Logout";
}
<h1>@ViewData["Title"]</h1>

You have successfully logged out.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.Extensions.Logging;

namespace Passwordless.AspNetIdentity.Example.Pages.Account;

public class Logout : PageModel
{
private readonly SignInManager<IdentityUser> _userSignInManager;
private readonly ILogger<Logout> _logger;

public Logout(SignInManager<IdentityUser> userSignInManager, ILogger<Logout> logger)
{
_userSignInManager = userSignInManager;
_logger = logger;
}

public async Task<IActionResult> OnGet()
{
await _userSignInManager.SignOutAsync();
_logger.LogInformation("User has signed out.");
return Page();
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<!DOCTYPE html>
@{
var loggedIn = User.Identity?.IsAuthenticated ?? false;
}

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
Expand Down Expand Up @@ -31,6 +35,12 @@
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-page="/Authorized/HelloWorld">Hello World (Protected Page)</a>
</li>
@if (loggedIn)
{
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-page="/Account/Logout">Logout</a>
</li>
}
</ul>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion examples/Passwordless.AspNetIdentity.Example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Requirements

* .NET 7 SDK
* .NET 8 SDK
* A free account obtained from [passwordless.dev](https://admin.passwordless.dev/signup).
* [A Passwordless.dev public and private API key pair](https://docs.passwordless.dev/guide/get-started.html#create-an-application).
* An IDE such as Visual Studio or JetBrains Rider.
Expand Down

0 comments on commit bf6d30e

Please sign in to comment.