diff --git a/HHWMS.Web/Controllers/LoginController.cs b/HHWMS.Web/Controllers/LoginController.cs
index 0b699d7..2581872 100644
--- a/HHWMS.Web/Controllers/LoginController.cs
+++ b/HHWMS.Web/Controllers/LoginController.cs
@@ -56,11 +56,11 @@ namespace HHWMS.Web.Controllers
}
else
{
- var signined = UserSessionManager.IsUserSignined(user.Name);
+ var signined = UserSessionManager.IsUserSignined(user.ITCode);
if (signined)
{
// 踢人下线
- await KickUser(user.Name);
+ await KickUser(user.ITCode);
}
//其他属性可以通过user.Attributes["aaa"] = "bbb"方式赋值
Wtm.LoginUserInfo = user;
@@ -85,8 +85,15 @@ namespace HHWMS.Web.Controllers
}
var principal = user.CreatePrincipal();
+ // 确保Principal包含ITCode claim,用于会话验证
+ var identity = principal.Identity as System.Security.Claims.ClaimsIdentity;
+ if (identity != null && !identity.HasClaim(c => c.Type == "ITCode"))
+ {
+ identity.AddClaim(new System.Security.Claims.Claim("ITCode", user.ITCode));
+ }
+
await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, principal, properties);
- UserSessionManager.AddUserSession(user.Name,principal.Claims.First(c => c.Type == "SessionId").Value);
+ UserSessionManager.AddUserSession(user.ITCode,principal.Claims.First(c => c.Type == "SessionId").Value);
return Redirect(HttpUtility.UrlDecode(url));
}
}
diff --git a/HHWMS.Web/Support/SessionValidationMiddleware.cs b/HHWMS.Web/Support/SessionValidationMiddleware.cs
index 794bb6e..aab6241 100644
--- a/HHWMS.Web/Support/SessionValidationMiddleware.cs
+++ b/HHWMS.Web/Support/SessionValidationMiddleware.cs
@@ -21,7 +21,9 @@ public class SessionValidationMiddleware
{
if (context.User.Identity.IsAuthenticated)
{
- var userId = context.User.Identity.Name;
+ // 优先使用ITCode claim,如果不存在则使用Name
+ var userId = context.User.Claims.FirstOrDefault(c => c.Type == "ITCode")?.Value
+ ?? context.User.Identity.Name;
var sessionId = context.User.Claims.FirstOrDefault(c => c.Type == "SessionId")?.Value;
if (!UserSessionManager.IsUserSessionValid(userId, sessionId))
@@ -35,4 +37,4 @@ public class SessionValidationMiddleware
await _next(context);
}
-}
\ No newline at end of file
+}
diff --git a/HHWMS.Web/Views/Home/Index.cshtml b/HHWMS.Web/Views/Home/Index.cshtml
index b1d2e1d..967a704 100644
--- a/HHWMS.Web/Views/Home/Index.cshtml
+++ b/HHWMS.Web/Views/Home/Index.cshtml
@@ -1 +1,267 @@
+
+