@@ -6,6 +6,7 @@ namespace LearningHub.Nhs.WebUI.Controllers
66 using System . Linq ;
77 using System . Net . Http ;
88 using System . Threading . Tasks ;
9+ using AspNetCoreRateLimit ;
910 using elfhHub . Nhs . Models . Common ;
1011 using elfhHub . Nhs . Models . Enums ;
1112 using LearningHub . Nhs . Models . Content ;
@@ -26,6 +27,7 @@ namespace LearningHub.Nhs.WebUI.Controllers
2627 using Microsoft . Extensions . Logging ;
2728 using Microsoft . Extensions . Options ;
2829 using Microsoft . FeatureManagement ;
30+ using UAParser ;
2931 using Settings = LearningHub . Nhs . WebUI . Configuration . Settings ;
3032
3133 /// <summary>
@@ -206,43 +208,54 @@ public async Task<IActionResult> Index(string myLearningDashboard = "my-in-progr
206208 {
207209 if ( this . User ? . Identity . IsAuthenticated == true )
208210 {
209- this . Settings . ConcurrentId = this . CurrentUserId ;
210- this . Logger . LogInformation ( "User is authenticated: User is {fullname} and userId is: {lhuserid}" , this . User . Identity . GetCurrentName ( ) , this . User . Identity . GetCurrentUserId ( ) ) ;
211- if ( this . User . IsInRole ( "Administrator" ) || this . User . IsInRole ( "BlueUser" ) || this . User . IsInRole ( "ReadOnly" ) || this . User . IsInRole ( "BasicUser" ) )
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 )
212216 {
213- var learningTask = this . dashboardService . GetMyAccessLearningsAsync ( myLearningDashboard , 1 ) ;
214- var resourcesTask = this . dashboardService . GetResourcesAsync ( resourceDashboard , 1 ) ;
215- var cataloguesTask = this . dashboardService . GetCataloguesAsync ( catalogueDashboard , 1 ) ;
216-
217- var enrolledCoursesTask = Task . FromResult ( new List < MoodleCourseResponseViewModel > ( ) ) ;
218- var enableMoodle = Task . Run ( ( ) => this . featureManager . IsEnabledAsync ( FeatureFlags . EnableMoodle ) ) . Result ;
219- this . ViewBag . EnableMoodle = enableMoodle ;
220- this . ViewBag . ValidMoodleUser = this . CurrentMoodleUserId > 0 ;
221- if ( enableMoodle && myLearningDashboard == "my-enrolled-courses" )
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" ) )
222220 {
223- enrolledCoursesTask = this . dashboardService . GetEnrolledCoursesFromMoodleAsync ( this . CurrentMoodleUserId , 1 ) ;
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 ) ;
224250 }
225-
226- await Task . WhenAll ( learningTask , resourcesTask , cataloguesTask ) ;
227-
228- var model = new DashboardViewModel ( )
251+ else
229252 {
230- MyLearnings = await learningTask ,
231- Resources = await resourcesTask ,
232- Catalogues = await cataloguesTask ,
233- EnrolledCourses = await enrolledCoursesTask ,
234- } ;
235-
236- if ( ! string . IsNullOrEmpty ( this . Request . Query [ "preview" ] ) && Convert . ToBoolean ( this . Request . Query [ "preview" ] ) )
237- {
238- return this . View ( "LandingPage" , await this . GetLandingPageContent ( Convert . ToBoolean ( this . Request . Query [ "preview" ] ) ) ) ;
253+ return this . RedirectToAction ( "InvalidUserAccount" , "Account" ) ;
239254 }
240-
241- return this . View ( "Dashboard" , model ) ;
242255 }
243256 else
244257 {
245- return this . RedirectToAction ( "InvalidUserAccount " , "Account" ) ;
258+ return this . RedirectToAction ( "AlreadyAnActiveSession " , "Account" ) ;
246259 }
247260 }
248261 else
0 commit comments