mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 11:05:54 +01:00 
			
		
		
		
	feat: recent logins sessions table in dashbaord subpage
This commit is contained in:
		| @@ -81,5 +81,7 @@ | |||||||
| 	"back-to-dashboard": "Back to Dashboard", | 	"back-to-dashboard": "Back to Dashboard", | ||||||
| 	"details.no-users": "No users have joined within the selected timeframe", | 	"details.no-users": "No users have joined within the selected timeframe", | ||||||
| 	"details.no-topics": "No topics have been posted within the selected timeframe", | 	"details.no-topics": "No topics have been posted within the selected timeframe", | ||||||
| 	"details.no-logins": "No logins have been recorded within the selected timeframe" | 	"details.no-logins": "No logins have been recorded within the selected timeframe", | ||||||
|  | 	"details.logins-static": "NodeBB only saves session data for %1 days, and so this table below will only show the most recently active sessions", | ||||||
|  | 	"details.logins-login-time": "Login Time" | ||||||
| } | } | ||||||
|   | |||||||
| @@ -242,11 +242,27 @@ dashboardController.getLogins = async (req, res) => { | |||||||
| 		month: stats[0].thismonth, | 		month: stats[0].thismonth, | ||||||
| 	}; | 	}; | ||||||
|  |  | ||||||
|  | 	// List recent sessions | ||||||
|  | 	const start = Date.now() - (1000 * 60 * 60 * 24 * meta.config.loginDays); | ||||||
|  | 	const uids = await db.getSortedSetRangeByScore('users:online', 0, 500, start, Date.now()); | ||||||
|  | 	const usersData = await user.getUsersData(uids); | ||||||
|  | 	let sessions = await Promise.all(uids.map(async (uid) => { | ||||||
|  | 		const sessions = await user.auth.getSessions(uid); | ||||||
|  | 		sessions.forEach((session) => { | ||||||
|  | 			session.user = usersData[uids.indexOf(uid)]; | ||||||
|  | 		}); | ||||||
|  |  | ||||||
|  | 		return sessions; | ||||||
|  | 	})); | ||||||
|  | 	sessions = _.flatten(sessions).sort((a, b) => b.datetime - a.datetime); | ||||||
|  |  | ||||||
| 	res.render('admin/dashboard/logins', { | 	res.render('admin/dashboard/logins', { | ||||||
| 		set: 'logins', | 		set: 'logins', | ||||||
| 		query: req.query, | 		query: req.query, | ||||||
| 		stats, | 		stats, | ||||||
| 		summary, | 		summary, | ||||||
|  | 		sessions, | ||||||
|  | 		loginDays: meta.config.loginDays, | ||||||
| 	}); | 	}); | ||||||
| }; | }; | ||||||
|  |  | ||||||
|   | |||||||
| @@ -7,5 +7,29 @@ | |||||||
|  |  | ||||||
| 		<!-- IMPORT admin/partials/dashboard/graph.tpl --> | 		<!-- IMPORT admin/partials/dashboard/graph.tpl --> | ||||||
| 		<!-- IMPORT admin/partials/dashboard/stats.tpl --> | 		<!-- IMPORT admin/partials/dashboard/stats.tpl --> | ||||||
|  |  | ||||||
|  | 		<div class="alert alert-info">[[admin/dashboard:details.logins-static, {loginDays}]]</div> | ||||||
|  | 		<table class="table table-striped"> | ||||||
|  | 			<thead> | ||||||
|  | 				<th class="text-muted">[[admin/manage/users:users.username]]</th> | ||||||
|  | 				<th data-sort="joindate">[[admin/dashboard:details.logins-login-time]]</th> | ||||||
|  | 			</thead> | ||||||
|  | 			<tbody> | ||||||
|  | 				{{{ if !sessions.length}}} | ||||||
|  | 				<tr> | ||||||
|  | 					<td colspan=4" class="text-center"><em>[[admin/dashboard:details.no-logins]]</em></td> | ||||||
|  | 				</tr> | ||||||
|  | 				{{{ end }}} | ||||||
|  | 				{{{ each sessions }}} | ||||||
|  | 				<tr> | ||||||
|  | 					<td> | ||||||
|  | 						<a href="{config.relative_path}/uid/{./user.uid}">{buildAvatar(./user, "sm", true)} {../username}</a> | ||||||
|  | 						{function.userAgentIcons} {../browser} {../version} on {../platform} | ||||||
|  | 					</td> | ||||||
|  | 					<td><span class="timeago" title="{./datetimeISO}"></span></td> | ||||||
|  | 				</tr> | ||||||
|  | 				{{{ end }}} | ||||||
|  | 			</tbody> | ||||||
|  | 		</table> | ||||||
| 	</div> | 	</div> | ||||||
| </div> | </div> | ||||||
		Reference in New Issue
	
	Block a user