Skip to content
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
60 changes: 60 additions & 0 deletions AdminUI/LearningHub.Nhs.AdminUI/Controllers/api/UserController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
namespace LearningHub.Nhs.AdminUI.Controllers.Api
{
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using elfhHub.Nhs.Models.Common;
using elfhHub.Nhs.Models.Enums;
using LearningHub.Nhs.AdminUI.Interfaces;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;

/// <summary>
/// The UserController class.
/// </summary>
[Authorize]
[Route("api/[controller]")]
[ApiController]
public class UserController : BaseApiController
{
/// <summary>
/// The elfh user service..
/// </summary>
private IUserService userService;

/// <summary>
/// Initializes a new instance of the <see cref="UserController"/> class.
/// </summary>
/// <param name="userService">The userService<see cref="IUserService"/>.</param>
/// <param name="loginWizardService">loginWizardService.</param>
/// <param name="logger">logger.</param>
/// <param name="settings">Settings.</param>
public UserController(IUserService userService, ILogger<UserController> logger)
: base(logger)
{
this.userService = userService;
}

/// <summary>
/// The SessionTimeout.
/// </summary>
/// <returns>The <see cref="IActionResult"/>.</returns>
[HttpPost("browser-close")]
public IActionResult BrowserClose()
{
// Add browser close to the UserHistory
UserHistoryViewModel userHistory = new UserHistoryViewModel()
{
UserId = this.CurrentUserId,
UserHistoryTypeId = (int)UserHistoryType.Logout,
Detail = @"User browser closed",
};

this.userService.StoreUserHistory(userHistory);

return this.Ok(true);
}
}
}
1,711 changes: 857 additions & 854 deletions AdminUI/LearningHub.Nhs.AdminUI/Views/Resource/Details.cshtml

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions AdminUI/LearningHub.Nhs.AdminUI/Views/Shared/_Layout.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,14 @@
</environment>
@*<script type="text/javascript" src="~/js/bundle/header.js"></script>*@
<partial name="~/Views/Shared/_ValidationScriptsPartial.cshtml" />

@RenderSection("Scripts", required: false)
<script type="text/javascript" src="~/js/pageunload.js" asp-append-version="true"></script>
<script type="text/javascript">
// Bind the function to the unload event
window.onunload = tellServerBrowserClosed;

</script>
</body>
</html>
<!-- Build number: @settings.Value.BuildNumber -->
Expand Down
13 changes: 13 additions & 0 deletions AdminUI/LearningHub.Nhs.AdminUI/wwwroot/js/PageUnload.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
 // This function will be called when the browser window is closed or unloaded
function tellServerBrowserClosed() {
// Send an asynchronous request to the server when the browser is closed
fetch('/api/user/browser-close', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ message: 'Browser closed' })
})
.then(response => response.json())
.catch(error => console.error('Error sending data to server:', error));
}
5 changes: 5 additions & 0 deletions LearningHub.Nhs.WebUI/Configuration/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,11 @@ public Settings()
/// </summary>
public int PasswordRequestLimit { get; set; }

/// <summary>
/// Gets or sets the ConcurrentId.
/// </summary>
public int ConcurrentId { get; set; }

/// <summary>
/// Gets or sets the SupportUrls.
/// </summary>
Expand Down
21 changes: 21 additions & 0 deletions LearningHub.Nhs.WebUI/Controllers/Api/UserController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using elfhHub.Nhs.Models.Common;
using elfhHub.Nhs.Models.Enums;
using LearningHub.Nhs.WebUI.Configuration;
using LearningHub.Nhs.WebUI.Interfaces;
using Microsoft.AspNetCore.Authorization;
Expand Down Expand Up @@ -62,6 +63,26 @@ public async Task<IActionResult> CurrentProfile()
return this.Ok(await this.userService.GetCurrentUserProfileAsync());
}

/// <summary>
/// The SessionTimeout.
/// </summary>
/// <returns>The <see cref="IActionResult"/>.</returns>
[HttpPost("browser-close")]
public IActionResult BrowserClose()
{
// Add browser close to the UserHistory
UserHistoryViewModel userHistory = new UserHistoryViewModel()
{
UserId = this.CurrentUserId,
UserHistoryTypeId = (int)UserHistoryType.Logout,
Detail = @"User browser closed",
};

this.userService.StoreUserHistory(userHistory);

return this.Ok(true);
}

