diff --git a/src/web/Jordnaer/Components/Account/Pages/Logout.razor b/src/web/Jordnaer/Components/Account/Pages/Logout.razor deleted file mode 100644 index 1b3631d5..00000000 --- a/src/web/Jordnaer/Components/Account/Pages/Logout.razor +++ /dev/null @@ -1,26 +0,0 @@ -@page "/Account/Logout" - -@attribute [Authorize] - -
- - - - - - - Du er nu logget ud. - - - - -@code { - [SupplyParameterFromQuery] - public string? ReturnUrl { get; set; } -} diff --git a/src/web/Jordnaer/Pages/Account/Logout.cshtml b/src/web/Jordnaer/Pages/Account/Logout.cshtml new file mode 100644 index 00000000..641ec0f7 --- /dev/null +++ b/src/web/Jordnaer/Pages/Account/Logout.cshtml @@ -0,0 +1,27 @@ +@page + +@model Jordnaer.Components.Account.Pages.LogoutModel + +@using Microsoft.AspNetCore.Authorization + +@attribute [Authorize] + +
+ @Html.AntiForgeryToken() + + +
+ +
+ +
+ + diff --git a/src/web/Jordnaer/Pages/Account/Logout.cshtml.cs b/src/web/Jordnaer/Pages/Account/Logout.cshtml.cs new file mode 100644 index 00000000..81089915 --- /dev/null +++ b/src/web/Jordnaer/Pages/Account/Logout.cshtml.cs @@ -0,0 +1,25 @@ +using Jordnaer.Database; +using Jordnaer.Features.Metrics; +using Microsoft.AspNetCore.Authentication; +using Microsoft.AspNetCore.Identity; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; + +namespace Jordnaer.Components.Account.Pages; + +public class LogoutModel(SignInManager signInManager) : PageModel +{ + [BindProperty(SupportsGet = true)] + public string? ReturnUrl { get; set; } + public void OnGet(){} + + public async Task OnPostAsync() + { + await HttpContext.SignOutAsync(); + await signInManager.SignOutAsync(); + + JordnaerMetrics.LogoutCounter.Add(1); + + return LocalRedirect(ReturnUrl ?? "~/"); + } +} \ No newline at end of file diff --git a/src/web/Jordnaer/Program.cs b/src/web/Jordnaer/Program.cs index a3b56507..8993442a 100644 --- a/src/web/Jordnaer/Program.cs +++ b/src/web/Jordnaer/Program.cs @@ -101,6 +101,8 @@ .AddHttpContextAccessor() .AddDefaultSitemapServices(); +builder.Services.AddRazorPages(); + var app = builder.Build(); app.UseSecurityHeaders(policies => policies.AddFrameOptionsDeny() @@ -134,6 +136,8 @@ app.UseAuthorization(); app.UseAntiforgery(); +app.MapRazorPages(); + app.MapRazorComponents() .AddInteractiveServerRenderMode();