Skip to content

Commit e368fc9

Browse files
committed
TD-3731: Invalidated Current User Session on Password Change.
1 parent 359dfa6 commit e368fc9

File tree

3 files changed

+58
-10
lines changed

3 files changed

+58
-10
lines changed

LearningHub.Nhs.WebUI/Controllers/HomeController.cs

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -335,14 +335,19 @@ public IActionResult NhsSites()
335335
}
336336

337337
/// <summary>
338-
/// The Logout.
339-
/// This is directly referenced in the LoginWizardFilter to allow
340-
/// logouts to bypass LoginWizard redirects.
341-
/// If the name is changed, the LoginWizardFilter MUST be updated.
338+
/// The ChangePasswordAcknowledgement.
342339
/// </summary>
343340
/// <returns>The <see cref="IActionResult"/>.</returns>
344-
[AllowAnonymous]
345-
public IActionResult Logout()
341+
public IActionResult ChangePasswordAcknowledgement()
342+
{
343+
return this.View();
344+
}
345+
346+
/// <summary>
347+
/// StatusUpdate.
348+
/// </summary>
349+
/// <returns>Actionresult.</returns>
350+
public IActionResult UserLogout()
346351
{
347352
if (!(this.User?.Identity.IsAuthenticated ?? false))
348353
{
@@ -352,6 +357,20 @@ public IActionResult Logout()
352357
return new SignOutResult(new[] { CookieAuthenticationDefaults.AuthenticationScheme, "oidc" });
353358
}
354359

360+
/// <summary>
361+
/// The Logout.
362+
/// This is directly referenced in the LoginWizardFilter to allow
363+
/// logouts to bypass LoginWizard redirects.
364+
/// If the name is changed, the LoginWizardFilter MUST be updated.
365+
/// </summary>
366+
/// <returns>The <see cref="IActionResult"/>.</returns>
367+
[AllowAnonymous]
368+
public IActionResult Logout()
369+
{
370+
var redirectUri = $"{this.configuration["LearningHubAuthServiceConfig:Authority"]}/Home/SetIsPasswordUpdate?isLogout=true";
371+
return this.Redirect(redirectUri);
372+
}
373+
355374
/// <summary>
356375
/// The SessionTimeout.
357376
/// </summary>

LearningHub.Nhs.WebUI/Controllers/MyAccountController.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@
2121
using Microsoft.AspNetCore.Hosting;
2222
using Microsoft.AspNetCore.Mvc;
2323
using Microsoft.AspNetCore.Routing;
24+
using Microsoft.Extensions.Configuration;
2425
using Microsoft.Extensions.Logging;
2526
using Microsoft.Extensions.Options;
2627
using NHSUKViewComponents.Web.ViewModels;
2728
using ChangePasswordViewModel = LearningHub.Nhs.WebUI.Models.UserProfile.ChangePasswordViewModel;
29+
using IConfiguration = Microsoft.Extensions.Configuration.IConfiguration;
2830

2931
/// <summary>
3032
/// The UserController.
@@ -43,6 +45,7 @@ public partial class MyAccountController : BaseController
4345
private readonly ISpecialtyService specialtyService;
4446
private readonly ILocationService locationService;
4547
private readonly ICacheService cacheService;
48+
private readonly IConfiguration configuration;
4649

4750
/// <summary>
4851
/// Initializes a new instance of the <see cref="MyAccountController"/> class.
@@ -61,6 +64,7 @@ public partial class MyAccountController : BaseController
6164
/// <param name="locationService">The locationService.</param>
6265
/// <param name="multiPageFormService">The multiPageFormService<see cref="IMultiPageFormService"/>.</param>
6366
/// <param name="cacheService">The cacheService<see cref="ICacheService"/>.</param>
67+
/// <param name="configuration">The cacheService<see cref="IConfiguration"/>.</param>
6468
public MyAccountController(
6569
IWebHostEnvironment hostingEnvironment,
6670
ILogger<ResourceController> logger,
@@ -75,7 +79,8 @@ public MyAccountController(
7579
ISpecialtyService specialtyService,
7680
ILocationService locationService,
7781
IMultiPageFormService multiPageFormService,
78-
ICacheService cacheService)
82+
ICacheService cacheService,
83+
IConfiguration configuration)
7984
: base(hostingEnvironment, httpClientFactory, logger, settings.Value)
8085
{
8186
this.userService = userService;
@@ -88,6 +93,7 @@ public MyAccountController(
8893
this.locationService = locationService;
8994
this.multiPageFormService = multiPageFormService;
9095
this.cacheService = cacheService;
96+
this.configuration = configuration;
9197
}
9298

9399
private string LoginWizardCacheKey => $"{this.CurrentUserId}:LoginWizard";
@@ -452,9 +458,8 @@ public async Task<IActionResult> UpdatePassword(ChangePasswordViewModel model)
452458
if (this.ModelState.IsValid)
453459
{
454460
await this.userService.UpdatePassword(model.NewPassword);
455-
456-
this.ViewBag.SuccessMessage = CommonValidationErrorMessages.PasswordSuccessMessage;
457-
return this.View("SuccessMessage");
461+
var redirectUri = $"{this.configuration["LearningHubAuthServiceConfig:Authority"]}/Home/SetIsPasswordUpdate?isLogout=false";
462+
return this.Redirect(redirectUri);
458463
}
459464
else
460465
{
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
@{
2+
ViewData["Title"] = "Change password Acknowledgement";
3+
}
4+
5+
<div class="forgot-password">
6+
<div class="nhsuk-width-container app-width-container">
7+
<div class="nhsuk-grid-row">
8+
<div class="nhsuk-grid-column-full nhsuk-u-padding-top-9">
9+
<div class="nhsuk-u-reading-width">
10+
<h1 class="nhsuk-heading-xl"> Your password has been changed successfully.</h1>
11+
12+
<p class="nhsuk-body">
13+
You have been logged out. Please log in using your username and new password to explore the Learning Hub.
14+
</p>
15+
<div class="nhsuk-u-padding-bottom-9">
16+
<form asp-controller="Home" asp-action="Index" method="post">
17+
<button class="nhsuk-button" id="save-button" type="submit">Continue to the Learning Hub</button>
18+
</form>
19+
</div>
20+
</div>
21+
</div>
22+
</div>
23+
</div>
24+
</div>

0 commit comments

Comments
 (0)