Skip to content

Commit

Permalink
Add Sign out link to Elevate journey
Browse files Browse the repository at this point in the history
  • Loading branch information
gunndabad committed Oct 9, 2023
1 parent 963d932 commit 38e6c86
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -405,13 +405,17 @@ public async Task<IActionResult> Exchange()
[ActionName(nameof(SignOut)), HttpPost("~/connect/signout")]
public async Task<IActionResult> SignOutPost()
{
var redirectUri = HttpContext.TryGetAuthenticationState(out var authenticationState) ?
authenticationState.PostSignInUrl :
"/";

await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);

return SignOut(
authenticationSchemes: OpenIddictServerAspNetCoreDefaults.AuthenticationScheme,
properties: new AuthenticationProperties
{
RedirectUri = "/"
RedirectUri = redirectUri
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
@{
ViewBag.ServiceUrl = LinkGenerator.Account(Context.GetClientRedirectInfo());
Layout = "/Views/Shared/_Layout.cshtml";

var signOutUrl = Context.GetClientRedirectInfo()?.SignOutUri ?? LinkGenerator.SignOut();
}

@section HeaderNav {
<nav aria-label="Menu" class="govuk-header__navigation">
<button type="button" class="govuk-header__menu-button govuk-js-header-toggle" aria-controls="navigation" aria-label="Show or hide menu" hidden>Menu</button>
<ul id="navigation" class="govuk-header__navigation-list">
<li class="govuk-header__navigation-item @(Context.Request.Path.StartsWithSegments("/sign-out") ? "govuk-header__navigation-item--active" : "")">
<a class="govuk-header__link" href="@signOutUrl">Sign out</a>
</li>
</ul>
</nav>
}

@section BeforeContent {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
}
}

var signOutLink = LinkGenerator.SignOut();

async Task RenderContent()
{
<govuk-panel class="app-panel--interruption">
Expand Down Expand Up @@ -135,17 +133,6 @@
}
}

@section HeaderNav {
<nav aria-label="Menu" class="govuk-header__navigation ">
<button type="button" class="govuk-header__menu-button govuk-js-header-toggle" aria-controls="navigation" aria-label="Show or hide menu" hidden>Menu</button>
<ul id="navigation" class="govuk-header__navigation-list">
<li class="govuk-header__navigation-item @(ViewContext.HttpContext.Request.Path == signOutLink ? "govuk-header__navigation-item--active" : "")">
<a class="govuk-header__link" href="@signOutLink">Sign out</a>
</li>
</ul>
</nav>
}

@if (Model.CanAccessService)
{
<form action="@action" method="@method" asp-antiforgery="false">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@using TeacherIdentity.AuthServer.Journeys;
@using Microsoft.AspNetCore.Authentication;
@inject TeacherIdentity.AuthServer.Oidc.ICurrentClientProvider CurrentClientProvider
@inject ClientScopedViewHelper ClientScopedViewHelper
@inject SignInJourneyProvider SignInJourneyProvider
Expand All @@ -13,6 +14,9 @@

var serviceName = ViewBag.ServiceName ?? "DfE Identity account";
var serviceUrl = ViewBag.ServiceUrl ?? "/";

var isSignedIn = (await Context.AuthenticateAsync(Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationDefaults.AuthenticationScheme)).Succeeded;
var signOutLink = Context.GetClientRedirectInfo()?.SignOutUri ?? LinkGenerator.SignOut();
}

@section Head {
Expand Down Expand Up @@ -45,7 +49,25 @@
<a href="@serviceUrl" class="govuk-header__link govuk-header__link--service-name">
@serviceName
</a>
@RenderSection("HeaderNav", required: false)

@if (IsSectionDefined("HeaderNav"))
{
@RenderSection("HeaderNav")
}
else
{
@if (isSignedIn)
{
<nav aria-label="Menu" class="govuk-header__navigation">
<button type="button" class="govuk-header__menu-button govuk-js-header-toggle" aria-controls="navigation" aria-label="Show or hide menu" hidden>Menu</button>
<ul id="navigation" class="govuk-header__navigation-list">
<li class="govuk-header__navigation-item @(Url.IsLocalUrl(signOutLink) && ViewContext.HttpContext.Request.Path == signOutLink ? "govuk-header__navigation-item--active" : "")">
<a class="govuk-header__link" href="@signOutLink">Sign out</a>
</li>
</ul>
</nav>
}
}
</div>
</div>
</header>
Expand All @@ -55,13 +77,13 @@
@RenderSection("BeforeContent", required: false)
}

@if (TempData.TryGetFlashSuccess(out (string heading, string? message)? flashSuccess))
@if (TempData.TryGetFlashSuccess(out (string Heading, string? Message)? flashSuccess))
{
<govuk-notification-banner type="Success">
<p class="govuk-notification-banner__heading">@flashSuccess.Value.heading</p>
@if (flashSuccess.Value.message is not null)
<p class="govuk-notification-banner__heading">@flashSuccess.Value.Heading</p>
@if (flashSuccess.Value.Message is not null)
{
@foreach (var line in flashSuccess.Value.message.Split(Environment.NewLine))
@foreach (var line in flashSuccess.Value.Message.Split(Environment.NewLine))
{
<span>@line</span><br/>
}
Expand Down

0 comments on commit 38e6c86

Please sign in to comment.