From 44e8ec135cee333c8b114afc82e13c03f2ed691e Mon Sep 17 00:00:00 2001 From: hjhan Date: Mon, 23 Mar 2026 10:45:09 +0800 Subject: [PATCH] =?UTF-8?q?feat(account):=20=E6=B7=BB=E5=8A=A0=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E9=80=80=E5=87=BA=E6=97=A5=E5=BF=97=E8=AE=B0=E5=BD=95?= =?UTF-8?q?=E5=92=8CSSO=E4=BC=98=E5=8C=96=20-=20=E5=9C=A8=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E9=A1=B5=E9=9D=A2=E6=B7=BB=E5=8A=A0=E8=AE=BF=E9=97=AE?= =?UTF-8?q?=E6=97=A5=E5=BF=97=E8=AE=B0=E5=BD=95=EF=BC=8C=E5=8C=85=E6=8B=AC?= =?UTF-8?q?IP=E5=9C=B0=E5=9D=80=E5=92=8C=E8=B7=B3=E8=BF=87SSO=E5=8F=82?= =?UTF-8?q?=E6=95=B0=20-=20=E5=A2=9E=E5=8A=A0=E5=A4=A9=E9=A3=8ESSO?= =?UTF-8?q?=E5=90=AF=E7=94=A8=E7=8A=B6=E6=80=81=E7=9A=84=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E8=BE=93=E5=87=BA=20-=20=E6=B7=BB=E5=8A=A0=E5=AF=86=E7=A0=81?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E7=A6=81=E7=94=A8=E9=85=8D=E7=BD=AE=E7=9A=84?= =?UTF-8?q?=E6=A3=80=E6=9F=A5=E6=97=A5=E5=BF=97=20-=20=E5=9C=A8=E9=80=80?= =?UTF-8?q?=E5=87=BA=E7=99=BB=E5=BD=95=E6=97=B6=E8=AE=B0=E5=BD=95=E7=94=A8?= =?UTF-8?q?=E6=88=B7ID=E3=80=81=E7=94=A8=E6=88=B7=E5=90=8D=E5=92=8CIP?= =?UTF-8?q?=E5=9C=B0=E5=9D=80=20-=20=E4=BC=98=E5=8C=96=E9=80=80=E5=87=BA?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E6=B5=81=E7=A8=8B=EF=BC=8C=E9=81=BF=E5=85=8D?= =?UTF-8?q?=E7=A6=81=E7=94=A8=E5=AF=86=E7=A0=81=E7=99=BB=E5=BD=95=E6=97=B6?= =?UTF-8?q?=E7=9A=84=E5=BE=AA=E7=8E=AF=E8=B7=B3=E8=BD=AC=E9=97=AE=E9=A2=98?= =?UTF-8?q?=20-=20=E4=B8=BASSO=E7=99=BB=E5=BD=95=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E9=87=8D=E6=96=B0=E7=99=BB=E5=BD=95=E6=8C=89=E9=92=AE=E6=A0=B7?= =?UTF-8?q?=E5=BC=8F=E5=92=8C=E5=8A=9F=E8=83=BD=20-=20=E7=BB=9F=E4=B8=80?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E8=BF=9C=E7=A8=8BIP=E5=9C=B0=E5=9D=80?= =?UTF-8?q?=E5=8F=98=E9=87=8F=E9=81=BF=E5=85=8D=E9=87=8D=E5=A4=8D=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=20-=20=E5=A2=9E=E5=8A=A0=E5=BC=82=E5=B8=B8=E5=A4=84?= =?UTF-8?q?=E7=90=86=E7=9A=84=E6=97=A5=E5=BF=97=E8=AE=B0=E5=BD=95=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- YLErpWeb/Controllers/AccountController.cs | 36 +++++++++++++++++++++-- YLErpWeb/Views/Account/LogOut.cshtml | 23 ++++++++++++++- 2 files changed, 55 insertions(+), 4 deletions(-) diff --git a/YLErpWeb/Controllers/AccountController.cs b/YLErpWeb/Controllers/AccountController.cs index 9f83badb..1b58e68d 100644 --- a/YLErpWeb/Controllers/AccountController.cs +++ b/YLErpWeb/Controllers/AccountController.cs @@ -34,6 +34,10 @@ namespace YLErp.Web.Controllers public ActionResult Login(bool skipSso = false) { + var logger = LogFactory.GetLogger(); + var remoteIp = HttpContext.Connection.RemoteIpAddress?.ToString(); + logger.Info($"[登录页面] 访问登录页,IP: {remoteIp}, skipSso: {skipSso}"); + var keys = Request.Cookies.Keys.ToArray(); foreach (var key in keys) @@ -44,18 +48,27 @@ namespace YLErp.Web.Controllers } } + // 检查天风SSO if (SsoLoginConfig.SSO_Enable && PS.Config.Company == CompanyEnum.天风) { + logger.Info($"[登录页面] 天风SSO已启用,跳转到天风登录页"); return View("TianFengLogin"); } - if (PS.Config.ErpElement.DisablePasswordLogin) + // 检查是否禁用密码登录 + var disablePasswordLogin = PS.Config.ErpElement.DisablePasswordLogin; + var strictAuthorize = PS.Config.ErpElement.StrictAuthorize; + logger.Info($"[登录页面] 配置检查 - DisablePasswordLogin: {disablePasswordLogin}, StrictAuthorize: {strictAuthorize}, Company: {PS.Config.Company}"); + + if (disablePasswordLogin) { var ssoUrl = YLErp.Web.Models.GeneralSSOConfig.AuthUrl; + logger.Info($"[登录页面] 密码登录已禁用,准备跳转到SSO: {ssoUrl}"); if (!string.IsNullOrEmpty(ssoUrl)) { return Redirect(ssoUrl); } + logger.Error($"[登录页面] SSO地址未配置,无法跳转"); return Content("SSO登录未配置,请联系管理员"); } @@ -265,8 +278,12 @@ namespace YLErp.Web.Controllers public ActionResult LogOut() { + var logger = LogFactory.GetLogger(); var userId = User.GetUserId(); var loginName = User.GetUserName(); + var remoteIp = HttpContext.Connection.RemoteIpAddress?.ToString(); + + logger.Info($"[退出登录] 用户请求退出 - UserId: {userId}, LoginName: {loginName}, IP: {remoteIp}"); if (userId > 0) { @@ -283,7 +300,7 @@ namespace YLErp.Web.Controllers } db.SystemUserLoginfo.Add(new SystemUserLoginfo { - IPAddress = HttpContext.Connection.RemoteIpAddress?.ToString(), + IPAddress = remoteIp, LogTime = DateTime.Now, LogType = "登出", UserId = userId, @@ -291,15 +308,17 @@ namespace YLErp.Web.Controllers MACAddress = string.Empty }); db.SaveChanges(); + logger.Info($"[退出登录] 用户退出记录已保存 - UserId: {userId}, LoginName: {loginName}"); } } catch (Exception ex) { - LogFactory.GetLogger("用户登出").Error(ex); + logger.Error($"[退出登录] 保存退出记录失败 - UserId: {userId}", ex); } } HttpContext.SignOutAsync(IdentityConstants.ApplicationScheme); + logger.Info($"[退出登录] SignOutAsync 已调用"); if (SsoLoginConfig.SSO_Enable) { @@ -316,6 +335,17 @@ namespace YLErp.Web.Controllers } } + // 如果禁用了密码登录,显示退出页面(避免循环跳转到SSO) + var disablePasswordLogin = PS.Config.ErpElement.DisablePasswordLogin; + logger.Info($"[退出登录] 跳转判断 - DisablePasswordLogin: {disablePasswordLogin}, SsoLoginConfig.SSO_Enable: {SsoLoginConfig.SSO_Enable}"); + + if (disablePasswordLogin) + { + logger.Info($"[退出登录] 密码登录已禁用,返回LogOut视图"); + return View("LogOut"); + } + + logger.Info($"[退出登录] 跳转到登录页"); return RedirectToAction("Login"); } diff --git a/YLErpWeb/Views/Account/LogOut.cshtml b/YLErpWeb/Views/Account/LogOut.cshtml index 274b11ae..85be5a71 100644 --- a/YLErpWeb/Views/Account/LogOut.cshtml +++ b/YLErpWeb/Views/Account/LogOut.cshtml @@ -3,6 +3,7 @@ @{ Layout = null; ViewBag.Title = "登出"; + var disablePasswordLogin = PS.Config?.ErpElement?.DisablePasswordLogin ?? false; } @@ -10,11 +11,31 @@ @GlobalConfig.ProjectTitle +
-
+
已经登出系统,为安全性考虑,浏览器窗口将在 5秒 后自动关闭! + @if (disablePasswordLogin) + { +

+ + }