mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-12-22 16:54:46 +03:00
Add active session tracking
Adds a flag for a maximum number of user sessions, as well as an authentication check to ensure that the user is not above this level.
This commit is contained in:
@@ -1484,6 +1484,19 @@ namespace Emby.Server.Implementations.Session
|
||||
throw new SecurityException("User is not allowed access from this device.");
|
||||
}
|
||||
|
||||
var sessionsCount = Sessions.Where(i => string.Equals(i.UserId, user.Id)).ToList().Count;
|
||||
int maxActiveSessions = user.MaxActiveSessions;
|
||||
_logger.LogDebug("Current/Max sessions for user {User}: {Sessions}/{Max}", user.Username, sessionsCount, maxActiveSessions);
|
||||
if (maxActiveSessions >= 0 && sessionsCount >= maxActiveSessions)
|
||||
{
|
||||
throw new SecurityException(
|
||||
"User {User} is at their maximum number of sessions ({Sessions}/{Max}).",
|
||||
user.Username,
|
||||
sessionsCount,
|
||||
maxActiveSessions
|
||||
)
|
||||
}
|
||||
|
||||
var token = GetAuthorizationToken(user, request.DeviceId, request.App, request.AppVersion, request.DeviceName);
|
||||
|
||||
var session = LogSessionActivity(
|
||||
|
||||
Reference in New Issue
Block a user