/// <summary>
/// Get current user's basic details.
/// </summary>
Expand Down
32 changes: 32 additions & 0 deletions LearningHub.Nhs.WebUI/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace LearningHub.Nhs.WebUI.Controllers
using System.Net.Http;
using System.Threading.Tasks;
using elfhHub.Nhs.Models.Common;
using elfhHub.Nhs.Models.Enums;
using LearningHub.Nhs.Models.Content;
using LearningHub.Nhs.Models.Enums.Content;
using LearningHub.Nhs.Models.Extensions;
Expand Down Expand Up @@ -205,6 +206,7 @@ public async Task<IActionResult> Index(string myLearningDashboard = "my-in-progr
{
if (this.User?.Identity.IsAuthenticated == true)
{
this.Settings.ConcurrentId = this.CurrentUserId;
this.Logger.LogInformation("User is authenticated: User is {fullname} and userId is: {lhuserid}", this.User.Identity.GetCurrentName(), this.User.Identity.GetCurrentUserId());
if (this.User.IsInRole("Administrator") || this.User.IsInRole("BlueUser") || this.User.IsInRole("ReadOnly") || this.User.IsInRole("BasicUser"))
{
Expand Down Expand Up @@ -374,11 +376,41 @@ public IActionResult SessionTimeout(string returnUrl = "/")
return this.Redirect(returnUrl);
}

// Add successful logout to the UserHistory
UserHistoryViewModel userHistory = new UserHistoryViewModel()
{
UserId = this.Settings.ConcurrentId,
UserHistoryTypeId = (int)UserHistoryType.Logout,
Detail = @"User session time out",
};

this.userService.StoreUserHistory(userHistory);

this.ViewBag.AuthTimeout = this.authConfig.AuthTimeout;
this.ViewBag.ReturnUrl = returnUrl;

return this.View();
}

/// <summary>
/// The SessionTimeout.
/// </summary>
/// <returns>The <see cref="IActionResult"/>.</returns>
[HttpPost("browser-close")]
public IActionResult BrowserClose()
{
// Add browser close to the UserHistory
UserHistoryViewModel userHistory = new UserHistoryViewModel()
{
UserId = this.CurrentUserId,
UserHistoryTypeId = (int)UserHistoryType.Logout,
Detail = @"User browser closed",
};

this.userService.StoreUserHistory(userHistory);
return this.Ok(true);
}

/// <summary>
/// The SitemapXml.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,19 +133,19 @@
@if (!ViewData["DisableValidation"]?.Equals(true) ?? true)
{
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.19.5/jquery.validate.min.js"
asp-fallback-src="~/lib/jquery-validation/dist/jquery.validate.min.js"
asp-fallback-test="window.jQuery && window.jQuery.validator"
asp-suppress-fallback-integrity="true"
crossorigin="anonymous"
integrity="sha512-rstIgDs0xPgmG6RX1Aba4KV5cWJbAMcvRCVmglpam9SoHZiUCyQVDdH2LPlxoHtrv17XWblE/V/PP+Tr04hbtA==">
asp-fallback-src="~/lib/jquery-validation/dist/jquery.validate.min.js"
asp-fallback-test="window.jQuery && window.jQuery.validator"
asp-suppress-fallback-integrity="true"
crossorigin="anonymous"
integrity="sha512-rstIgDs0xPgmG6RX1Aba4KV5cWJbAMcvRCVmglpam9SoHZiUCyQVDdH2LPlxoHtrv17XWblE/V/PP+Tr04hbtA==">
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validation-unobtrusive/4.0.0/jquery.validate.unobtrusive.min.js"
asp-fallback-src="~/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min.js"
asp-fallback-test="window.jQuery && window.jQuery.validator && window.jQuery.validator.unobtrusive"
asp-suppress-fallback-integrity="true"
crossorigin="anonymous"
integrity="sha512-xq+Vm8jC94ynOikewaQXMEkJIOBp7iArs3IhFWSWdRT3Pq8wFz46p+ZDFAR7kHnSFf+zUv52B3prRYnbDRdgog==">
</script>
asp-fallback-src="~/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min.js"
asp-fallback-test="window.jQuery && window.jQuery.validator && window.jQuery.validator.unobtrusive"
asp-suppress-fallback-integrity="true"
crossorigin="anonymous"
integrity="sha512-xq+Vm8jC94ynOikewaQXMEkJIOBp7iArs3IhFWSWdRT3Pq8wFz46p+ZDFAR7kHnSFf+zUv52B3prRYnbDRdgog==">
</script>
}
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js" asp-append-version="true"></script>
<script type="text/javascript" src="~/js/jquery.matchHeight.min.js" asp-append-version="true"></script>
Expand All @@ -161,6 +161,13 @@
@RenderSection("Scripts", required: false)

<script type="text/javascript" src="~/js/mkplayer-ui-custom.js" asp-append-version="true"></script>
<script type="text/javascript" src="~/js/pageunload.js" asp-append-version="true"></script>

<script type="text/javascript">
// Bind the function to the unload event
window.onunload = tellServerBrowserClosed;

</script>

</body>
</html>
Expand Down
1 change: 1 addition & 0 deletions LearningHub.Nhs.WebUI/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"Restricted": false,
"PasswordRequestLimitingPeriod": 1, // minutes
"PasswordRequestLimit": 2,
"ConcurrentId": 0,
"AzureBlobSettings": {
"ConnectionString": "",
"UploadContainer": ""
Expand Down
13 changes: 13 additions & 0 deletions LearningHub.Nhs.WebUI/wwwroot/js/PageUnload.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
 // This function will be called when the browser window is closed or unloaded
function tellServerBrowserClosed() {
// Send an asynchronous request to the server when the browser is closed
fetch('/api/user/browser-close', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ message: 'Browser closed' })
})
.then(response => response.json())
.catch(error => console.error('Error sending data to server:', error));
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<ModelCollation>1033, CI</ModelCollation>
<DefaultFileStructure>BySchemaAndSchemaType</DefaultFileStructure>
<DeployToDatabase>True</DeployToDatabase>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<TargetLanguage>CS</TargetLanguage>
<AppDesignerFolder>Properties</AppDesignerFolder>
<SqlServerVerification>False</SqlServerVerification>
Expand Down Expand Up @@ -539,6 +539,7 @@
<Build Include="Stored Procedures\Activity\GetAssessmentActivityCompletionPercentage.sql" />
<Build Include="Tables\Hub\PasswordResetRequests.sql" />
<Build Include="Stored Procedures\External\ExternalSystemUserCreate.sql" />
<None Include="Scripts\ELFH Database Scripts\ConCurrentUserSessionsTablesandSP.sql" />
</ItemGroup>
<ItemGroup>
<None Include="Scripts\Pre-Deploy\Scripts\Card5766_AuthorTableChanges.PreDeployment.sql" />
Expand Down
Loading
Loading