Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Sign out link to Elevate journey #734

Merged
merged 1 commit into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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