Revert "添加在线用户管理,同一账号只允许一台设备登陆。"

This reverts commit a777e04e83.
This commit is contained in:
zhougf committed 2024-07-08 14:08:02 +08:00
1 parent a777e04e83
commit 4c99666b75
11 files changed
+10 -192

No files matched your search

@@ -1,38 +0,0 @@
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Http;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Support.Quartz;
namespace HHWMS.Web.Support;
public class SessionValidationMiddleware
{
private readonly RequestDelegate _next;
public SessionValidationMiddleware(RequestDelegate next)
{
_next = next;
}
public async Task InvokeAsync(HttpContext context)
{
if (context.User.Identity.IsAuthenticated)
{
var userId = context.User.Identity.Name;
var sessionId = context.User.Claims.FirstOrDefault(c => c.Type == "SessionId")?.Value;
if (!UserSessionManager.IsUserSessionValid(userId, sessionId))
{
// UserSessionManager.RemoveUserSession(userId);
await context.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
context.Response.Redirect(new Configs().CookieOptions.LogoutPath);
return;
}
}
await _next(context);
}
}
-42
View File
@@ -1,42 +0,0 @@
using System.Linq;
using Microsoft.AspNetCore.Mvc;
using WalkingTec.Mvvm.Core;
namespace HHWMS.Web.Support;
using System.Collections.Concurrent;
public class UserSessionManager
{
private static ConcurrentDictionary<string, string> userSessions = new ConcurrentDictionary<string, string>();
public static void AddUserSession(string userId, string sessionId)
{
userSessions[userId.ToLower()] = sessionId;
}
public static void RemoveUserSession(string userId)
{
userSessions.TryRemove(userId, out _);
}
public static bool IsUserSessionValid(string userId, string sessionId)
{
return userSessions.TryGetValue(userId.ToLower(), out var storedSessionId) && storedSessionId == sessionId;
}
public static bool IsUserSignined(string userId)
{
return userSessions.ContainsKey(userId);
}
public static void KickUser(string userId)
{
userSessions.TryRemove(userId, out _);
}
public static ConcurrentDictionary<string, string> AllSignined()
{
return userSessions;
}
}