@@ -7,6 +7,7 @@ namespace LearningHub.Nhs.WebUI.Controllers
77 using System . Net . Http ;
88 using System . Threading . Tasks ;
99 using elfhHub . Nhs . Models . Common ;
10+ using elfhHub . Nhs . Models . Enums ;
1011 using LearningHub . Nhs . Models . Content ;
1112 using LearningHub . Nhs . Models . Enums . Content ;
1213 using LearningHub . Nhs . Models . Extensions ;
@@ -205,6 +206,7 @@ public async Task<IActionResult> Index(string myLearningDashboard = "my-in-progr
205206 {
206207 if ( this . User ? . Identity . IsAuthenticated == true )
207208 {
209+ this . Settings . ConcurrentId = this . CurrentUserId ;
208210 this . Logger . LogInformation ( "User is authenticated: User is {fullname} and userId is: {lhuserid}" , this . User . Identity . GetCurrentName ( ) , this . User . Identity . GetCurrentUserId ( ) ) ;
209211 if ( this . User . IsInRole ( "Administrator" ) || this . User . IsInRole ( "BlueUser" ) || this . User . IsInRole ( "ReadOnly" ) || this . User . IsInRole ( "BasicUser" ) )
210212 {
@@ -374,11 +376,41 @@ public IActionResult SessionTimeout(string returnUrl = "/")
374376 return this . Redirect ( returnUrl ) ;
375377 }
376378
379+ // Add successful logout to the UserHistory
380+ UserHistoryViewModel userHistory = new UserHistoryViewModel ( )
381+ {
382+ UserId = this . Settings . ConcurrentId ,
383+ UserHistoryTypeId = ( int ) UserHistoryType . Logout ,
384+ Detail = @"User session time out" ,
385+ } ;
386+
387+ this . userService . StoreUserHistory ( userHistory ) ;
388+
377389 this . ViewBag . AuthTimeout = this . authConfig . AuthTimeout ;
378390 this . ViewBag . ReturnUrl = returnUrl ;
391+
379392 return this . View ( ) ;
380393 }
381394
395+ /// <summary>
396+ /// The SessionTimeout.
397+ /// </summary>
398+ /// <returns>The <see cref="IActionResult"/>.</returns>
399+ [ HttpPost ( "browser-close" ) ]
400+ public IActionResult BrowserClose ( )
401+ {
402+ // Add browser close to the UserHistory
403+ UserHistoryViewModel userHistory = new UserHistoryViewModel ( )
404+ {
405+ UserId = this . CurrentUserId ,
406+ UserHistoryTypeId = ( int ) UserHistoryType . Logout ,
407+ Detail = @"User browser closed" ,
408+ } ;
409+
410+ this . userService . StoreUserHistory ( userHistory ) ;
411+ return this . Ok ( true ) ;
412+ }
413+
382414 /// <summary>
383415 /// The SitemapXml.
384416 /// </summary>
0 commit comments