From 8dc0205016bd8a0c0dfe8154aa7493409c19d146 Mon Sep 17 00:00:00 2001 From: hjhan Date: Mon, 23 Mar 2026 11:20:33 +0800 Subject: [PATCH] =?UTF-8?q?refactor(account):=20=E5=B0=86=E5=AF=86?= =?UTF-8?q?=E7=A0=81=E7=99=BB=E5=BD=95=E7=A6=81=E7=94=A8=E9=80=BB=E8=BE=91?= =?UTF-8?q?=E4=BB=8E=E6=8E=A7=E5=88=B6=E5=99=A8=E7=A7=BB=E5=88=B0=E8=A7=86?= =?UTF-8?q?=E5=9B=BE=E5=B1=82=20-=20=E7=A7=BB=E9=99=A4=20AccountController?= =?UTF-8?q?=20=E4=B8=AD=E7=9A=84=E5=AF=86=E7=A0=81=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E9=87=8D=E5=AE=9A=E5=90=91=E9=80=BB=E8=BE=91=20-=20=E5=9C=A8?= =?UTF-8?q?=20Login.cshtml=20=E8=A7=86=E5=9B=BE=E4=B8=AD=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=20DisablePasswordLogin=20=E5=92=8C=20SSO=20=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=A3=80=E6=B5=8B=20-=20=E6=A0=B9=E6=8D=AE=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E5=8A=A8=E6=80=81=E6=98=BE=E7=A4=BA=20SSO=20=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E6=88=96=E5=B8=B8=E8=A7=84=E7=99=BB=E5=BD=95=E8=A1=A8=E5=8D=95?= =?UTF-8?q?=20-=20=E5=BD=93=E7=A6=81=E7=94=A8=E5=AF=86=E7=A0=81=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E6=97=B6=E6=98=BE=E7=A4=BA=20SSO=20=E5=8D=95=E7=82=B9?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E6=8C=89=E9=92=AE=20-=20=E7=A7=BB=E9=99=A4?= =?UTF-8?q?=E9=80=80=E5=87=BA=E7=99=BB=E5=BD=95=E6=97=B6=E7=9A=84=E5=AF=86?= =?UTF-8?q?=E7=A0=81=E7=99=BB=E5=BD=95=E7=A6=81=E7=94=A8=E5=88=A4=E6=96=AD?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- YLErpWeb/Controllers/AccountController.cs | 23 +----- YLErpWeb/Views/Account/Login.cshtml | 99 ++++++++++++++--------- 2 files changed, 62 insertions(+), 60 deletions(-) diff --git a/YLErpWeb/Controllers/AccountController.cs b/YLErpWeb/Controllers/AccountController.cs index 1b58e68d..3adc4f8d 100644 --- a/YLErpWeb/Controllers/AccountController.cs +++ b/YLErpWeb/Controllers/AccountController.cs @@ -60,17 +60,8 @@ namespace YLErp.Web.Controllers 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登录未配置,请联系管理员"); - } + // 注意:DisablePasswordLogin 的逻辑在 Login.cshtml 视图中处理 + // 这里不再直接跳转,而是显示登录页,由页面决定显示什么内容 return LoginError(null); } @@ -335,16 +326,6 @@ 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/Login.cshtml b/YLErpWeb/Views/Account/Login.cshtml index 167b9aa4..65bf3b6c 100644 --- a/YLErpWeb/Views/Account/Login.cshtml +++ b/YLErpWeb/Views/Account/Login.cshtml @@ -5,6 +5,8 @@ ViewBag.Title = "登录"; var captchaUrl = Url.Action("Captcha") + "?sid=" + Model.SID; Model.LoadTime = DateTime.Now; + var disablePasswordLogin = PS.Config?.ErpElement?.DisablePasswordLogin ?? false; + var ssoEnable = YLErp.Web.Models.GeneralSSOConfig.Enable; } @@ -54,51 +56,70 @@
@GlobalConfig.ProjectTitle
-
- - - - - - - - - - - - - - - - - - @if (Model.NeedCaptcha) + @if (disablePasswordLogin) + { + +
+

请使用SSO单点登录

+ @if (ssoEnable) { + + } + else + { +

SSO登录未配置,请联系管理员

+ } +
+ } + else + { + + + + + + + + + + + + + + + + + + + + @if (Model.NeedCaptcha) + { + + + + + } - } - - - - - -
+ + + }
Copyright © 2020 YieldChain All rights reserved.