diff --git a/AdminUI/LearningHub.Nhs.AdminUI/Controllers/api/UserController.cs b/AdminUI/LearningHub.Nhs.AdminUI/Controllers/api/UserController.cs deleted file mode 100644 index d2b97e13c..000000000 --- a/AdminUI/LearningHub.Nhs.AdminUI/Controllers/api/UserController.cs +++ /dev/null @@ -1,60 +0,0 @@ -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; - - /// - /// The UserController class. - /// - [Authorize] - [Route("api/[controller]")] - [ApiController] - public class UserController : BaseApiController - { - /// - /// The elfh user service.. - /// - private IUserService userService; - - /// - /// Initializes a new instance of the class. - /// - /// The userService. - /// loginWizardService. - /// logger. - /// Settings. - public UserController(IUserService userService, ILogger logger) - : base(logger) - { - this.userService = userService; - } - - /// - /// The SessionTimeout. - /// - /// The . - [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); - } - } -} diff --git a/AdminUI/LearningHub.Nhs.AdminUI/Views/Shared/_Layout.cshtml b/AdminUI/LearningHub.Nhs.AdminUI/Views/Shared/_Layout.cshtml index aa098dc6a..d12be205a 100644 --- a/AdminUI/LearningHub.Nhs.AdminUI/Views/Shared/_Layout.cshtml +++ b/AdminUI/LearningHub.Nhs.AdminUI/Views/Shared/_Layout.cshtml @@ -78,14 +78,7 @@ @**@ - @RenderSection("Scripts", required: false) - - diff --git a/AdminUI/LearningHub.Nhs.AdminUI/wwwroot/js/PageUnload.js b/AdminUI/LearningHub.Nhs.AdminUI/wwwroot/js/PageUnload.js deleted file mode 100644 index 8c458bee1..000000000 --- a/AdminUI/LearningHub.Nhs.AdminUI/wwwroot/js/PageUnload.js +++ /dev/null @@ -1,13 +0,0 @@ - // 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)); - } \ No newline at end of file diff --git a/LearningHub.Nhs.WebUI/Configuration/Settings.cs b/LearningHub.Nhs.WebUI/Configuration/Settings.cs index f0f2da3c1..ccb06c921 100644 --- a/LearningHub.Nhs.WebUI/Configuration/Settings.cs +++ b/LearningHub.Nhs.WebUI/Configuration/Settings.cs @@ -196,11 +196,6 @@ public Settings() /// public int PasswordRequestLimit { get; set; } - /// - /// Gets or sets the ConcurrentId. - /// - public int ConcurrentId { get; set; } - /// /// Gets or sets the SupportUrls. /// diff --git a/LearningHub.Nhs.WebUI/Controllers/Api/UserController.cs b/LearningHub.Nhs.WebUI/Controllers/Api/UserController.cs index 48f2c0e9e..35294cc11 100644 --- a/LearningHub.Nhs.WebUI/Controllers/Api/UserController.cs +++ b/LearningHub.Nhs.WebUI/Controllers/Api/UserController.cs @@ -63,26 +63,6 @@ public async Task CurrentProfile() return this.Ok(await this.userService.GetCurrentUserProfileAsync()); } - /// - /// The SessionTimeout. - /// - /// The . - [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); - } - /// /// Get current user's basic details. /// diff --git a/LearningHub.Nhs.WebUI/Controllers/HomeController.cs b/LearningHub.Nhs.WebUI/Controllers/HomeController.cs index 9b91ed9ac..7f40afe15 100644 --- a/LearningHub.Nhs.WebUI/Controllers/HomeController.cs +++ b/LearningHub.Nhs.WebUI/Controllers/HomeController.cs @@ -6,7 +6,6 @@ namespace LearningHub.Nhs.WebUI.Controllers using System.Linq; using System.Net.Http; using System.Threading.Tasks; - using AspNetCoreRateLimit; using elfhHub.Nhs.Models.Common; using elfhHub.Nhs.Models.Enums; using LearningHub.Nhs.Models.Content; @@ -27,7 +26,6 @@ namespace LearningHub.Nhs.WebUI.Controllers using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Microsoft.FeatureManagement; - using UAParser; using Settings = LearningHub.Nhs.WebUI.Configuration.Settings; /// @@ -208,54 +206,42 @@ public async Task Index(string myLearningDashboard = "my-in-progr { if (this.User?.Identity.IsAuthenticated == true) { - var userHistoryDetail = await this.userService.CheckUserHasAnActiveSessionAsync(this.CurrentUserId); - var uaParser = Parser.GetDefault(); - var clientInfo = uaParser.Parse(this.Request.Headers["User-Agent"]); - - if (userHistoryDetail.Items.Count == 0 || userHistoryDetail.Items[0].BrowserName == clientInfo.UA.Family) + 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")) { - 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")) + var learningTask = this.dashboardService.GetMyAccessLearningsAsync(myLearningDashboard, 1); + var resourcesTask = this.dashboardService.GetResourcesAsync(resourceDashboard, 1); + var cataloguesTask = this.dashboardService.GetCataloguesAsync(catalogueDashboard, 1); + + var enrolledCoursesTask = Task.FromResult(new List()); + var enableMoodle = Task.Run(() => this.featureManager.IsEnabledAsync(FeatureFlags.EnableMoodle)).Result; + this.ViewBag.EnableMoodle = enableMoodle; + this.ViewBag.ValidMoodleUser = this.CurrentMoodleUserId > 0; + if (enableMoodle && myLearningDashboard == "my-enrolled-courses") { - var learningTask = this.dashboardService.GetMyAccessLearningsAsync(myLearningDashboard, 1); - var resourcesTask = this.dashboardService.GetResourcesAsync(resourceDashboard, 1); - var cataloguesTask = this.dashboardService.GetCataloguesAsync(catalogueDashboard, 1); - - var enrolledCoursesTask = Task.FromResult(new List()); - var enableMoodle = Task.Run(() => this.featureManager.IsEnabledAsync(FeatureFlags.EnableMoodle)).Result; - this.ViewBag.EnableMoodle = enableMoodle; - this.ViewBag.ValidMoodleUser = this.CurrentMoodleUserId > 0; - if (enableMoodle && myLearningDashboard == "my-enrolled-courses") - { - enrolledCoursesTask = this.dashboardService.GetEnrolledCoursesFromMoodleAsync(this.CurrentMoodleUserId, 1); - } - - await Task.WhenAll(learningTask, resourcesTask, cataloguesTask); - - var model = new DashboardViewModel() - { - MyLearnings = await learningTask, - Resources = await resourcesTask, - Catalogues = await cataloguesTask, - EnrolledCourses = await enrolledCoursesTask, - }; - - if (!string.IsNullOrEmpty(this.Request.Query["preview"]) && Convert.ToBoolean(this.Request.Query["preview"])) - { - return this.View("LandingPage", await this.GetLandingPageContent(Convert.ToBoolean(this.Request.Query["preview"]))); - } - - return this.View("Dashboard", model); + enrolledCoursesTask = this.dashboardService.GetEnrolledCoursesFromMoodleAsync(this.CurrentMoodleUserId, 1); } - else + + await Task.WhenAll(learningTask, resourcesTask, cataloguesTask); + + var model = new DashboardViewModel() + { + MyLearnings = await learningTask, + Resources = await resourcesTask, + Catalogues = await cataloguesTask, + EnrolledCourses = await enrolledCoursesTask, + }; + + if (!string.IsNullOrEmpty(this.Request.Query["preview"]) && Convert.ToBoolean(this.Request.Query["preview"])) { - return this.RedirectToAction("InvalidUserAccount", "Account"); + return this.View("LandingPage", await this.GetLandingPageContent(Convert.ToBoolean(this.Request.Query["preview"]))); } + + return this.View("Dashboard", model); } else { - return this.RedirectToAction("AlreadyAnActiveSession", "Account"); + return this.RedirectToAction("InvalidUserAccount", "Account"); } } else @@ -399,41 +385,12 @@ 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(); } - /// - /// The SessionTimeout. - /// - /// The . - [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); - } - /// /// The SitemapXml. /// diff --git a/LearningHub.Nhs.WebUI/Views/Shared/Tenant/LearningHub/_Layout.cshtml b/LearningHub.Nhs.WebUI/Views/Shared/Tenant/LearningHub/_Layout.cshtml index b999a6fb2..c16fa837c 100644 --- a/LearningHub.Nhs.WebUI/Views/Shared/Tenant/LearningHub/_Layout.cshtml +++ b/LearningHub.Nhs.WebUI/Views/Shared/Tenant/LearningHub/_Layout.cshtml @@ -161,13 +161,6 @@ @RenderSection("Scripts", required: false) - - - diff --git a/LearningHub.Nhs.WebUI/appsettings.json b/LearningHub.Nhs.WebUI/appsettings.json index edb50316b..95dd80eee 100644 --- a/LearningHub.Nhs.WebUI/appsettings.json +++ b/LearningHub.Nhs.WebUI/appsettings.json @@ -39,7 +39,6 @@ "Restricted": false, "PasswordRequestLimitingPeriod": 1, // minutes "PasswordRequestLimit": 2, - "ConcurrentId": 0, "AzureBlobSettings": { "ConnectionString": "", "UploadContainer": "" diff --git a/LearningHub.Nhs.WebUI/wwwroot/js/PageUnload.js b/LearningHub.Nhs.WebUI/wwwroot/js/PageUnload.js deleted file mode 100644 index 8c458bee1..000000000 --- a/LearningHub.Nhs.WebUI/wwwroot/js/PageUnload.js +++ /dev/null @@ -1,13 +0,0 @@ - // 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)); - } \ No newline at end of file