@@ -6,7 +6,6 @@ namespace LearningHub.Nhs.WebUI.Controllers
66 using System . Linq ;
77 using System . Net . Http ;
88 using System . Threading . Tasks ;
9- using AspNetCoreRateLimit ;
109 using elfhHub . Nhs . Models . Common ;
1110 using elfhHub . Nhs . Models . Enums ;
1211 using LearningHub . Nhs . Models . Content ;
@@ -27,7 +26,6 @@ namespace LearningHub.Nhs.WebUI.Controllers
2726 using Microsoft . Extensions . Logging ;
2827 using Microsoft . Extensions . Options ;
2928 using Microsoft . FeatureManagement ;
30- using UAParser ;
3129 using Settings = LearningHub . Nhs . WebUI . Configuration . Settings ;
3230
3331 /// <summary>
@@ -208,54 +206,42 @@ public async Task<IActionResult> Index(string myLearningDashboard = "my-in-progr
208206 {
209207 if ( this . User ? . Identity . IsAuthenticated == true )
210208 {
211- var userHistoryDetail = await this . userService . CheckUserHasAnActiveSessionAsync ( this . CurrentUserId ) ;
212- var uaParser = Parser . GetDefault ( ) ;
213- var clientInfo = uaParser . Parse ( this . Request . Headers [ "User-Agent" ] ) ;
214-
215- if ( userHistoryDetail . Items . Count == 0 || userHistoryDetail . Items [ 0 ] . BrowserName == clientInfo . UA . Family )
209+ this . Logger . LogInformation ( "User is authenticated: User is {fullname} and userId is: {lhuserid}" , this . User . Identity . GetCurrentName ( ) , this . User . Identity . GetCurrentUserId ( ) ) ;
210+ if ( this . User . IsInRole ( "Administrator" ) || this . User . IsInRole ( "BlueUser" ) || this . User . IsInRole ( "ReadOnly" ) || this . User . IsInRole ( "BasicUser" ) )
216211 {
217- this . Settings . ConcurrentId = this . CurrentUserId ;
218- this . Logger . LogInformation ( "User is authenticated: User is {fullname} and userId is: {lhuserid}" , this . User . Identity . GetCurrentName ( ) , this . User . Identity . GetCurrentUserId ( ) ) ;
219- if ( this . User . IsInRole ( "Administrator" ) || this . User . IsInRole ( "BlueUser" ) || this . User . IsInRole ( "ReadOnly" ) || this . User . IsInRole ( "BasicUser" ) )
212+ var learningTask = this . dashboardService . GetMyAccessLearningsAsync ( myLearningDashboard , 1 ) ;
213+ var resourcesTask = this . dashboardService . GetResourcesAsync ( resourceDashboard , 1 ) ;
214+ var cataloguesTask = this . dashboardService . GetCataloguesAsync ( catalogueDashboard , 1 ) ;
215+
216+ var enrolledCoursesTask = Task . FromResult ( new List < MoodleCourseResponseViewModel > ( ) ) ;
217+ var enableMoodle = Task . Run ( ( ) => this . featureManager . IsEnabledAsync ( FeatureFlags . EnableMoodle ) ) . Result ;
218+ this . ViewBag . EnableMoodle = enableMoodle ;
219+ this . ViewBag . ValidMoodleUser = this . CurrentMoodleUserId > 0 ;
220+ if ( enableMoodle && myLearningDashboard == "my-enrolled-courses" )
220221 {
221- var learningTask = this . dashboardService . GetMyAccessLearningsAsync ( myLearningDashboard , 1 ) ;
222- var resourcesTask = this . dashboardService . GetResourcesAsync ( resourceDashboard , 1 ) ;
223- var cataloguesTask = this . dashboardService . GetCataloguesAsync ( catalogueDashboard , 1 ) ;
224-
225- var enrolledCoursesTask = Task . FromResult ( new List < MoodleCourseResponseViewModel > ( ) ) ;
226- var enableMoodle = Task . Run ( ( ) => this . featureManager . IsEnabledAsync ( FeatureFlags . EnableMoodle ) ) . Result ;
227- this . ViewBag . EnableMoodle = enableMoodle ;
228- this . ViewBag . ValidMoodleUser = this . CurrentMoodleUserId > 0 ;
229- if ( enableMoodle && myLearningDashboard == "my-enrolled-courses" )
230- {
231- enrolledCoursesTask = this . dashboardService . GetEnrolledCoursesFromMoodleAsync ( this . CurrentMoodleUserId , 1 ) ;
232- }
233-
234- await Task . WhenAll ( learningTask , resourcesTask , cataloguesTask ) ;
235-
236- var model = new DashboardViewModel ( )
237- {
238- MyLearnings = await learningTask ,
239- Resources = await resourcesTask ,
240- Catalogues = await cataloguesTask ,
241- EnrolledCourses = await enrolledCoursesTask ,
242- } ;
243-
244- if ( ! string . IsNullOrEmpty ( this . Request . Query [ "preview" ] ) && Convert . ToBoolean ( this . Request . Query [ "preview" ] ) )
245- {
246- return this . View ( "LandingPage" , await this . GetLandingPageContent ( Convert . ToBoolean ( this . Request . Query [ "preview" ] ) ) ) ;
247- }
248-
249- return this . View ( "Dashboard" , model ) ;
222+ enrolledCoursesTask = this . dashboardService . GetEnrolledCoursesFromMoodleAsync ( this . CurrentMoodleUserId , 1 ) ;
250223 }
251- else
224+
225+ await Task . WhenAll ( learningTask , resourcesTask , cataloguesTask ) ;
226+
227+ var model = new DashboardViewModel ( )
228+ {
229+ MyLearnings = await learningTask ,
230+ Resources = await resourcesTask ,
231+ Catalogues = await cataloguesTask ,
232+ EnrolledCourses = await enrolledCoursesTask ,
233+ } ;
234+
235+ if ( ! string . IsNullOrEmpty ( this . Request . Query [ "preview" ] ) && Convert . ToBoolean ( this . Request . Query [ "preview" ] ) )
252236 {
253- return this . RedirectToAction ( "InvalidUserAccount ", "Account" ) ;
237+ return this . View ( "LandingPage ", await this . GetLandingPageContent ( Convert . ToBoolean ( this . Request . Query [ "preview" ] ) ) ) ;
254238 }
239+
240+ return this . View ( "Dashboard" , model ) ;
255241 }
256242 else
257243 {
258- return this . RedirectToAction ( "AlreadyAnActiveSession " , "Account" ) ;
244+ return this . RedirectToAction ( "InvalidUserAccount " , "Account" ) ;
259245 }
260246 }
261247 else
@@ -399,41 +385,12 @@ public IActionResult SessionTimeout(string returnUrl = "/")
399385 return this . Redirect ( returnUrl ) ;
400386 }
401387
402- // Add successful logout to the UserHistory
403- UserHistoryViewModel userHistory = new UserHistoryViewModel ( )
404- {
405- UserId = this . Settings . ConcurrentId ,
406- UserHistoryTypeId = ( int ) UserHistoryType . Logout ,
407- Detail = @"User session time out" ,
408- } ;
409-
410- this . userService . StoreUserHistory ( userHistory ) ;
411-
412388 this . ViewBag . AuthTimeout = this . authConfig . AuthTimeout ;
413389 this . ViewBag . ReturnUrl = returnUrl ;
414390
415391 return this . View ( ) ;
416392 }
417393
418- /// <summary>
419- /// The SessionTimeout.
420- /// </summary>
421- /// <returns>The <see cref="IActionResult"/>.</returns>
422- [ HttpPost ( "browser-close" ) ]
423- public IActionResult BrowserClose ( )
424- {
425- // Add browser close to the UserHistory
426- UserHistoryViewModel userHistory = new UserHistoryViewModel ( )
427- {
428- UserId = this . CurrentUserId ,
429- UserHistoryTypeId = ( int ) UserHistoryType . Logout ,
430- Detail = @"User browser closed" ,
431- } ;
432-
433- this . userService . StoreUserHistory ( userHistory ) ;
434- return this . Ok ( true ) ;
435- }
436-
437394 /// <summary>
438395 /// The SitemapXml.
439396 /// </summary>
0 commit comments